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 incremental sorts #84

Open
dqii opened this issue Aug 25, 2023 · 3 comments
Open

Support incremental sorts #84

dqii opened this issue Aug 25, 2023 · 3 comments
Labels
good first issue Good for newcomers test

Comments

@dqii
Copy link
Contributor

dqii commented Aug 25, 2023

B-Tree indices support incremental sorts on top of an index.

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=# explain select 1 from temp_table order by v;
                                       QUERY PLAN                                        
-----------------------------------------------------------------------------------------
 Index Only Scan using temp_table_v_idx on temp_table  (cost=0.13..12.18 rows=3 width=8)
(1 row)

postgres=# explain select 1 from temp_table order by v, id;
                                        QUERY PLAN                                         
-------------------------------------------------------------------------------------------
 Incremental Sort  (cost=4.15..12.31 rows=3 width=12)
   Sort Key: v, id
   Presorted Key: v
   ->  Index Scan using temp_table_v_idx on temp_table  (cost=0.13..12.18 rows=3 width=12)
(4 rows)
postgres=# explain select 1 from temp_table order by v, b;
                                        QUERY PLAN                                         
-------------------------------------------------------------------------------------------
 Incremental Sort  (cost=4.15..12.31 rows=3 width=12)
   Sort Key: v, b
   Presorted Key: v
   ->  Index Scan using temp_table_v_idx on temp_table  (cost=0.13..12.18 rows=3 width=12)
(4 rows)

We should do the same.

@dqii
Copy link
Contributor Author

dqii commented Aug 25, 2023

https://stackoverflow.com/questions/52033327/multi-column-indexes-and-order-by
This is a new-ish feature and tests should account for that.

@dqii
Copy link
Contributor Author

dqii commented Sep 19, 2023

It seems like both #85 and this issue are supposed to be supported out of the box by Postgres. Maybe the issue is with the cost estimate function.

@Ngalstyan4 Ngalstyan4 added the good first issue Good for newcomers label Oct 1, 2023
@Ngalstyan4
Copy link
Contributor

Given @dqii 's observation above, it would be great to collect conclusive evidence and add some tests to check these and close this issue with that

@Ngalstyan4 Ngalstyan4 added the test label Oct 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers test
Projects
None yet
Development

No branches or pull requests

2 participants