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

Commitf4e7ae2

Browse files
committed
Fix SP-GiST scan initialization logic for binary-compatible cases.
Commitac9099f rearranged the logic in spgGetCache() that determinesthe index's attType (nominal input data type) and leafType (actualtype stored in leaf index tuples). Turns out this broke things forthe case where (a) the actual input data type is different from thenominal type, (b) the opclass's config function leaves leafTypedefaulted, and (c) the opclass has no "compress" function. (b) causedus to assign the actual input data type as leafType, and then sincethat's not attType, we complained that a "compress" function isrequired. For non-polymorphic opclasses, condition (a) arises inbinary-compatible cases, such as using SP-GiST text_ops for a varcharcolumn, or using any opclass on a domain over its nominal input type.To fix, use attType for leafType when the index's declared column typeis different from but binary-compatible with attType. Do this only inthe defaulted-leafType case, to avoid overriding any explicitselection made by the opclass.Per bug #17294 from Ilya Anfimov. Back-patch to v14.Discussion:https://postgr.es/m/17294-8f6c7962ce877edc@postgresql.org
1 parent46d665b commitf4e7ae2

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

‎src/backend/access/spgist/spgutils.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include"catalog/pg_amop.h"
2626
#include"commands/vacuum.h"
2727
#include"nodes/nodeFuncs.h"
28+
#include"parser/parse_coerce.h"
2829
#include"storage/bufmgr.h"
2930
#include"storage/indexfsm.h"
3031
#include"storage/lmgr.h"
@@ -218,9 +219,20 @@ spgGetCache(Relation index)
218219
* correctly, so believe leafType if it's given.)
219220
*/
220221
if (!OidIsValid(cache->config.leafType))
222+
{
221223
cache->config.leafType=
222224
TupleDescAttr(RelationGetDescr(index),spgKeyColumn)->atttypid;
223225

226+
/*
227+
* If index column type is binary-coercible to atttype (for
228+
* example, it's a domain over atttype), treat it as plain atttype
229+
* to avoid thinking we need to compress.
230+
*/
231+
if (cache->config.leafType!=atttype&&
232+
IsBinaryCoercible(cache->config.leafType,atttype))
233+
cache->config.leafType=atttype;
234+
}
235+
224236
/* Get the information we need about each relevant datatype */
225237
fillTypeDesc(&cache->attType,atttype);
226238

‎src/test/regress/expected/spgist.out

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,24 @@ DETAIL: Valid values are between "10" and "100".
6565
-- Modify fillfactor in existing index
6666
alter index spgist_point_idx set (fillfactor = 90);
6767
reindex index spgist_point_idx;
68+
-- Test index over a domain
69+
create domain spgist_text as varchar;
70+
create table spgist_domain_tbl (f1 spgist_text);
71+
create index spgist_domain_idx on spgist_domain_tbl using spgist(f1);
72+
insert into spgist_domain_tbl values('fee'), ('fi'), ('fo'), ('fum');
73+
explain (costs off)
74+
select * from spgist_domain_tbl where f1 = 'fo';
75+
QUERY PLAN
76+
-----------------------------------------------
77+
Bitmap Heap Scan on spgist_domain_tbl
78+
Recheck Cond: ((f1)::text = 'fo'::text)
79+
-> Bitmap Index Scan on spgist_domain_idx
80+
Index Cond: ((f1)::text = 'fo'::text)
81+
(4 rows)
82+
83+
select * from spgist_domain_tbl where f1 = 'fo';
84+
f1
85+
----
86+
fo
87+
(1 row)
88+

‎src/test/regress/sql/spgist.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,12 @@ create index spgist_point_idx2 on spgist_point_tbl using spgist(p) with (fillfac
7171
-- Modify fillfactor in existing index
7272
alterindex spgist_point_idxset (fillfactor=90);
7373
reindex index spgist_point_idx;
74+
75+
-- Test index over a domain
76+
createdomainspgist_textasvarchar;
77+
createtablespgist_domain_tbl (f1 spgist_text);
78+
createindexspgist_domain_idxon spgist_domain_tbl using spgist(f1);
79+
insert into spgist_domain_tblvalues('fee'), ('fi'), ('fo'), ('fum');
80+
explain (costs off)
81+
select*from spgist_domain_tblwhere f1='fo';
82+
select*from spgist_domain_tblwhere f1='fo';

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp