我在我的数据库上使用这个查询
SELECT
DISTINCT wb_expr_pattern2gene.gene
FROM
wb_expr_pattern2gene
, wb_expr_pattern2anatomy_term
, wb_anatomy_term2ancestor
, wb_anatomy_term2cell
WHERE
wb_anatomy_term2cell.cell = 'P0'
AND (
wb_anatomy_term2cell.anatomy_term = wb_expr_pattern2anatomy_term.anatomy_term
OR (
wb_anatomy_term2cell.anatomy_term = wb_anatomy_term2ancestor.anatomy_term
AND wb_anatomy_term2ancestor.ancestor_term = wb_expr_pattern2anatomy_term.anatomy_term
)
)
AND wb_expr_pattern2anatomy_term.expr_pattern = wb_expr_pattern2gene.expr_pattern
;
这需要很长时间。原因是 sqlite 不会在wb_anatomy_term2ancestor
表上使用索引
0|0|3|SEARCH TABLE wb_anatomy_term2cell USING INDEX wb_anatomy_term2cell__cell (cell=?) (~10 rows)
0|1|2|SCAN TABLE wb_anatomy_term2ancestor (~1000000 rows)
0|2|1|SEARCH TABLE wb_expr_pattern2anatomy_term USING INDEX wb_expr_pattern2anatomy_term__anatomy_term (anatomy_term=?) (~10 rows)
0|2|1|SEARCH TABLE wb_expr_pattern2anatomy_term USING INDEX wb_expr_pattern2anatomy_term__anatomy_term (anatomy_term=?) (~10 rows)
0|3|0|SEARCH TABLE wb_expr_pattern2gene USING INDEX wb_expr_pattern2gene__expr_pattern (expr_pattern=?) (~10 rows)
0|0|0|USE TEMP B-TREE FOR DISTINCT
尽管它们存在
CREATE INDEX wb_anatomy_term2ancestor__anatomy_term__ancestor_term ON wb_anatomy_term2ancestor(anatomy_term, ancestor_term);
CREATE INDEX wb_anatomy_term2ancestor__anatomy_term ON wb_anatomy_term2ancestor(anatomy_term);
CREATE INDEX wb_anatomy_term2ancestor__ancestor_term ON wb_anatomy_term2ancestor(ancestor_term);
sqlite 有这种行为的充分理由吗?