-
Notifications
You must be signed in to change notification settings - Fork 889
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]: Could not find pathkey item to sort on partially compressed chunks of a hypertable #6975
Comments
Thanks for reporting with a great repro case! Taking a look at this, will update once I have something. |
I just realized I haven't sent the comment I've prepared last week. I've reduced the reproduction script, getting the same error. CREATE TABLE measurements (
generated_at timestamptz not null,
device_id int4 not null,
CONSTRAINT measurements_pkey PRIMARY KEY (generated_at)
);
CREATE TABLE devices (
id int4 not null,
name varchar(255) not null
);
SELECT create_hypertable(
'measurements',
'generated_at',
chunk_time_interval => INTERVAL '7 days',
if_not_exists => TRUE,
create_default_indexes => FALSE
);
INSERT INTO measurements VALUES ('2023-01-01 12:00', 1), ('2023-01-02 12:00', 1), ('2023-01-08 12:00', 1);
ALTER TABLE measurements SET (timescaledb.compress);
SELECT compress_chunk(format('%I.%I', chunk_schema, chunk_name)::regclass)
FROM timescaledb_information.chunks
WHERE is_compressed = false and hypertable_name = 'measurements';
UPDATE measurements SET device_id = 2 WHERE generated_at = '2023-01-01 12:00:00';
EXPLAIN SELECT * FROM measurements
JOIN devices ON measurements.device_id = devices.id
WHERE device_id = 1 ORDER BY devices.name;
ERROR: could not find pathkey item to sort Looks like there is a problem creating a Merge Append plan with partially compressed chunk when the result is sorted by a column that doesn't belong to the hypertable. Here's a stacktrace: #0 errstart (elevel=21, domain=0x0) at elog.c:336
#1 0x00005f6a72cf2d79 in prepare_sort_from_pathkeys (lefttree=0x5f6a74694898, pathkeys=0x5f6a74650aa8,
relids=0x5f6a74638ef0, reqColIdx=0x0, adjust_tlist_in_place=<optimized out>,
p_numsortkeys=0x5f6a74694910, p_sortColIdx=0x5f6a74694918, p_sortOperators=0x5f6a74694920,
p_collations=0x5f6a74694928, p_nullsFirst=0x5f6a74694930) at createplan.c:6236
#2 0x00005f6a72fd0a5e in create_merge_append_plan (root=0x5f6a74639538, best_path=0x5f6a74694eb8,
flags=1) at createplan.c:1450
#3 0x00005f6a72fd14e3 in create_customscan_plan (scan_clauses=0x5f6a7464fda0, tlist=0x5f6a74696a30,
best_path=0x5f6a74694d18, root=0x5f6a74639538) at createplan.c:4256
#4 create_scan_plan (root=0x5f6a74639538, best_path=0x5f6a74694d18, flags=<optimized out>)
at createplan.c:773
#5 0x00005f6a72fccb0b in create_nestloop_plan (best_path=0x5f6a74695c30, root=0x5f6a74639538)
at createplan.c:4331
#6 create_join_plan (best_path=0x5f6a74695c30, root=0x5f6a74639538) at createplan.c:1076
#7 create_plan_recurse (root=0x5f6a74639538, best_path=0x5f6a74695c30, flags=<optimized out>)
at createplan.c:416
#8 0x00005f6a72fd0165 in create_plan (root=root@entry=0x5f6a74639538, best_path=<optimized out>)
at createplan.c:347
#9 0x00005f6a72fdf888 in standard_planner (parse=parse@entry=0x5f6a74664fb0,
query_string=query_string@entry=0x5f6a7453ddb0 "explain select * from measurements\njoin devices on measurements.device_id = devices.id\nwhere generated_at > '2023-01-04 12:00:00' and generated_at < '2023-01-19 12:17:00'\n and device_id = 1 order b"..., cursorOptions=cursorOptions@entry=2048,
boundParams=boundParams@entry=0x0) at planner.c:415
#10 0x0000795f18c41138 in timescaledb_planner (parse=0x5f6a74664fb0,
query_string=0x5f6a7453ddb0 "explain select * from measurements\njoin devices on measurements.device_id = devices.id\nwhere generated_at > '2023-01-04 12:00:00' and generated_at < '2023-01-19 12:17:00'\n and device_id = 1 order b"..., cursor_opts=2048, bound_params=0x0)
at /home/zilder/projects/timescaledb/src/planner/planner.c:543
#11 0x00005f6a730ba23d in pg_plan_query (querytree=0x5f6a74664fb0,
query_string=query_string@entry=0x5f6a7453ddb0 "explain select * from measurements\njoin devices on measurements.device_id = devices.id\nwhere generated_at > '2023-01-04 12:00:00' and generated_at < '2023-01-19 12:17:00'\n and device_id = 1 order b"..., cursorOptions=cursorOptions@entry=2048,
boundParams=boundParams@entry=0x0) at postgres.c:883
#12 0x00005f6a72eaf714 in ExplainOneQuery (query=<optimized out>, cursorOptions=2048, into=0x0,
es=0x5f6a74638258,
queryString=0x5f6a7453ddb0 "explain select * from measurements\njoin devices on measurements.device_id = devices.id\nwhere generated_at > '2023-01-04 12:00:00' and generated_at < '2023-01-19 12:17:00'\n and device_id = 1 order b"..., params=0x0, queryEnv=0x0) at explain.c:397
... |
Workaround: SELECT * FROM (
SELECT * FROM measurements
JOIN devices ON measurements.device_id = devices.id
WHERE device_id = 1
) x
ORDER BY x.name; |
Thanks for all the input, I have a PR up for the fix that should go out with the next release. |
This release contains performance improvements and bug fixes since the 2.15.0 release. Best practice is to upgrade at the next available opportunity. **Migrating from self-hosted TimescaleDB v2.14.x and earlier** After you run `ALTER EXTENSION`, you must run [this SQL script](https://github.com/timescale/timescaledb-extras/blob/master/utils/2.15.X-fix_hypertable_foreign_keys.sql). For more details, see the following pull request [timescale#6797](timescale#6797). If you are migrating from TimescaleDB v2.15.0 or v2.15.1, no changes are required. **Bugfixes** * timescale#6975: Fix sort pushdown for partially compressed chunks. * timescale#6976: Fix removal of metadata function and update script. * timescale#6978: Fix segfault in compress_chunk with primary space partition. * timescale#6993: Disallow hash partitioning on primary column. **Thanks** * @gugu for reporting the issue with catalog corruption due to update. * @srieding for reporting an issue with partially compressed chunks and ordering on joined columns.
This release contains performance improvements and bug fixes since the 2.15.0 release. Best practice is to upgrade at the next available opportunity. **Migrating from self-hosted TimescaleDB v2.14.x and earlier** After you run `ALTER EXTENSION`, you must run [this SQL script](https://github.com/timescale/timescaledb-extras/blob/master/utils/2.15.X-fix_hypertable_foreign_keys.sql). For more details, see the following pull request [timescale#6797](timescale#6797). If you are migrating from TimescaleDB v2.15.0 or v2.15.1, no changes are required. **Bugfixes** * timescale#6975: Fix sort pushdown for partially compressed chunks. * timescale#6976: Fix removal of metadata function and update script. * timescale#6978: Fix segfault in compress_chunk with primary space partition. * timescale#6993: Disallow hash partitioning on primary column. **Thanks** * @gugu for reporting the issue with catalog corruption due to update. * @srieding for reporting an issue with partially compressed chunks and ordering on joined columns.
This release contains performance improvements and bug fixes since the 2.15.1 release. Best practice is to upgrade at the next available opportunity. **Bugfixes** * timescale#6975: Fix sort pushdown for partially compressed chunks. * timescale#6976: Fix removal of metadata function and the update script. * timescale#6978: Fix segfault in compress_chunk with primary space partition. * timescale#6993: Disallow hash partitioning on the primary column. **Thanks** * @gugu for reporting the issue with catalog corruption due to update. * @srieding for reporting the issue with partially compressed chunks and ordering on joined columns.
This release contains bug fixes since the 2.15.1 release. Best practice is to upgrade at the next available opportunity. **Bugfixes** * #6975: Fix sort pushdown for partially compressed chunks. * #6976: Fix removal of metadata function and the update script. * #6978: Fix segfault in `compress_chunk` with primary space partition. * #6993: Disallow hash partitioning on the primary column. **Thanks** * @gugu for reporting the issue with catalog corruption due to update. * @srieding for reporting the issue with partially compressed chunks and ordering on joined columns.
This release contains performance improvements and bug fixes since the 2.15.0 release. Best practice is to upgrade at the next available opportunity. **Migrating from self-hosted TimescaleDB v2.14.x and earlier** After you run `ALTER EXTENSION`, you must run [this SQL script](https://github.com/timescale/timescaledb-extras/blob/master/utils/2.15.X-fix_hypertable_foreign_keys.sql). For more details, see the following pull request [timescale#6797](timescale#6797). If you are migrating from TimescaleDB v2.15.0 or v2.15.1, no changes are required. **Bugfixes** * timescale#6975: Fix sort pushdown for partially compressed chunks. * timescale#6976: Fix removal of metadata function and update script. * timescale#6978: Fix segfault in compress_chunk with primary space partition. * timescale#6993: Disallow hash partitioning on primary column. **Thanks** * @gugu for reporting the issue with catalog corruption due to update. * @srieding for reporting an issue with partially compressed chunks and ordering on joined columns.
This release contains performance improvements and bug fixes since the 2.15.0 release. Best practice is to upgrade at the next available opportunity. **Migrating from self-hosted TimescaleDB v2.14.x and earlier** After you run `ALTER EXTENSION`, you must run [this SQL script](https://github.com/timescale/timescaledb-extras/blob/master/utils/2.15.X-fix_hypertable_foreign_keys.sql). For more details, see the following pull request [#6797](#6797). If you are migrating from TimescaleDB v2.15.0 or v2.15.1, no changes are required. **Bugfixes** * #6975: Fix sort pushdown for partially compressed chunks. * #6976: Fix removal of metadata function and update script. * #6978: Fix segfault in compress_chunk with primary space partition. * #6993: Disallow hash partitioning on primary column. **Thanks** * @gugu for reporting the issue with catalog corruption due to update. * @srieding for reporting an issue with partially compressed chunks and ordering on joined columns.
What type of bug is this?
Unexpected error
What subsystems and features are affected?
Query executor, Query planner
What happened?
The problem occurs for a query that takes the form:
The query is not a production like query. It instead comes from the included script that has a more minimal reproduction path to get to the same error. Here
It could be similar to #2232 But that is almost impossible to tell since that ticket is neither moving nor does it have a clean enough reproduction path.
TimescaleDB version affected
2.14.2
PostgreSQL version used
14.1
What operating system did you use?
window 11 x64
What installation method did you use?
Docker
What platform did you run on?
Timescale Cloud
Relevant log output and stack trace
How can we reproduce the bug?
The text was updated successfully, but these errors were encountered: