SQLite查询未完成执行,而Access运行需要一分钟

SQLite查询未完成执行,而Access运行需要一分钟,sqlite,select,Sqlite,Select,我在试图让SQLite查询完成执行时陷入了困境,目前没有什么好主意。此外,我还不熟悉编写SQL查询的领域,我还在学习数据库索引等概念 我正在将一个应用程序从Access迁移到SQLite,在Access中运行查询大约需要1分钟。下面给出了查询,我也无法从SQLite迁移回Access: SELECT pgDescription, oSimulationID, oSimRunID, ipParticipantID, oPeriod, Some_Aggregation_Function(d

我在试图让SQLite查询完成执行时陷入了困境,目前没有什么好主意。此外,我还不熟悉编写SQL查询的领域,我还在学习数据库索引等概念

我正在将一个应用程序从Access迁移到SQLite,在Access中运行查询大约需要1分钟。下面给出了查询,我也无法从SQLite迁移回Access:

    SELECT pgDescription, oSimulationID, oSimRunID, ipParticipantID, oPeriod, 
Some_Aggregation_Function(dpVal) FROM 

        (
          SELECT pgDescription, oSimulationID, oSimRunID, ipParticipantID, oPeriod, dpVal, 
ptPropertyTypeName FROM tmpPartArgs INNER JOIN 

            (
              SELECT pgDescription, oSimulationID, oSimRunID, ipParticipantID, 
oPeriod, dpVal, dpParticipantID, ptPropertyTypeName FROM 

                (
                  SELECT o.SimulationID AS oSimulationID, o.SimRunID AS oSimRunID, 
o.Period AS oPeriod, dpVal, dpParticipantID, ptPropertyTypeName FROM Occurrence AS o INNER JOIN 

                    (
                      SELECT * FROM 
                        (
                           SELECT dp.Val AS dpVal, dp.SimulationID AS 
dpSimulationID, dp.SimRunID AS dpSimRunID,dp.ParticipantID AS dpParticipantID, 
dp.OccurrenceID AS dpOccurrenceID, pt.PropertyTypeName AS ptPropertyTypeName FROM
 PropertyType AS pt INNER JOIN DynamicProperty AS dp ON pt.PropertyTypeID =  dp.PropertyTypeID
                        ) AS query0 WHERE query0.ptPropertyTypeName = \"" + args.propertyName + "\"
                    ) AS query1 ON (o.SimulationID = query1.dpSimulationID) 
AND (o.SimRunID = query1.dpSimRunID) AND (o.OccurrenceID = query1.dpOccurrenceID)
                ) AS query2 INNER JOIN 

                (
                   SELECT pg.Description AS pgDescription, ip.ParticipantID AS 
ipParticipantID FROM ParticipantGroup AS pg INNER JOIN InitialParticipant AS ip ON pg.ParticipantGroupID = ip.ParticipantGroupID
                ) AS query3 ON query2.dpParticipantID = query3.ipParticipantID
            ) AS query4 ON tmpPartArgs.participantID = query4.dpParticipantID
        ) AS query5 INNER JOIN tmpSimArgs ON (query5.oSimRunID = tmpSimArgs.SimRunID) AND (query5.oSimulationID = tmpSimArgs.SimulationID)

    GROUP BY query5.oSimulationID, query5.oSimRunID, query5.oPeriod,
 query5.ipParticipantID, query5.pgDescription ORDER BY query5.oPeriod ASC;
上述查询在Access中运行大约一分钟。query1、query2、query3、query4和query5的输出约为1200000条记录。在SQLite中,它没有完成执行,我不知道为什么?我不明白为什么上面的查询需要一分钟才能在Access中执行,而不能在SQLite中完成执行。关于上述查询,最令人困惑的是第5个子查询,即

    SELECT pgDescription, oSimulationID, oSimRunID, ipParticipantID, oPeriod, dpVal, 
ptPropertyTypeName FROM tmpPartArgs INNER JOIN 

            (
              SELECT pgDescription, oSimulationID, oSimRunID, ipParticipantID, 
oPeriod, dpVal, dpParticipantID, ptPropertyTypeName FROM 

                (
                  SELECT o.SimulationID AS oSimulationID, o.SimRunID AS oSimRunID, 
o.Period AS oPeriod, dpVal, dpParticipantID, ptPropertyTypeName FROM Occurrence AS o INNER JOIN 

                    (
                      SELECT * FROM 
                        (
                           SELECT dp.Val AS dpVal, dp.SimulationID AS 
dpSimulationID, dp.SimRunID AS dpSimRunID,dp.ParticipantID AS dpParticipantID, 
dp.OccurrenceID AS dpOccurrenceID, pt.PropertyTypeName AS ptPropertyTypeName FROM 
PropertyType AS pt INNER JOIN DynamicProperty AS dp ON pt.PropertyTypeID = dp.PropertyTypeID
                        ) AS query0 WHERE query0.ptPropertyTypeName = \"" + args.propertyName + "\"
                    ) AS query1 ON (o.SimulationID = query1.dpSimulationID) 
AND (o.SimRunID = query1.dpSimRunID) AND (o.OccurrenceID = query1.dpOccurrenceID)
                ) AS query2 INNER JOIN 

                (
                   SELECT pg.Description AS pgDescription, ip.ParticipantID AS 
ipParticipantID FROM ParticipantGroup AS pg INNER JOIN InitialParticipant AS ip ON pg.ParticipantGroupID = ip.ParticipantGroupID
                ) AS query3 ON query2.dpParticipantID = query3.ipParticipantID
            ) AS query4 ON tmpPartArgs.participantID = query4.dpParticipantID
        ) AS query5
