Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support autoindexing #747

Open
jussisaurio opened this issue Jan 19, 2025 · 0 comments
Open

Support autoindexing #747

jussisaurio opened this issue Jan 19, 2025 · 0 comments
Labels
enhancement New feature or request help wanted Extra attention is needed query planner

Comments

@jussisaurio
Copy link
Collaborator

Sqlite3 uses an automatic ephemeral index to avoid a naive nested loop join when there are no usable indexes.

sqlite> explain select p.name, u.first_name from users u join products p on p.name = u.first_name;
addr  opcode         p1    p2    p3    p4             p5  comment      
----  -------------  ----  ----  ----  -------------  --  -------------
0     Init           0     22    0                    0   Start at 22
1     OpenRead       0     2     0     2              0   root=2 iDb=0; users
2     OpenRead       1     3     0     3              0   root=3 iDb=0; products
3     Rewind         0     21    0                    0   
4       Once           0     12    0                    0   
5       OpenAutoindex  2     2     0     k(2,B,)        0   nColumn=2; for products
6       Rewind         1     12    0                    0   
7         Column         1     1     2                    0   r[2]= cursor 1 column 1
8         Rowid          1     3     0                    0   r[3]=products.rowid
9         MakeRecord     2     2     1                    0   r[1]=mkrec(r[2..3])
10        IdxInsert      2     1     0                    16  key=r[1]
11      Next           1     7     0                    3   
12      Column         0     1     4                    0   r[4]= cursor 0 column 1
13      IsNull         4     20    0                    0   if r[4]==NULL goto 20
14      SeekGE         2     20    4     1              0   key=r[4]
15        IdxGT          2     20    4     1              0   key=r[4]
16        Column         2     0     5                    0   r[5]= cursor 2 column 0
17        Column         0     1     6                    0   r[6]= cursor 0 column 1
18        ResultRow      5     2     0                    0   output=r[5..6]
19      Next           2     15    0                    0   
20    Next           0     4     0                    1   
21    Halt           0     0     0                    0   
22    Transaction    0     0     3     0              1   usesStmtJournal=0
23    Goto           0     1     0                    0 
@jussisaurio jussisaurio added enhancement New feature or request help wanted Extra attention is needed query planner labels Jan 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed query planner
Projects
None yet
Development

No branches or pull requests

1 participant