2

調査と同期ヘッダーの 2 つのテーブルを持つデータベースがあります。Survey には SurveyId (Guid) の主キーがあり、これは syncheader テーブルの外部キーです。

私が抱えている問題は、これらのテーブル間で結合すると、sqlite クエリがハングして応答が返されないことです (Firefox sqlite マネージャーと 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

EXPLAIN QUERY PLAN 出力:

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
4

0 に答える 0