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

Commitabb9c63

Browse files
committed
Unbreak index optimization for LIKE on bytea
The same code is used to handle both text and bytea, but bytea is notcollation-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 parentc34677f commitabb9c63

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
returnNIL;
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+
CREATETABLEtexttest (atextPRIMARY KEY, bint);
331+
SELECT*FROM texttestWHERE aLIKE'%1%';
332+
333+
CREATETABLEbyteatest (abyteaPRIMARY KEY, bint);
334+
SELECT*FROM byteatestWHERE aLIKE'%1%';
335+
336+
DROPTABLE texttest, byteatest;
337+
338+
326339
--
327340
-- test implicit type conversion
328341
--

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp