mardi 13 janvier 2015

How can I understand the sqlite query plan?

I executed a query on SQLite and the plan part is



0|1|5|SCAN TABLE edges AS e1 (~250000 rows)
0|0|0|EXECUTE CORRELATED SCALAR SUBQUERY 2
2|0|0|SEARCH TABLE dihedral USING AUTOMATIC
COVERING INDEX (TYPE=? AND EDGE=?) (~7 rows)
0|0|0|EXECUTE CORRELATED SCALAR SUBQUERY 3
3|0|0|SEARCH TABLE bounds USING AUTOMATIC
COVERING INDEX (FACE=? AND EDGE=?) (~7 rows)


where the query in WHERE is



exists (select dihedral.edge from dihedral where ihedral.type=2 and dihedral.edge=e1.edge) and
exists (select bounds.edge from bounds where bounds.face=f1.face and bounds.edge=e1.edge) and


I understand this is not a high effeciency query,Ijust want to increase the performance.


This is my guess:




  1. There is no subquery flattening, right?




  2. The two exist subquery introduce the correlated subquery, and as they are acctually executed as indexed nested loop, right?




  3. Read the query, because table dihedral and bounds are independent, both are correlated with the outer edge table, so the computational complexity is O(n^2) for no index. However, as there are covering index, the performance should be much better, right? I found on wiki, index has performance of O(log(N)) even better,so the overall performance should be O(n+log(N))=O(n), is this right?




Could anyone help me to understand what happened? thanks.


Aucun commentaire:

Enregistrer un commentaire