在几秒钟内运行,即语句“reader=com.ExecuteReader;”运行只需几秒钟,但如果我尝试用上述查询返回的记录创建一个表,它不会完成。有人能告诉我为什么会发生这种情况吗?我的意思是,它能够在几秒钟内检索到大约1200000条记录,但当我试图用这些记录创建一个表时,出现了一些问题,即创建表query5作为SELECT pgDescription、oSimulationID、oSimRunID、ipParticipantID等。。。没有完成执行。请帮忙!任何类型的指针都会非常有用

我想要创建一个名为query5的临时表的唯一原因是,我可以在该临时表上创建索引,即query5。我在这里假设,由于索引问题,我的原始查询(即第一段代码)没有完成。因此,我的另一个问题是如何在一分钟内有效地在一个表中插入大约1200000条记录

这些表具有以下结构:

发生

CREATE TABLE "Occurrence" ("SimulationID" smallint(5) NOT NULL  DEFAULT 0, "SimRunID" smallint(5) NOT NULL  DEFAULT 0, "OccurrenceID" int(10) NOT NULL DEFAULT 0, "OccurrenceTypeID" smallint(5) NOT NULL  DEFAULT 0, "Period" smallint(5) NOT NULL  DEFAULT 0, "HasSucceeded" bool NOT NULL  DEFAULT 0, PRIMARY KEY ("SimulationID", "SimRunID", "OccurrenceID"))
事件表有大约740000条记录

动态特性

CREATE TABLE "DynamicProperty" ("SimulationID" smallint(5) NOT NULL  DEFAULT 0 ,"SimRunID" smallint(5) NOT NULL  DEFAULT 0 ,"ParticipantID" int(10) NOT NULL  DEFAULT 0 ,"PropertyTypeID" smallint(5) NOT NULL  DEFAULT 0 ,"OccurrenceID" int(10) NOT NULL  DEFAULT 0 ,"Val" DOUBLE DEFAULT 0 , PRIMARY KEY ("SimulationID", "SimRunID", "ParticipantID", "PropertyTypeID", "OccurrenceID") )
DynamicProperty表有大约6250000条记录

属性类型

CREATE TABLE `PropertyType` (`PropertyTypeID` smallint (5),`PropertyTypeName` varchar (50),`IsAgentProperty` bool NOT NULL,`IsActionProperty` bool NOT NULL, `IsKnowledgeItemProperty` bool NOT NULL,`IsStatic` bool NOT NULL,`IsKnowledgeStoreProperty` bool NOT NULL,`IsSimulationProperty` bool NOT NULL,`IsAssignable` bool NOT NULL, PRIMARY KEY(`PropertyTypeID`))
PropertyType有大约50条记录

初始参与者

CREATE TABLE "InitialParticipant" ("ParticipantID" smallint(5) PRIMARY KEY  NOT NULL  DEFAULT 0, "ParticipantTypeID" smallint(5) NOT NULL  DEFAULT 0, "ParticipantGroupID" smallint(5) NOT NULL  DEFAULT 0)
参与者有大约120条记录

参与团体

CREATE TABLE `ParticipantGroup` (`ParticipantGroupID` smallint (5),`ParticipantGroupTypeID` smallint (5),`Description` varchar (50), PRIMARY KEY
参与者组ID

参和小组有大约25项记录

tmpSimArgs

CREATE TABLE tmpSimArgs (SimulationID smallint(5), SimRunID int(10))
tmpSimArgs有大约20条记录

tmpPartArgs

CREATE TABLE tmpPartArgs(participantID INT)
tmpPartArgs有大约80条记录

数据库具有以下索引:

如上所示的各个表的所有主键

在tmpSimArgsSimulationID ASC上创建索引tmpSimArgs\u SimulationID\u idx; 在tmpSimArgsSimRunID ASC上创建索引tmpSimArgs_SimRunID_idx

在tmpPartArgsparticipantID ASC上创建索引tmpPartArgs_participantID_idx


请帮忙

重新格式化您的查询,这样人们就不必通过水平滚动来了解您正在尝试做什么,这会有很大帮助。我建议您通过“解释查询计划”运行您的查询,看看哪里出了问题