lanterndata / lantern

PostgreSQL vector database extension for building AI applications
https://lantern.dev
GNU Affero General Public License v3.0
790 stars 57 forks source link

Support nested loop within index scan #85

Open dqii opened 1 year ago

dqii commented 1 year ago

B tree indices support nested loops within index scans.

postgres=# create table temp_table(id serial primary key, v integer, b integer);
CREATE TABLE
postgres=# insert into temp_table(v) values (1), (2), (3);
INSERT 0 3
postgres=# create index on temp_table(v);
CREATE INDEX
postgres=# set enable_seqscan = off;
SET
postgres=# create table temp_table2(id serial primary key);
CREATE TABLE
postgres=# explain select 1 from temp_table join temp_table2 using (id) order by v;
                                          QUERY PLAN                                           
-----------------------------------------------------------------------------------------------
 Nested Loop  (cost=0.29..28.70 rows=3 width=8)
   ->  Index Scan using temp_table_v_idx on temp_table  (cost=0.13..12.18 rows=3 width=8)
   ->  Index Only Scan using temp_table2_pkey on temp_table2  (cost=0.15..5.51 rows=1 width=4)
         Index Cond: (id = temp_table.id)

We should do the same.