-- The member `LEFT JOIN LATERAL jsonb_each(doc) r ON r.key = 'k'` picks is the one the key equals: a non-deterministic collation equates k and K, so the join -- matches both and the query keeps its plan. Only whether the results agree is printed. CREATE EXTENSION pg_sift; SET max_parallel_workers_per_gather = 0; CREATE COLLATION ci (provider = icu, locale = 'und-u-ks-level2', deterministic = false); CREATE TABLE facts (id int, dim_a_id int, metrics jsonb); INSERT INTO facts SELECT i, i % 40, CASE i % 4 WHEN 0 THEN '{}'::jsonb WHEN 1 THEN jsonb_build_object('k', i % 10, 'K', i % 3) ELSE jsonb_build_object('k', i % 7) END FROM generate_series(1, 4000) i; CREATE INDEX facts_col ON facts USING sift_col (id, dim_a_id, metrics) WITH (paths = 'metrics.* float8'); VACUUM (FREEZE, ANALYZE) facts; \ir test/agg_helpers.sql CREATE FUNCTION same(q text) RETURNS bool LANGUAGE sql AS $$ SELECT outcome(q, false) = outcome(q, true) $$; SELECT same($q$ SELECT f.dim_a_id % 3 AS g, count(*) AS n, count(CAST(r.value AS float)) AS dim_b, sum(CAST(r.value AS float)) AS total FROM facts f LEFT JOIN LATERAL jsonb_each(f.metrics) r ON r.key = 'k' GROUP BY 1 $q$) AS key; SELECT same($q$ SELECT f.dim_a_id % 3 AS g, count(*) AS n, count(CAST(r.value AS float)) AS dim_b, sum(CAST(r.value AS float)) AS total FROM facts f LEFT JOIN LATERAL jsonb_each(f.metrics) r ON r.key = 'k' COLLATE ci GROUP BY 1 $q$) AS insensitive_key; DROP FUNCTION same(text), outcome(text, bool), runs_in_scan(text), pushed, runq; DROP TABLE facts; DROP COLLATION ci; DROP EXTENSION pg_sift;