Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit abb9c63

Browse files
committed
Unbreak index optimization for LIKE on bytea
The same code is used to handle both text and bytea, but bytea is not collation-aware, so we shouldn't call get_collation_isdeterministic() in that case, since that will error out with an invalid collation. Reported-by: Jeevan Chalke <jeevan.chalke@enterprisedb.com> Discussion: https://www.postgresql.org/message-id/flat/CAM2%2B6%3DWaf3qJ1%3DyVTUH8_yG-SC0xcBMY%2BSFLhvKKNnWNXSUDBw%40mail.gmail.com
1 parent c34677f commit abb9c63

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

src/backend/utils/adt/like_support.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,10 @@ match_pattern_prefix(Node *leftop,
267267
* precise error messages.) (It should be possible to support at least
268268
* Pattern_Prefix_Exact, but no point as along as the actual
269269
* pattern-matching implementations don't support it.)
270+
*
271+
* expr_coll is not set for a non-collation-aware data type such as bytea.
270272
*/
271-
if (!get_collation_isdeterministic(expr_coll))
273+
if (expr_coll && !get_collation_isdeterministic(expr_coll))
272274
return NIL;
273275

274276
/*

src/test/regress/expected/strings.out

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,22 @@ SELECT 'jack' LIKE '%____%' AS t;
11011101
t
11021102
(1 row)
11031103

1104+
--
1105+
-- basic tests of LIKE with indexes
1106+
--
1107+
CREATE TABLE texttest (a text PRIMARY KEY, b int);
1108+
SELECT * FROM texttest WHERE a LIKE '%1%';
1109+
a | b
1110+
---+---
1111+
(0 rows)
1112+
1113+
CREATE TABLE byteatest (a bytea PRIMARY KEY, b int);
1114+
SELECT * FROM byteatest WHERE a LIKE '%1%';
1115+
a | b
1116+
---+---
1117+
(0 rows)
1118+
1119+
DROP TABLE texttest, byteatest;
11041120
--
11051121
-- test implicit type conversion
11061122
--

src/test/regress/sql/strings.sql

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,19 @@ SELECT 'foo' LIKE '%__' as t, 'foo' LIKE '%___' as t, 'foo' LIKE '%____' as f;
323323
SELECT 'jack' LIKE '%____%' AS t;
324324

325325

326+
--
327+
-- basic tests of LIKE with indexes
328+
--
329+
330+
CREATE TABLE texttest (a text PRIMARY KEY, b int);
331+
SELECT * FROM texttest WHERE a LIKE '%1%';
332+
333+
CREATE TABLE byteatest (a bytea PRIMARY KEY, b int);
334+
SELECT * FROM byteatest WHERE a LIKE '%1%';
335+
336+
DROP TABLE texttest, byteatest;
337+
338+
326339
--
327340
-- test implicit type conversion
328341
--

0 commit comments

Comments
 (0)