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

[Bug] Unneeded sorting of compressed chunk table with aggregation #6836

Open
akuzm opened this issue Apr 17, 2024 · 0 comments · May be fixed by #6879
Open

[Bug] Unneeded sorting of compressed chunk table with aggregation #6836

akuzm opened this issue Apr 17, 2024 · 0 comments · May be fixed by #6879

Comments

@akuzm
Copy link
Member

akuzm commented Apr 17, 2024

create table pvagg(s int, a int);

select create_hypertable('pvagg', 'a', chunk_time_interval => 1000);

insert into pvagg select 1, generate_series(1, 999);
insert into pvagg select 2, generate_series(1001, 1999);

alter table pvagg set (timescaledb.compress, timescaledb.compress_segmentby = 's');

select count(compress_chunk(x)) from show_chunks('pvagg') x;

analyze pvagg;

set enable_indexscan to off;

explain (costs off) select count(a), s from pvagg group by s;
                            QUERY PLAN                            
──────────────────────────────────────────────────────────────────
 HashAggregate
   Group Key: _hyper_50_339_chunk.s
   ->  Append
         ->  Custom Scan (DecompressChunk) on _hyper_50_339_chunk
               ->  Sort
                     Sort Key: compress_hyper_51_345_chunk.s
                     ->  Seq Scan on compress_hyper_51_345_chunk
         ->  Custom Scan (DecompressChunk) on _hyper_50_340_chunk
               ->  Sort
                     Sort Key: compress_hyper_51_346_chunk.s
                     ->  Seq Scan on compress_hyper_51_346_chunk

We're doing hash aggregation here, so these Sorts are just useless work. The reason is that we don't create an unsorted version of the decompression path if the query pathkeys can be pushed down. Queries with aggregation have query pathkeys set to the grouping columns. See ts_decompress_chunk_generate_paths.

@akuzm akuzm changed the title [Bug] Uneeded sorting of compressed chunk table with aggregation [Bug] Unneeded sorting of compressed chunk table with aggregation May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant