pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedWrong Results from SP-GiST with Collations
11+ messages / 3 participants
[nested] [flat]
Commits from this thread:
2018-04-16 d90b2904c7 93053aca54 608d1f9711 cf73a5b34a 3397c67272 b15e8f71db Fix broken collation-aware searches in SP-GiST text opclass.
* Wrong Results from SP-GiST with Collations
@ 2018-04-10 16:21 Emre Hasegeli <emre@hasegeli.com>
0 siblings, 1 reply; 11+ messages in thread
From: Emre Hasegeli @ 2018-04-10 16:21 UTC (permalink / raw)
To: pgsql-bugs
Please see:
> # create table t (a text collate "cs_CZ");
> CREATE TABLE
>
> # insert into t values ('c'), ('ch');
> INSERT 0 2
>
> # select * from t where a < 'd';
> a
> ---
> c
> (1 row)
>
> xx2_game=# create index on t using spgist (a);
> CREATE INDEX
>
> xx2_game=# set enable_seqscan = 0;
> SET
>
> xx2_game=# select * from t where a < 'd';
> a
> ----
> c
> ch
> (2 rows)
I assume we don't have any option than removing support for comparison
operators with collations just like btree.
The bug may apply to the other access methods.
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: Wrong Results from SP-GiST with Collations
@ 2018-04-10 16:38 Peter Geoghegan <pg@bowt.ie>
parent: Emre Hasegeli <emre@hasegeli.com>
0 siblings, 1 reply; 11+ messages in thread
From: Peter Geoghegan @ 2018-04-10 16:38 UTC (permalink / raw)
To: emre@hasegeli.com, Teodor Sigaev <teodor@sigaev.ru>; +Cc: pgsql-bugs
On Tue, Apr 10, 2018 at 9:21 AM, Emre Hasegeli <emre@hasegeli.com> wrote:
> I assume we don't have any option than removing support for comparison
> operators with collations just like btree.
I can't imagine how this could ever work, since a non C-collation
string cannot be atomized into tokens like that. Considering each
token successively during a comparison does not always produce the
same answer as a straight comparison against the original string
would.
I believe that there are cases that won't work with *any* glibc or ICU
collation, not just "cs_CZ".
--
Peter Geoghegan
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: Wrong Results from SP-GiST with Collations
@ 2018-04-16 15:16 Emre Hasegeli <emre@hasegeli.com>
parent: Peter Geoghegan <pg@bowt.ie>
0 siblings, 1 reply; 11+ messages in thread
From: Emre Hasegeli @ 2018-04-16 15:16 UTC (permalink / raw)
To: Peter Geoghegan <pg@bowt.ie>; +Cc: Teodor Sigaev <teodor@sigaev.ru>; pgsql-bugs
> I can't imagine how this could ever work, since a non C-collation
> string cannot be atomized into tokens like that. Considering each
> token successively during a comparison does not always produce the
> same answer as a straight comparison against the original string
> would.
I think the only fix is to remove support for those operators from the
operator class. The logic on match_special_index_operator() doesn't
seem to need any change. Patch attached. As far as I understand, we
cannot back-patch catalog changes. In this case, we can leave it
broken and apply the documentation part.
Attachments:
remove-wrong-spgist-text-operators-v00.patch (application/octet-stream, 24.7K) download
diff --git a/doc/src/sgml/spgist.sgml b/doc/src/sgml/spgist.sgml
index 06b7519052..437b17c2ae 100644
--- a/doc/src/sgml/spgist.sgml
+++ b/doc/src/sgml/spgist.sgml
@@ -145,25 +145,21 @@
<literal>&<|</literal>
<literal><<|</literal>
<literal>|>></literal>
<literal>|&></literal>
</entry>
</row>
<row>
<entry><literal>text_ops</literal></entry>
<entry><type>text</type></entry>
<entry>
- <literal><</literal>
- <literal><=</literal>
<literal>=</literal>
- <literal>></literal>
- <literal>>=</literal>
<literal>~<=~</literal>
<literal>~<~</literal>
<literal>~>=~</literal>
<literal>~>~</literal>
<literal>^@</literal>
</entry>
</row>
<row>
<entry><literal>inet_ops</literal></entry>
<entry><type>inet</type>, <type>cidr</type></entry>
@@ -185,20 +181,30 @@
</tgroup>
</table>
<para>
Of the two operator classes for type <type>point</type>,
<literal>quad_point_ops</literal> is the default. <literal>kd_point_ops</literal>
supports the same operators but uses a different index data structure which
may offer better performance in some applications.
</para>
+ <warning>
+ <para>
+ Before PostgreSQL 11, the basic comparison operators <literal><</literal>,
+ <literal><=</literal>, <literal>></literal>, and <literal>>=</literal>
+ were also supported by <acronym>SP-GiST</acronym> <literal>text_ops</literal>.
+ They may return wrong results in collation sensive cases hence should not
+ be used.
+ </para>
+ </warning>
+
</sect1>
<sect1 id="spgist-extensibility">
<title>Extensibility</title>
<para>
<acronym>SP-GiST</acronym> offers an interface with a high level of
abstraction, requiring the access method developer to implement only
methods specific to a given data type. The <acronym>SP-GiST</acronym> core
is responsible for efficient disk mapping and searching the tree structure.
diff --git a/src/include/catalog/pg_amop.dat b/src/include/catalog/pg_amop.dat
index b1cf8ec5fc..70b3789c36 100644
--- a/src/include/catalog/pg_amop.dat
+++ b/src/include/catalog/pg_amop.dat
@@ -1431,32 +1431,20 @@
amopmethod => 'spgist' },
{ amopfamily => 'spgist/text_ops', amoplefttype => 'text',
amoprighttype => 'text', amopstrategy => '3', amopopr => '=(text,text)',
amopmethod => 'spgist' },
{ amopfamily => 'spgist/text_ops', amoplefttype => 'text',
amoprighttype => 'text', amopstrategy => '4', amopopr => '~>=~(text,text)',
amopmethod => 'spgist' },
{ amopfamily => 'spgist/text_ops', amoplefttype => 'text',
amoprighttype => 'text', amopstrategy => '5', amopopr => '~>~(text,text)',
amopmethod => 'spgist' },
-{ amopfamily => 'spgist/text_ops', amoplefttype => 'text',
- amoprighttype => 'text', amopstrategy => '11', amopopr => '<(text,text)',
- amopmethod => 'spgist' },
-{ amopfamily => 'spgist/text_ops', amoplefttype => 'text',
- amoprighttype => 'text', amopstrategy => '12', amopopr => '<=(text,text)',
- amopmethod => 'spgist' },
-{ amopfamily => 'spgist/text_ops', amoplefttype => 'text',
- amoprighttype => 'text', amopstrategy => '14', amopopr => '>=(text,text)',
- amopmethod => 'spgist' },
-{ amopfamily => 'spgist/text_ops', amoplefttype => 'text',
- amoprighttype => 'text', amopstrategy => '15', amopopr => '>(text,text)',
- amopmethod => 'spgist' },
{ amopfamily => 'spgist/text_ops', amoplefttype => 'text',
amoprighttype => 'text', amopstrategy => '28', amopopr => '^@(text,text)',
amopmethod => 'spgist' },
# btree jsonb_ops
{ amopfamily => 'btree/jsonb_ops', amoplefttype => 'jsonb',
amoprighttype => 'jsonb', amopstrategy => '1', amopopr => '<(jsonb,jsonb)',
amopmethod => 'btree' },
{ amopfamily => 'btree/jsonb_ops', amoplefttype => 'jsonb',
amoprighttype => 'jsonb', amopstrategy => '2', amopopr => '<=(jsonb,jsonb)',
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index fe5b698669..43f9242b03 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -305,74 +305,50 @@ SELECT count(*) FROM radix_text_tbl WHERE t = 'P0123456789abcde';
-------
1
(1 row)
SELECT count(*) FROM radix_text_tbl WHERE t = 'P0123456789abcdefF';
count
-------
1
(1 row)
-SELECT count(*) FROM radix_text_tbl WHERE t < 'Aztec Ct ';
- count
--------
- 272
-(1 row)
-
SELECT count(*) FROM radix_text_tbl WHERE t ~<~ 'Aztec Ct ';
count
-------
272
(1 row)
-SELECT count(*) FROM radix_text_tbl WHERE t <= 'Aztec Ct ';
- count
--------
- 273
-(1 row)
-
SELECT count(*) FROM radix_text_tbl WHERE t ~<=~ 'Aztec Ct ';
count
-------
273
(1 row)
SELECT count(*) FROM radix_text_tbl WHERE t = 'Aztec Ct ';
count
-------
1
(1 row)
SELECT count(*) FROM radix_text_tbl WHERE t = 'Worth St ';
count
-------
2
(1 row)
-SELECT count(*) FROM radix_text_tbl WHERE t >= 'Worth St ';
- count
--------
- 50
-(1 row)
-
SELECT count(*) FROM radix_text_tbl WHERE t ~>=~ 'Worth St ';
count
-------
50
(1 row)
-SELECT count(*) FROM radix_text_tbl WHERE t > 'Worth St ';
- count
--------
- 48
-(1 row)
-
SELECT count(*) FROM radix_text_tbl WHERE t ~>~ 'Worth St ';
count
-------
48
(1 row)
SELECT count(*) FROM radix_text_tbl WHERE t ^@ 'Worth';
count
-------
2
@@ -1031,65 +1007,35 @@ SELECT count(*) FROM radix_text_tbl WHERE t = 'P0123456789abcdefF';
-> Index Only Scan using sp_radix_ind on radix_text_tbl
Index Cond: (t = 'P0123456789abcdefF'::text)
(3 rows)
SELECT count(*) FROM radix_text_tbl WHERE t = 'P0123456789abcdefF';
count
-------
1
(1 row)
-EXPLAIN (COSTS OFF)
-SELECT count(*) FROM radix_text_tbl WHERE t < 'Aztec Ct ';
- QUERY PLAN
-----------------------------------------------------------------------
- Aggregate
- -> Index Only Scan using sp_radix_ind on radix_text_tbl
- Index Cond: (t < 'Aztec Ct '::text)
-(3 rows)
-
-SELECT count(*) FROM radix_text_tbl WHERE t < 'Aztec Ct ';
- count
--------
- 272
-(1 row)
-
EXPLAIN (COSTS OFF)
SELECT count(*) FROM radix_text_tbl WHERE t ~<~ 'Aztec Ct ';
QUERY PLAN
------------------------------------------------------------------------
Aggregate
-> Index Only Scan using sp_radix_ind on radix_text_tbl
Index Cond: (t ~<~ 'Aztec Ct '::text)
(3 rows)
SELECT count(*) FROM radix_text_tbl WHERE t ~<~ 'Aztec Ct ';
count
-------
272
(1 row)
-EXPLAIN (COSTS OFF)
-SELECT count(*) FROM radix_text_tbl WHERE t <= 'Aztec Ct ';
- QUERY PLAN
------------------------------------------------------------------------
- Aggregate
- -> Index Only Scan using sp_radix_ind on radix_text_tbl
- Index Cond: (t <= 'Aztec Ct '::text)
-(3 rows)
-
-SELECT count(*) FROM radix_text_tbl WHERE t <= 'Aztec Ct ';
- count
--------
- 273
-(1 row)
-
EXPLAIN (COSTS OFF)
SELECT count(*) FROM radix_text_tbl WHERE t ~<=~ 'Aztec Ct ';
QUERY PLAN
-------------------------------------------------------------------------
Aggregate
-> Index Only Scan using sp_radix_ind on radix_text_tbl
Index Cond: (t ~<=~ 'Aztec Ct '::text)
(3 rows)
SELECT count(*) FROM radix_text_tbl WHERE t ~<=~ 'Aztec Ct ';
@@ -1121,65 +1067,35 @@ SELECT count(*) FROM radix_text_tbl WHERE t = 'Worth
-> Index Only Scan using sp_radix_ind on radix_text_tbl
Index Cond: (t = 'Worth St '::text)
(3 rows)
SELECT count(*) FROM radix_text_tbl WHERE t = 'Worth St ';
count
-------
2
(1 row)
-EXPLAIN (COSTS OFF)
-SELECT count(*) FROM radix_text_tbl WHERE t >= 'Worth St ';
- QUERY PLAN
------------------------------------------------------------------------
- Aggregate
- -> Index Only Scan using sp_radix_ind on radix_text_tbl
- Index Cond: (t >= 'Worth St '::text)
-(3 rows)
-
-SELECT count(*) FROM radix_text_tbl WHERE t >= 'Worth St ';
- count
--------
- 50
-(1 row)
-
EXPLAIN (COSTS OFF)
SELECT count(*) FROM radix_text_tbl WHERE t ~>=~ 'Worth St ';
QUERY PLAN
-------------------------------------------------------------------------
Aggregate
-> Index Only Scan using sp_radix_ind on radix_text_tbl
Index Cond: (t ~>=~ 'Worth St '::text)
(3 rows)
SELECT count(*) FROM radix_text_tbl WHERE t ~>=~ 'Worth St ';
count
-------
50
(1 row)
-EXPLAIN (COSTS OFF)
-SELECT count(*) FROM radix_text_tbl WHERE t > 'Worth St ';
- QUERY PLAN
-----------------------------------------------------------------------
- Aggregate
- -> Index Only Scan using sp_radix_ind on radix_text_tbl
- Index Cond: (t > 'Worth St '::text)
-(3 rows)
-
-SELECT count(*) FROM radix_text_tbl WHERE t > 'Worth St ';
- count
--------
- 48
-(1 row)
-
EXPLAIN (COSTS OFF)
SELECT count(*) FROM radix_text_tbl WHERE t ~>~ 'Worth St ';
QUERY PLAN
------------------------------------------------------------------------
Aggregate
-> Index Only Scan using sp_radix_ind on radix_text_tbl
Index Cond: (t ~>~ 'Worth St '::text)
(3 rows)
SELECT count(*) FROM radix_text_tbl WHERE t ~>~ 'Worth St ';
@@ -1607,71 +1523,37 @@ SELECT count(*) FROM radix_text_tbl WHERE t = 'P0123456789abcdefF';
-> Bitmap Index Scan on sp_radix_ind
Index Cond: (t = 'P0123456789abcdefF'::text)
(5 rows)
SELECT count(*) FROM radix_text_tbl WHERE t = 'P0123456789abcdefF';
count
-------
1
(1 row)
-EXPLAIN (COSTS OFF)
-SELECT count(*) FROM radix_text_tbl WHERE t < 'Aztec Ct ';
- QUERY PLAN
-----------------------------------------------------------------------------
- Aggregate
- -> Bitmap Heap Scan on radix_text_tbl
- Recheck Cond: (t < 'Aztec Ct '::text)
- -> Bitmap Index Scan on sp_radix_ind
- Index Cond: (t < 'Aztec Ct '::text)
-(5 rows)
-
-SELECT count(*) FROM radix_text_tbl WHERE t < 'Aztec Ct ';
- count
--------
- 272
-(1 row)
-
EXPLAIN (COSTS OFF)
SELECT count(*) FROM radix_text_tbl WHERE t ~<~ 'Aztec Ct ';
QUERY PLAN
------------------------------------------------------------------------------
Aggregate
-> Bitmap Heap Scan on radix_text_tbl
Recheck Cond: (t ~<~ 'Aztec Ct '::text)
-> Bitmap Index Scan on sp_radix_ind
Index Cond: (t ~<~ 'Aztec Ct '::text)
(5 rows)
SELECT count(*) FROM radix_text_tbl WHERE t ~<~ 'Aztec Ct ';
count
-------
272
(1 row)
-EXPLAIN (COSTS OFF)
-SELECT count(*) FROM radix_text_tbl WHERE t <= 'Aztec Ct ';
- QUERY PLAN
------------------------------------------------------------------------------
- Aggregate
- -> Bitmap Heap Scan on radix_text_tbl
- Recheck Cond: (t <= 'Aztec Ct '::text)
- -> Bitmap Index Scan on sp_radix_ind
- Index Cond: (t <= 'Aztec Ct '::text)
-(5 rows)
-
-SELECT count(*) FROM radix_text_tbl WHERE t <= 'Aztec Ct ';
- count
--------
- 273
-(1 row)
-
EXPLAIN (COSTS OFF)
SELECT count(*) FROM radix_text_tbl WHERE t ~<=~ 'Aztec Ct ';
QUERY PLAN
-------------------------------------------------------------------------------
Aggregate
-> Bitmap Heap Scan on radix_text_tbl
Recheck Cond: (t ~<=~ 'Aztec Ct '::text)
-> Bitmap Index Scan on sp_radix_ind
Index Cond: (t ~<=~ 'Aztec Ct '::text)
(5 rows)
@@ -1709,71 +1591,37 @@ SELECT count(*) FROM radix_text_tbl WHERE t = 'Worth
-> Bitmap Index Scan on sp_radix_ind
Index Cond: (t = 'Worth St '::text)
(5 rows)
SELECT count(*) FROM radix_text_tbl WHERE t = 'Worth St ';
count
-------
2
(1 row)
-EXPLAIN (COSTS OFF)
-SELECT count(*) FROM radix_text_tbl WHERE t >= 'Worth St ';
- QUERY PLAN
------------------------------------------------------------------------------
- Aggregate
- -> Bitmap Heap Scan on radix_text_tbl
- Recheck Cond: (t >= 'Worth St '::text)
- -> Bitmap Index Scan on sp_radix_ind
- Index Cond: (t >= 'Worth St '::text)
-(5 rows)
-
-SELECT count(*) FROM radix_text_tbl WHERE t >= 'Worth St ';
- count
--------
- 50
-(1 row)
-
EXPLAIN (COSTS OFF)
SELECT count(*) FROM radix_text_tbl WHERE t ~>=~ 'Worth St ';
QUERY PLAN
-------------------------------------------------------------------------------
Aggregate
-> Bitmap Heap Scan on radix_text_tbl
Recheck Cond: (t ~>=~ 'Worth St '::text)
-> Bitmap Index Scan on sp_radix_ind
Index Cond: (t ~>=~ 'Worth St '::text)
(5 rows)
SELECT count(*) FROM radix_text_tbl WHERE t ~>=~ 'Worth St ';
count
-------
50
(1 row)
-EXPLAIN (COSTS OFF)
-SELECT count(*) FROM radix_text_tbl WHERE t > 'Worth St ';
- QUERY PLAN
-----------------------------------------------------------------------------
- Aggregate
- -> Bitmap Heap Scan on radix_text_tbl
- Recheck Cond: (t > 'Worth St '::text)
- -> Bitmap Index Scan on sp_radix_ind
- Index Cond: (t > 'Worth St '::text)
-(5 rows)
-
-SELECT count(*) FROM radix_text_tbl WHERE t > 'Worth St ';
- count
--------
- 48
-(1 row)
-
EXPLAIN (COSTS OFF)
SELECT count(*) FROM radix_text_tbl WHERE t ~>~ 'Worth St ';
QUERY PLAN
------------------------------------------------------------------------------
Aggregate
-> Bitmap Heap Scan on radix_text_tbl
Recheck Cond: (t ~>~ 'Worth St '::text)
-> Bitmap Index Scan on sp_radix_ind
Index Cond: (t ~>~ 'Worth St '::text)
(5 rows)
diff --git a/src/test/regress/expected/opr_sanity.out b/src/test/regress/expected/opr_sanity.out
index a1e18a6ceb..6e59fcac26 100644
--- a/src/test/regress/expected/opr_sanity.out
+++ b/src/test/regress/expected/opr_sanity.out
@@ -1863,40 +1863,36 @@ ORDER BY 1, 2, 3;
4000 | 4 | ~>=~
4000 | 5 | >>
4000 | 5 | ~>~
4000 | 6 | -|-
4000 | 6 | ~=
4000 | 7 | @>
4000 | 8 | <@
4000 | 9 | &<|
4000 | 10 | <<|
4000 | 10 | <^
- 4000 | 11 | <
4000 | 11 | >^
4000 | 11 | |>>
- 4000 | 12 | <=
4000 | 12 | |&>
- 4000 | 14 | >=
- 4000 | 15 | >
4000 | 16 | @>
4000 | 18 | =
4000 | 19 | <>
4000 | 20 | <
4000 | 21 | <=
4000 | 22 | >
4000 | 23 | >=
4000 | 24 | <<
4000 | 25 | <<=
4000 | 26 | >>
4000 | 27 | >>=
4000 | 28 | ^@
-(122 rows)
+(118 rows)
-- Check that all opclass search operators have selectivity estimators.
-- This is not absolutely required, but it seems a reasonable thing
-- to insist on for all standard datatypes.
SELECT p1.amopfamily, p1.amopopr, p2.oid, p2.oprname
FROM pg_amop AS p1, pg_operator AS p2
WHERE p1.amopopr = p2.oid AND p1.amoppurpose = 's' AND
(p2.oprrest = 0 OR p2.oprjoin = 0);
amopfamily | amopopr | oid | oprname
------------+---------+-----+---------
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index f7731265a0..2b24747c44 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -197,38 +197,30 @@ SELECT count(*) FROM quad_point_tbl WHERE p <^ '(5000, 4000)';
SELECT count(*) FROM quad_point_tbl WHERE p >^ '(5000, 4000)';
SELECT count(*) FROM quad_point_tbl WHERE p ~= '(4585, 365)';
SELECT count(*) FROM radix_text_tbl WHERE t = 'P0123456789abcdef';
SELECT count(*) FROM radix_text_tbl WHERE t = 'P0123456789abcde';
SELECT count(*) FROM radix_text_tbl WHERE t = 'P0123456789abcdefF';
-SELECT count(*) FROM radix_text_tbl WHERE t < 'Aztec Ct ';
-
SELECT count(*) FROM radix_text_tbl WHERE t ~<~ 'Aztec Ct ';
-SELECT count(*) FROM radix_text_tbl WHERE t <= 'Aztec Ct ';
-
SELECT count(*) FROM radix_text_tbl WHERE t ~<=~ 'Aztec Ct ';
SELECT count(*) FROM radix_text_tbl WHERE t = 'Aztec Ct ';
SELECT count(*) FROM radix_text_tbl WHERE t = 'Worth St ';
-SELECT count(*) FROM radix_text_tbl WHERE t >= 'Worth St ';
-
SELECT count(*) FROM radix_text_tbl WHERE t ~>=~ 'Worth St ';
-SELECT count(*) FROM radix_text_tbl WHERE t > 'Worth St ';
-
SELECT count(*) FROM radix_text_tbl WHERE t ~>~ 'Worth St ';
SELECT count(*) FROM radix_text_tbl WHERE t ^@ 'Worth';
SELECT * FROM gpolygon_tbl ORDER BY f1 <-> '(0,0)'::point LIMIT 10;
SELECT circle_center(f1), round(radius(f1)) as radius FROM gcircle_tbl ORDER BY f1 <-> '(200,300)'::point LIMIT 10;
-- Now check the results from plain indexscan
SET enable_seqscan = OFF;
@@ -396,56 +388,40 @@ SELECT count(*) FROM radix_text_tbl WHERE t = 'P0123456789abcdef';
SELECT count(*) FROM radix_text_tbl WHERE t = 'P0123456789abcdef';
EXPLAIN (COSTS OFF)
SELECT count(*) FROM radix_text_tbl WHERE t = 'P0123456789abcde';
SELECT count(*) FROM radix_text_tbl WHERE t = 'P0123456789abcde';
EXPLAIN (COSTS OFF)
SELECT count(*) FROM radix_text_tbl WHERE t = 'P0123456789abcdefF';
SELECT count(*) FROM radix_text_tbl WHERE t = 'P0123456789abcdefF';
-EXPLAIN (COSTS OFF)
-SELECT count(*) FROM radix_text_tbl WHERE t < 'Aztec Ct ';
-SELECT count(*) FROM radix_text_tbl WHERE t < 'Aztec Ct ';
-
EXPLAIN (COSTS OFF)
SELECT count(*) FROM radix_text_tbl WHERE t ~<~ 'Aztec Ct ';
SELECT count(*) FROM radix_text_tbl WHERE t ~<~ 'Aztec Ct ';
-EXPLAIN (COSTS OFF)
-SELECT count(*) FROM radix_text_tbl WHERE t <= 'Aztec Ct ';
-SELECT count(*) FROM radix_text_tbl WHERE t <= 'Aztec Ct ';
-
EXPLAIN (COSTS OFF)
SELECT count(*) FROM radix_text_tbl WHERE t ~<=~ 'Aztec Ct ';
SELECT count(*) FROM radix_text_tbl WHERE t ~<=~ 'Aztec Ct ';
EXPLAIN (COSTS OFF)
SELECT count(*) FROM radix_text_tbl WHERE t = 'Aztec Ct ';
SELECT count(*) FROM radix_text_tbl WHERE t = 'Aztec Ct ';
EXPLAIN (COSTS OFF)
SELECT count(*) FROM radix_text_tbl WHERE t = 'Worth St ';
SELECT count(*) FROM radix_text_tbl WHERE t = 'Worth St ';
-EXPLAIN (COSTS OFF)
-SELECT count(*) FROM radix_text_tbl WHERE t >= 'Worth St ';
-SELECT count(*) FROM radix_text_tbl WHERE t >= 'Worth St ';
-
EXPLAIN (COSTS OFF)
SELECT count(*) FROM radix_text_tbl WHERE t ~>=~ 'Worth St ';
SELECT count(*) FROM radix_text_tbl WHERE t ~>=~ 'Worth St ';
-EXPLAIN (COSTS OFF)
-SELECT count(*) FROM radix_text_tbl WHERE t > 'Worth St ';
-SELECT count(*) FROM radix_text_tbl WHERE t > 'Worth St ';
-
EXPLAIN (COSTS OFF)
SELECT count(*) FROM radix_text_tbl WHERE t ~>~ 'Worth St ';
SELECT count(*) FROM radix_text_tbl WHERE t ~>~ 'Worth St ';
EXPLAIN (COSTS OFF)
SELECT count(*) FROM radix_text_tbl WHERE t ^@ 'Worth';
SELECT count(*) FROM radix_text_tbl WHERE t ^@ 'Worth';
EXPLAIN (COSTS OFF)
SELECT * FROM gpolygon_tbl ORDER BY f1 <-> '(0,0)'::point LIMIT 10;
@@ -537,56 +513,40 @@ SELECT count(*) FROM radix_text_tbl WHERE t = 'P0123456789abcdef';
SELECT count(*) FROM radix_text_tbl WHERE t = 'P0123456789abcdef';
EXPLAIN (COSTS OFF)
SELECT count(*) FROM radix_text_tbl WHERE t = 'P0123456789abcde';
SELECT count(*) FROM radix_text_tbl WHERE t = 'P0123456789abcde';
EXPLAIN (COSTS OFF)
SELECT count(*) FROM radix_text_tbl WHERE t = 'P0123456789abcdefF';
SELECT count(*) FROM radix_text_tbl WHERE t = 'P0123456789abcdefF';
-EXPLAIN (COSTS OFF)
-SELECT count(*) FROM radix_text_tbl WHERE t < 'Aztec Ct ';
-SELECT count(*) FROM radix_text_tbl WHERE t < 'Aztec Ct ';
-
EXPLAIN (COSTS OFF)
SELECT count(*) FROM radix_text_tbl WHERE t ~<~ 'Aztec Ct ';
SELECT count(*) FROM radix_text_tbl WHERE t ~<~ 'Aztec Ct ';
-EXPLAIN (COSTS OFF)
-SELECT count(*) FROM radix_text_tbl WHERE t <= 'Aztec Ct ';
-SELECT count(*) FROM radix_text_tbl WHERE t <= 'Aztec Ct ';
-
EXPLAIN (COSTS OFF)
SELECT count(*) FROM radix_text_tbl WHERE t ~<=~ 'Aztec Ct ';
SELECT count(*) FROM radix_text_tbl WHERE t ~<=~ 'Aztec Ct ';
EXPLAIN (COSTS OFF)
SELECT count(*) FROM radix_text_tbl WHERE t = 'Aztec Ct ';
SELECT count(*) FROM radix_text_tbl WHERE t = 'Aztec Ct ';
EXPLAIN (COSTS OFF)
SELECT count(*) FROM radix_text_tbl WHERE t = 'Worth St ';
SELECT count(*) FROM radix_text_tbl WHERE t = 'Worth St ';
-EXPLAIN (COSTS OFF)
-SELECT count(*) FROM radix_text_tbl WHERE t >= 'Worth St ';
-SELECT count(*) FROM radix_text_tbl WHERE t >= 'Worth St ';
-
EXPLAIN (COSTS OFF)
SELECT count(*) FROM radix_text_tbl WHERE t ~>=~ 'Worth St ';
SELECT count(*) FROM radix_text_tbl WHERE t ~>=~ 'Worth St ';
-EXPLAIN (COSTS OFF)
-SELECT count(*) FROM radix_text_tbl WHERE t > 'Worth St ';
-SELECT count(*) FROM radix_text_tbl WHERE t > 'Worth St ';
-
EXPLAIN (COSTS OFF)
SELECT count(*) FROM radix_text_tbl WHERE t ~>~ 'Worth St ';
SELECT count(*) FROM radix_text_tbl WHERE t ~>~ 'Worth St ';
EXPLAIN (COSTS OFF)
SELECT count(*) FROM radix_text_tbl WHERE t ^@ 'Worth';
SELECT count(*) FROM radix_text_tbl WHERE t ^@ 'Worth';
RESET enable_seqscan;
RESET enable_indexscan;
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: Wrong Results from SP-GiST with Collations
@ 2018-04-16 16:38 Peter Geoghegan <pg@bowt.ie>
parent: Emre Hasegeli <emre@hasegeli.com>
0 siblings, 2 replies; 11+ messages in thread
From: Peter Geoghegan @ 2018-04-16 16:38 UTC (permalink / raw)
To: Emre Hasegeli <emre@hasegeli.com>; +Cc: Teodor Sigaev <teodor@sigaev.ru>; pgsql-bugs
On Mon, Apr 16, 2018 at 8:16 AM, Emre Hasegeli <emre@hasegeli.com> wrote:
> I think the only fix is to remove support for those operators from the
> operator class. The logic on match_special_index_operator() doesn't
> seem to need any change. Patch attached. As far as I understand, we
> cannot back-patch catalog changes. In this case, we can leave it
> broken and apply the documentation part.
Has the operator class really been completely broken since SP-GiST was
first introduced? I tend to doubt that. spg_text_inner_consistent()
has the following code, which appears to acknowledge the problem with
non-C collations:
for (j = 0; j < in->nkeys; j++)
{
StrategyNumber strategy = in->scankeys[j].sk_strategy;
text *inText;
int inSize;
int r;
/*
* If it's a collation-aware operator, but the collation is C, we
* can treat it as non-collation-aware. With non-C collation we
* need to traverse whole tree :-( so there's no point in making
* any check here. (Note also that our reconstructed value may
* well end with a partial multibyte character, so that applying
* any encoding-sensitive test to it would be risky anyhow.)
*/
if (SPG_IS_COLLATION_AWARE_STRATEGY(strategy))
{
if (collate_is_c)
strategy -= SPG_STRATEGY_ADDITION;
else
continue;
}
Maybe this is a simple, relatively benign bug. Maybe this problem is
due to commit 710d90da, which is only a couple of weeks old. Have you
reproduced the problem on v10 of Postgres?
--
Peter Geoghegan
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: Wrong Results from SP-GiST with Collations
@ 2018-04-16 17:59 Emre Hasegeli <emre@hasegeli.com>
parent: Peter Geoghegan <pg@bowt.ie>
1 sibling, 0 replies; 11+ messages in thread
From: Emre Hasegeli @ 2018-04-16 17:59 UTC (permalink / raw)
To: Peter Geoghegan <pg@bowt.ie>; +Cc: Teodor Sigaev <teodor@sigaev.ru>; pgsql-bugs
> Maybe this is a simple, relatively benign bug. Maybe this problem is
> due to commit 710d90da, which is only a couple of weeks old. Have you
> reproduced the problem on v10 of Postgres?
Yes, the initial example I posted was from 9.5.12 on Debian.
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: Wrong Results from SP-GiST with Collations
@ 2018-04-16 18:51 Tom Lane <tgl@sss.pgh.pa.us>
parent: Peter Geoghegan <pg@bowt.ie>
1 sibling, 1 reply; 11+ messages in thread
From: Tom Lane @ 2018-04-16 18:51 UTC (permalink / raw)
To: Peter Geoghegan <pg@bowt.ie>; +Cc: Emre Hasegeli <emre@hasegeli.com>; Teodor Sigaev <teodor@sigaev.ru>; pgsql-bugs
Peter Geoghegan <pg@bowt.ie> writes:
> Has the operator class really been completely broken since SP-GiST was
> first introduced? I tend to doubt that. spg_text_inner_consistent()
> has the following code, which appears to acknowledge the problem with
> non-C collations:
You're on to something, but I think the bug is in
spg_text_leaf_consistent, which thinks it can do collation-aware
comparisons like this:
r = varstr_cmp(fullValue, Min(queryLen, fullLen),
VARDATA_ANY(query), Min(queryLen, fullLen),
PG_GET_COLLATION());
That's got nothing to do with reality for non-C collations, and it seems
rather pointless anyway, Why isn't this just
r = varstr_cmp(fullValue, fullLen,
VARDATA_ANY(query), queryLen,
PG_GET_COLLATION());
and then the bit below about
if (r == 0)
{
if (queryLen > fullLen)
r = -1;
else if (queryLen < fullLen)
r = 1;
}
needs to move into the "non-collation-aware" branch.
regards, tom lane
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: Wrong Results from SP-GiST with Collations
@ 2018-04-16 19:19 Peter Geoghegan <pg@bowt.ie>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 11+ messages in thread
From: Peter Geoghegan @ 2018-04-16 19:19 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Emre Hasegeli <emre@hasegeli.com>; Teodor Sigaev <teodor@sigaev.ru>; pgsql-bugs
On Mon, Apr 16, 2018 at 11:51 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> You're on to something, but I think the bug is in
> spg_text_leaf_consistent, which thinks it can do collation-aware
> comparisons like this:
>
> r = varstr_cmp(fullValue, Min(queryLen, fullLen),
> VARDATA_ANY(query), Min(queryLen, fullLen),
> PG_GET_COLLATION());
Ah. Those arguments make that code completely broken.
> and then the bit below about
>
> if (r == 0)
> {
> if (queryLen > fullLen)
> r = -1;
> else if (queryLen < fullLen)
> r = 1;
> }
>
> needs to move into the "non-collation-aware" branch.
Right. Alternatively, you could actually call varstr_cmp() within the
"non-collation-aware" branch.
--
Peter Geoghegan
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: Wrong Results from SP-GiST with Collations
@ 2018-04-16 19:28 Tom Lane <tgl@sss.pgh.pa.us>
parent: Peter Geoghegan <pg@bowt.ie>
0 siblings, 1 reply; 11+ messages in thread
From: Tom Lane @ 2018-04-16 19:28 UTC (permalink / raw)
To: Peter Geoghegan <pg@bowt.ie>; +Cc: Emre Hasegeli <emre@hasegeli.com>; Teodor Sigaev <teodor@sigaev.ru>; pgsql-bugs
Peter Geoghegan <pg@bowt.ie> writes:
> On Mon, Apr 16, 2018 at 11:51 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> and then the bit below about ...
>> needs to move into the "non-collation-aware" branch.
> Right. Alternatively, you could actually call varstr_cmp() within the
> "non-collation-aware" branch.
True. This way saves a few cycles, but maybe it's not worth the extra
code. I think the only case where you could really notice the difference
is for an equality search operator, which might end up doing a lot more
work in non-C collations (full-blown strcoll vs memcmp).
regards, tom lane
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: Wrong Results from SP-GiST with Collations
@ 2018-04-16 19:39 Peter Geoghegan <pg@bowt.ie>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 11+ messages in thread
From: Peter Geoghegan @ 2018-04-16 19:39 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Emre Hasegeli <emre@hasegeli.com>; Teodor Sigaev <teodor@sigaev.ru>; pgsql-bugs
On Mon, Apr 16, 2018 at 12:28 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> Right. Alternatively, you could actually call varstr_cmp() within the
>> "non-collation-aware" branch.
>
> True. This way saves a few cycles, but maybe it's not worth the extra
> code. I think the only case where you could really notice the difference
> is for an equality search operator, which might end up doing a lot more
> work in non-C collations (full-blown strcoll vs memcmp).
I don't have a full understanding of this particular problem, but it
sounds to me that that would be a non-issue due to the equality
fast-path added to varstr_cmp() several years ago. I microbenchmarked
it quite extensively at the time, and concluded that it was all but
free in cases where it didn't work out.
--
Peter Geoghegan
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: Wrong Results from SP-GiST with Collations
@ 2018-04-16 19:55 Tom Lane <tgl@sss.pgh.pa.us>
parent: Peter Geoghegan <pg@bowt.ie>
0 siblings, 1 reply; 11+ messages in thread
From: Tom Lane @ 2018-04-16 19:55 UTC (permalink / raw)
To: Peter Geoghegan <pg@bowt.ie>; +Cc: Emre Hasegeli <emre@hasegeli.com>; Teodor Sigaev <teodor@sigaev.ru>; pgsql-bugs
Peter Geoghegan <pg@bowt.ie> writes:
> On Mon, Apr 16, 2018 at 12:28 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> True. This way saves a few cycles, but maybe it's not worth the extra
>> code. I think the only case where you could really notice the difference
>> is for an equality search operator, which might end up doing a lot more
>> work in non-C collations (full-blown strcoll vs memcmp).
> I don't have a full understanding of this particular problem, but it
> sounds to me that that would be a non-issue due to the equality
> fast-path added to varstr_cmp() several years ago. I microbenchmarked
> it quite extensively at the time, and concluded that it was all but
> free in cases where it didn't work out.
I'm not following --- varstr_cmp has no way to know that we only
care about equality vs inequality. Yes, it might give back an
answer quickly when the strings are equal, but when they aren't,
it has to decide which is greater. In this case we don't care,
so long as the search operator is "=".
regards, tom lane
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: Wrong Results from SP-GiST with Collations
@ 2018-04-16 19:58 Peter Geoghegan <pg@bowt.ie>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 11+ messages in thread
From: Peter Geoghegan @ 2018-04-16 19:58 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Emre Hasegeli <emre@hasegeli.com>; Teodor Sigaev <teodor@sigaev.ru>; pgsql-bugs
On Mon, Apr 16, 2018 at 12:55 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> I'm not following --- varstr_cmp has no way to know that we only
> care about equality vs inequality. Yes, it might give back an
> answer quickly when the strings are equal, but when they aren't,
> it has to decide which is greater. In this case we don't care,
> so long as the search operator is "=".
That was the subtlety I was missing. I didn't understand what you
meant, but thought that the fast-path might be relevant. Clearly not.
--
Peter Geoghegan
^ permalink raw reply [nested|flat] 11+ messages in thread
end of thread, other threads:[~2018-04-16 19:58 UTC | newest]
Thread overview: 11+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-04-10 16:21 Wrong Results from SP-GiST with Collations Emre Hasegeli <emre@hasegeli.com>
2018-04-10 16:38 ` Peter Geoghegan <pg@bowt.ie>
2018-04-16 15:16 ` Emre Hasegeli <emre@hasegeli.com>
2018-04-16 16:38 ` Peter Geoghegan <pg@bowt.ie>
2018-04-16 17:59 ` Emre Hasegeli <emre@hasegeli.com>
2018-04-16 18:51 ` Tom Lane <tgl@sss.pgh.pa.us>
2018-04-16 19:19 ` Peter Geoghegan <pg@bowt.ie>
2018-04-16 19:28 ` Tom Lane <tgl@sss.pgh.pa.us>
2018-04-16 19:39 ` Peter Geoghegan <pg@bowt.ie>
2018-04-16 19:55 ` Tom Lane <tgl@sss.pgh.pa.us>
2018-04-16 19:58 ` Peter Geoghegan <pg@bowt.ie>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox