mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-08-31 14:17:22 +02:00
Fix indexable-row-comparison logic to account for covering indexes.
indxpath.c needs a good deal more attention for covering indexes than
it's gotten. But so far as I can tell, the only really awful breakage
is in expand_indexqual_rowcompare (nee adjust_rowcompare_for_index),
which was only half fixed in c266ed31a
. The other problems aren't
bad enough to take the risk of a just-before-wrap fix.
The problem here is that if the leading column of a row comparison
matches an index (allowing this code to be reached), and some later
column doesn't match the index, it'll nonetheless believe that that
column matches the first included index column. Typically that'll
lead to an error like "operator M is not a member of opfamily N" as
a result of fetching a garbage opfamily OID. But with enough bad
luck, maybe a broken plan would be generated.
Discussion: https://postgr.es/m/25526.1549847928@sss.pgh.pa.us
This commit is contained in:
parent
2eebda274f
commit
eb68d71f99
@ -3966,7 +3966,7 @@ adjust_rowcompare_for_index(RowCompareExpr *clause,
|
|||||||
break; /* no good, volatile comparison value */
|
break; /* no good, volatile comparison value */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The Var side can match any column of the index.
|
* The Var side can match any key column of the index.
|
||||||
*/
|
*/
|
||||||
for (i = 0; i < index->nkeycolumns; i++)
|
for (i = 0; i < index->nkeycolumns; i++)
|
||||||
{
|
{
|
||||||
@ -3978,7 +3978,7 @@ adjust_rowcompare_for_index(RowCompareExpr *clause,
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (i >= index->ncolumns)
|
if (i >= index->nkeycolumns)
|
||||||
break; /* no match found */
|
break; /* no match found */
|
||||||
|
|
||||||
/* Add column number to returned list */
|
/* Add column number to returned list */
|
||||||
|
@ -127,6 +127,23 @@ INSERT INTO tbl SELECT 1, NULL, 3*x, box('4,4,4,4') FROM generate_series(1,10) A
|
|||||||
ERROR: null value in column "c2" violates not-null constraint
|
ERROR: null value in column "c2" violates not-null constraint
|
||||||
DETAIL: Failing row contains (1, null, 3, (4,4),(4,4)).
|
DETAIL: Failing row contains (1, null, 3, (4,4),(4,4)).
|
||||||
INSERT INTO tbl SELECT x, 2*x, NULL, NULL FROM generate_series(1,10) AS x;
|
INSERT INTO tbl SELECT x, 2*x, NULL, NULL FROM generate_series(1,10) AS x;
|
||||||
|
explain (costs off)
|
||||||
|
select * from tbl where (c1,c2,c3) < (2,5,1);
|
||||||
|
QUERY PLAN
|
||||||
|
------------------------------------------------
|
||||||
|
Bitmap Heap Scan on tbl
|
||||||
|
Filter: (ROW(c1, c2, c3) < ROW(2, 5, 1))
|
||||||
|
-> Bitmap Index Scan on covering
|
||||||
|
Index Cond: (ROW(c1, c2) <= ROW(2, 5))
|
||||||
|
(4 rows)
|
||||||
|
|
||||||
|
select * from tbl where (c1,c2,c3) < (2,5,1);
|
||||||
|
c1 | c2 | c3 | c4
|
||||||
|
----+----+----+----
|
||||||
|
1 | 2 | |
|
||||||
|
2 | 4 | |
|
||||||
|
(2 rows)
|
||||||
|
|
||||||
DROP TABLE tbl;
|
DROP TABLE tbl;
|
||||||
CREATE TABLE tbl (c1 int,c2 int, c3 int, c4 box,
|
CREATE TABLE tbl (c1 int,c2 int, c3 int, c4 box,
|
||||||
UNIQUE(c1,c2) INCLUDE(c3,c4));
|
UNIQUE(c1,c2) INCLUDE(c3,c4));
|
||||||
|
@ -73,6 +73,9 @@ SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conre
|
|||||||
INSERT INTO tbl SELECT 1, 2, 3*x, box('4,4,4,4') FROM generate_series(1,10) AS x;
|
INSERT INTO tbl SELECT 1, 2, 3*x, box('4,4,4,4') FROM generate_series(1,10) AS x;
|
||||||
INSERT INTO tbl SELECT 1, NULL, 3*x, box('4,4,4,4') FROM generate_series(1,10) AS x;
|
INSERT INTO tbl SELECT 1, NULL, 3*x, box('4,4,4,4') FROM generate_series(1,10) AS x;
|
||||||
INSERT INTO tbl SELECT x, 2*x, NULL, NULL FROM generate_series(1,10) AS x;
|
INSERT INTO tbl SELECT x, 2*x, NULL, NULL FROM generate_series(1,10) AS x;
|
||||||
|
explain (costs off)
|
||||||
|
select * from tbl where (c1,c2,c3) < (2,5,1);
|
||||||
|
select * from tbl where (c1,c2,c3) < (2,5,1);
|
||||||
DROP TABLE tbl;
|
DROP TABLE tbl;
|
||||||
|
|
||||||
CREATE TABLE tbl (c1 int,c2 int, c3 int, c4 box,
|
CREATE TABLE tbl (c1 int,c2 int, c3 int, c4 box,
|
||||||
|
Loading…
Reference in New Issue
Block a user