这是我的情况:
CREATE TABLE estimateperiod(estimatePeriodId int, periodTypeId int, companyId int, fiscalChainSeriesId int, fiscalQuarter int,fiscalYear int, calendarQuarter int, calendarYear int, periodEndDate datetime,advanceDate datetime);
CREATE INDEX estimateperiod_estimateperiodid_companyid on estimateperiod(estimateperiodid, companyid);
CREATE TABLE isinenhancedsymbol(symbolid int, symboltypeid int, symbolvalue char(64), relatedcompanyid char(64), exchangeid int, objectid int, symbolstartdate date, symbolenddate date, activeflag int);
CREATE INDEX isinenhancedsymbol_relatedcompanyid_isin on isinenhancedsymbol(relatedcompanyid, symbolvalue);
当我运行时:
sqlite> explain query plan **select ep.estimateperiodid, ep.companyid , isin.symbolvalue from estimateperiod ep, isinenhancedsymbol isin where ep.estimateperiodid = 100 and ep.companyid = isin.relatedcompanyid;**
orde from deta
---- ------------- ----
0 1 TABLE isinenhancedsymbol AS isin
1 0 TABLE estimateperiod AS ep WITH INDEX estimateperiod_estimateperiodid_companyid
因此,isinenhancedsymbol表被完全扫描,这需要很长时间。 select中的所有字段都在覆盖索引中,为什么无法使用索引搜索isinenhancedsymbol?
答案 0 :(得分:0)
SQLite版本3.6.20已经过时了几年。
当前版本支持覆盖索引:
sqlite> .eqp on
sqlite> select ep.estimateperiodid, ep.companyid , isin.symbolvalue from estimateperiod ep, isinenhancedsymbol isin where ep.estimateperiodid = 100 and ep.companyid = isin.relatedcompanyid;
--EQP-- 0,0,0,SEARCH TABLE estimateperiod AS ep USING COVERING INDEX estimateperiod_estimateperiodid_companyid (estimatePeriodId=?)
--EQP-- 0,1,1,SCAN TABLE isinenhancedsymbol AS isin USING COVERING INDEX isinenhancedsymbol_relatedcompanyid_isin