diff --git a/tsl/src/remote/cursor_fetcher.c b/tsl/src/remote/cursor_fetcher.c index 5ec162e6140..6cd07636747 100644 --- a/tsl/src/remote/cursor_fetcher.c +++ b/tsl/src/remote/cursor_fetcher.c @@ -421,7 +421,7 @@ cursor_fetcher_rewind(DataFetcher *df) { char sql[64]; - Assert(cursor->state.data_req != NULL); + Assert(cursor->state.eof || cursor->state.data_req != NULL); if (!cursor->state.eof) async_request_discard_response(cursor->state.data_req); diff --git a/tsl/test/shared/expected/dist_fetcher_type.out b/tsl/test/shared/expected/dist_fetcher_type.out index 496c537e206..1e04beaaf82 100644 --- a/tsl/test/shared/expected/dist_fetcher_type.out +++ b/tsl/test/shared/expected/dist_fetcher_type.out @@ -91,3 +91,31 @@ limit 1; (1 row) reset timescaledb.remote_data_fetcher; +-- #3786 test for assertion failure in cursor_fetcher_rewind +SET jit TO off; +SELECT * +FROM devices AS d +WHERE + EXISTS( + SELECT 1 + FROM metrics_dist AS m, + LATERAL( + SELECT 1 + FROM insert_test it + WHERE + EXISTS( + SELECT 1 + FROM dist_chunk_copy AS ref_2 + WHERE + it.id IS NOT NULL AND + EXISTS(SELECT d.name AS c0 FROM metrics_int WHERE NULL::TIMESTAMP <= m.time) + ) + ) AS l + WHERE d.name ~~ d.name + ) +ORDER BY 1,2; + device_id | name +-----------+------ +(0 rows) + +RESET jit; diff --git a/tsl/test/shared/sql/dist_fetcher_type.sql b/tsl/test/shared/sql/dist_fetcher_type.sql index 0668b56a1ae..2c8b3ceb1eb 100644 --- a/tsl/test/shared/sql/dist_fetcher_type.sql +++ b/tsl/test/shared/sql/dist_fetcher_type.sql @@ -37,3 +37,28 @@ where t1.id = t2.id + 1 limit 1; reset timescaledb.remote_data_fetcher; + +-- #3786 test for assertion failure in cursor_fetcher_rewind +SET jit TO off; +SELECT * +FROM devices AS d +WHERE + EXISTS( + SELECT 1 + FROM metrics_dist AS m, + LATERAL( + SELECT 1 + FROM insert_test it + WHERE + EXISTS( + SELECT 1 + FROM dist_chunk_copy AS ref_2 + WHERE + it.id IS NOT NULL AND + EXISTS(SELECT d.name AS c0 FROM metrics_int WHERE NULL::TIMESTAMP <= m.time) + ) + ) AS l + WHERE d.name ~~ d.name + ) +ORDER BY 1,2; +RESET jit;