我有一个包含 2 个表、调查表和同步头的数据库。Survey 的主键是 SurveyId (Guid),这是同步头表中的外键。
我遇到的问题是,当我在这些表之间加入时,sqlite 查询将挂起并且不返回任何响应(在 Firefox sqlite manager 和 SQLite2009Pro 中),即使它是有效的语法,我的代码在尝试运行查询时也会返回错误:
CREATE TABLE "syncheader" (
syncheaderid guid not null constraint pkc_syncheader_syncheaderid primary key,
surveyid guid not null,
surveydate datetime null,
syncsurveyorid guid null,
isdirty boolean null,
assetid int null,
syncinspectionid int null,
inspectionid int null
);
CREATE TABLE survey (
surveyid guid not null constraint pkc_survey_surveyid primary key,
assetid int not null,
sectionid int not null,
surveydate datetime null,
syncsurveyorid guid null,
isdirty boolean null,
inspectionid int null,
status int default 0 null
);
SELECT sh.surveyid SurveyID, sh.syncheaderid AS SyncHeaderID,
sh.surveydate AS SurveyDate, sh.syncsurveyorid AS SyncSurveyorID,
sh.assetid AS AssetID, sh.inspectionid AS InspectionID,
sh.syncinspectionid AS SyncInspectionID
FROM syncheader sh JOIN survey s ON sh.surveyid = s.surveyid
WHERE sh.isdirty = 1
AND s.isdirty = 1
ORDER BY sh.surveydate LIMIT 0, 100
解释查询计划输出:
0 0 0 SCAN TABLE syncheader1 AS sh (~168 rows)
0 1 1 SEARCH TABLE survey AS s USING INDEX sqlite_autoindex_survey_1 (surveyid=?) (~1 rows)
0 0 0 USE TEMP B-TREE FOR ORDER BY