The following bug has been logged on the website:
Bug reference: 19049
Logged by: Natalya Aksman
Email address: natalya@timescale.com
PostgreSQL version: 18rc1
Operating system: Ubuntu 24.04
Description:
Reproducer:
-- Set up a table with >=2 DESC index keys
create table mv (t1 int, t2 int, s0 int, s1 int);
create index on mv(s0, s1, t1 desc, t2 desc);
insert into mv select f.t, f.t, 1 s0, 1 s1 from generate_series(1, 2 *
pow(10, 4)::int) f(t);
analyze mv;
-- Make sure index is used
set enable_seqscan=0;
explain (costs off) select distinct on(s0, s1) * from mv where t2 >= -1 and
t1 < 10 order by s0, s1, t1 desc, t2 desc;
QUERY PLAN
-----------------------------------------------------------
Unique
-> Index Only Scan using mv_s0_s1_t1_t2_idx on mv
Index Cond: ((t1 < 10) AND (t2 >= '-1'::integer))
(3 rows)
-- This query crashes with an Assert
select distinct on(s0, s1) * from mv where t2 >= -1 and t1 < 10 order by
s0, s1, t1 desc, t2 desc;
Assert is:
if (ScanDirectionIsForward(dir) && array->low_compare)
Assert(DatumGetBool(FunctionCall2Coll(&array->low_compare->sk_func,
array->low_compare->sk_collation,
tupdatum,
array->low_compare->sk_argument)));
The problem is "array->low_compare" changing "t1<10" to "t1>10" because t1
order is DESC.