Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita7aa61f

Browse files
committed
Properly initialize SortSupport for ORDER BY rechecks in nodeIndexscan.c.
Fix still another bug in commit35fcb1b: it failed to fully initializethe SortSupport states it introduced to allow the executor to re-checkORDER BY expressions containing distance operators. That led to a nullpointer dereference if the sortsupport code tried to use ssup_cxt. Theproblem only manifests in narrow cases, explaining the lack of previousfield reports. It requires a GiST-indexable distance operator that lacksSortSupport and is on a pass-by-ref data type, which among core+contribseems to be only btree_gist's interval opclass; and it requires the scanto be done as an IndexScan not an IndexOnlyScan, which explains howbtree_gist's regression test didn't catch it. Per bug #14134 fromJihyun Yu.Peter GeogheganReport: <20160511154904.2603.43889@wrigleys.postgresql.org>
1 parentc82037e commita7aa61f

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

‎contrib/btree_gist/expected/interval.out

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,21 @@ SELECT a, a <-> '199 days 21:21:23' FROM intervaltmp ORDER BY a <-> '199 days 21
8989
@ 220 days 19 hours 5 mins 42 secs | @ 21 days -2 hours -15 mins -41 secs
9090
(3 rows)
9191

92+
SET enable_indexonlyscan=off;
93+
EXPLAIN (COSTS OFF)
94+
SELECT a, a <-> '199 days 21:21:23' FROM intervaltmp ORDER BY a <-> '199 days 21:21:23' LIMIT 3;
95+
QUERY PLAN
96+
---------------------------------------------------------------------------
97+
Limit
98+
-> Index Scan using intervalidx on intervaltmp
99+
Order By: (a <-> '@ 199 days 21 hours 21 mins 23 secs'::interval)
100+
(3 rows)
101+
102+
SELECT a, a <-> '199 days 21:21:23' FROM intervaltmp ORDER BY a <-> '199 days 21:21:23' LIMIT 3;
103+
a | ?column?
104+
-------------------------------------+--------------------------------------
105+
@ 199 days 21 hours 21 mins 23 secs | @ 0
106+
@ 183 days 6 hours 52 mins 48 secs | @ 16 days 14 hours 28 mins 35 secs
107+
@ 220 days 19 hours 5 mins 42 secs | @ 21 days -2 hours -15 mins -41 secs
108+
(3 rows)
109+

‎contrib/btree_gist/sql/interval.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,9 @@ SELECT count(*) FROM intervaltmp WHERE a > '199 days 21:21:23'::interval;
3535
EXPLAIN (COSTS OFF)
3636
SELECT a, a<->'199 days 21:21:23'FROM intervaltmpORDER BY a<->'199 days 21:21:23'LIMIT3;
3737
SELECT a, a<->'199 days 21:21:23'FROM intervaltmpORDER BY a<->'199 days 21:21:23'LIMIT3;
38+
39+
SET enable_indexonlyscan=off;
40+
41+
EXPLAIN (COSTS OFF)
42+
SELECT a, a<->'199 days 21:21:23'FROM intervaltmpORDER BY a<->'199 days 21:21:23'LIMIT3;
43+
SELECT a, a<->'199 days 21:21:23'FROM intervaltmpORDER BY a<->'199 days 21:21:23'LIMIT3;

‎src/backend/executor/nodeIndexscan.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -966,9 +966,20 @@ ExecInitIndexScan(IndexScan *node, EState *estate, int eflags)
966966
Oidorderbyop=lfirst_oid(lco);
967967
Node*orderbyexpr= (Node*)lfirst(lcx);
968968
OidorderbyType=exprType(orderbyexpr);
969+
OidorderbyColl=exprCollation(orderbyexpr);
970+
SortSupportorderbysort=&indexstate->iss_SortSupport[i];
971+
972+
/* Initialize sort support */
973+
orderbysort->ssup_cxt=CurrentMemoryContext;
974+
orderbysort->ssup_collation=orderbyColl;
975+
/* See cmp_orderbyvals() comments on NULLS LAST */
976+
orderbysort->ssup_nulls_first= false;
977+
/* ssup_attno is unused here and elsewhere */
978+
orderbysort->ssup_attno=0;
979+
/* No abbreviation */
980+
orderbysort->abbreviate= false;
981+
PrepareSortSupportFromOrderingOp(orderbyop,orderbysort);
969982

970-
PrepareSortSupportFromOrderingOp(orderbyop,
971-
&indexstate->iss_SortSupport[i]);
972983
get_typlenbyval(orderbyType,
973984
&indexstate->iss_OrderByTypLens[i],
974985
&indexstate->iss_OrderByTypByVals[i]);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp