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

Commitf897c47

Browse files
committed
Fix "element <@ range" cost estimation.
The statistics-based cost estimation patch for range types broke that, byincorrectly assuming that the left operand of all range oeprators is arange. That lead to a "type x is not a range type" error. Because it took solong for anyone to notice, add a regression test for that case.We still don't do proper statistics-based cost estimation for that, so youjust get a default constant estimate. We should look into implementing that,but this patch at least fixes the regression.Spotted by Tom Lane, when testing query from Josh Berkus.
1 parentf8348ea commitf897c47

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

‎src/backend/utils/adt/rangetypes_selfuncs.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,6 @@ rangesel(PG_FUNCTION_ARGS)
154154
}
155155
}
156156

157-
typcache=range_get_typcache(fcinfo,vardata.vartype);
158-
159157
/*
160158
* OK, there's a Var and a Const we're dealing with here. We need the
161159
* Const to be of same range type as the column, else we can't do anything
@@ -169,6 +167,8 @@ rangesel(PG_FUNCTION_ARGS)
169167
*/
170168
if (operator==OID_RANGE_CONTAINS_ELEM_OP)
171169
{
170+
typcache=range_get_typcache(fcinfo,vardata.vartype);
171+
172172
if (((Const*)other)->consttype==typcache->rngelemtype->type_id)
173173
{
174174
RangeBoundlower,upper;
@@ -185,6 +185,8 @@ rangesel(PG_FUNCTION_ARGS)
185185
}
186186
else
187187
{
188+
typcache=range_get_typcache(fcinfo, ((Const*)other)->consttype);
189+
188190
if (((Const*)other)->consttype==vardata.vartype)
189191
constrange=DatumGetRangeType(((Const*)other)->constvalue);
190192
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,17 @@ select count(*) from test_range_spgist where ir -|- int4range(100,500);
10431043
RESET enable_seqscan;
10441044
RESET enable_indexscan;
10451045
RESET enable_bitmapscan;
1046+
-- test elem <@ range operator
1047+
create table test_range_elem(i int4);
1048+
create index test_range_elem_idx on test_range_elem (i);
1049+
insert into test_range_elem select i from generate_series(1,100) i;
1050+
select count(*) from test_range_elem where i <@ int4range(10,50);
1051+
count
1052+
-------
1053+
40
1054+
(1 row)
1055+
1056+
drop table test_range_elem;
10461057
--
10471058
-- Btree_gist is not included by default, so to test exclusion
10481059
-- constraints with range types, use singleton int ranges for the "="

‎src/test/regress/sql/rangetypes.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,15 @@ RESET enable_seqscan;
286286
RESET enable_indexscan;
287287
RESET enable_bitmapscan;
288288

289+
-- test elem <@ range operator
290+
createtabletest_range_elem(i int4);
291+
createindextest_range_elem_idxon test_range_elem (i);
292+
insert into test_range_elemselect ifrom generate_series(1,100) i;
293+
294+
selectcount(*)from test_range_elemwhere i<@ int4range(10,50);
295+
296+
droptable test_range_elem;
297+
289298
--
290299
-- Btree_gist is not included by default, so to test exclusion
291300
-- constraints with range types, use singleton int ranges for the "="

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp