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

Commitfedc97c

Browse files
committed
Remove ruleutils.c's special case for BIT [VARYING] literals.
Up to now, get_const_expr() insisted on prefixing BIT and VARBITliterals with 'B'. That's not really necessary, because we alwaysappend explicit-cast syntax to identify the constant's type.Moreover, it's subtly wrong for VARBIT, because the parser willinterpret B'...' as '...'::"bit"; see make_const() which explicitlyassigns type BITOID for a T_BitString literal. So what had beena simple VARBIT literal is reconstructed as ('...'::"bit")::varbit,which is not the same thing, at least not before constant folding.This results in odd differences after dump/restore, as complainedof by the patch submitter, and it could result in actual failures inpartitioning or inheritance DDL operations (see commit542320c,which repaired similar misbehaviors for some other data types).Fixing it is pretty easy: just remove the special case and let thedefault code path handle these types. We could have kept the specialcase for BIT only, but there seems little point in that.Like the previous patch, I judge that back-patching this into stablebranches wouldn't be a good idea. However, it seems not quite toolate for v11, so let's fix it there.Paul Guo, reviewed by Davy Machado and John Naylor, minor adjustmentsby meDiscussion:https://postgr.es/m/CABQrizdTra=2JEqA6+Ms1D1k1Kqw+aiBBhC9TreuZRX2JzxLAA@mail.gmail.com
1 parent500d497 commitfedc97c

File tree

6 files changed

+41
-11
lines changed

6 files changed

+41
-11
lines changed

‎contrib/btree_gist/expected/bit.out

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ SELECT count(*) FROM bittmp WHERE a > '011011000100010111011000110000100';
6868
SET enable_bitmapscan=off;
6969
EXPLAIN (COSTS OFF)
7070
SELECT a FROM bittmp WHERE a BETWEEN '1000000' and '1000001';
71-
QUERY PLAN
72-
-----------------------------------------------------------------------
71+
QUERY PLAN
72+
---------------------------------------------------------------------
7373
Index Only Scan using bitidx on bittmp
74-
Index Cond: ((a >=B'1000000'::"bit") AND (a <=B'1000001'::"bit"))
74+
Index Cond: ((a >= '1000000'::"bit") AND (a <= '1000001'::"bit"))
7575
(2 rows)
7676

‎contrib/btree_gist/expected/varbit.out

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ SELECT count(*) FROM varbittmp WHERE a > '1110100111010'::varbit;
6868
SET enable_bitmapscan=off;
6969
EXPLAIN (COSTS OFF)
7070
SELECT a FROM bittmp WHERE a BETWEEN '1000000' and '1000001';
71-
QUERY PLAN
72-
-----------------------------------------------------------------------
71+
QUERY PLAN
72+
---------------------------------------------------------------------
7373
Index Only Scan using bitidx on bittmp
74-
Index Cond: ((a >=B'1000000'::"bit") AND (a <=B'1000001'::"bit"))
74+
Index Cond: ((a >= '1000000'::"bit") AND (a <= '1000001'::"bit"))
7575
(2 rows)
7676

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9490,11 +9490,6 @@ get_const_expr(Const *constval, deparse_context *context, int showtype)
94909490
}
94919491
break;
94929492

9493-
caseBITOID:
9494-
caseVARBITOID:
9495-
appendStringInfo(buf,"B'%s'",extval);
9496-
break;
9497-
94989493
caseBOOLOID:
94999494
if (strcmp(extval,"t")==0)
95009495
appendStringInfoString(buf,"true");

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,3 +549,26 @@ SELECT overlay(B'0101011100' placing '001' from 20);
549549
0101011100001
550550
(1 row)
551551

552+
-- This table is intentionally left around to exercise pg_dump/pg_upgrade
553+
CREATE TABLE bit_defaults(
554+
b1 bit(4) DEFAULT '1001',
555+
b2 bit(4) DEFAULT B'0101',
556+
b3 bit varying(5) DEFAULT '1001',
557+
b4 bit varying(5) DEFAULT B'0101'
558+
);
559+
\d bit_defaults
560+
Table "public.bit_defaults"
561+
Column | Type | Collation | Nullable | Default
562+
--------+----------------+-----------+----------+---------------------
563+
b1 | bit(4) | | | '1001'::"bit"
564+
b2 | bit(4) | | | '0101'::"bit"
565+
b3 | bit varying(5) | | | '1001'::bit varying
566+
b4 | bit varying(5) | | | '0101'::"bit"
567+
568+
INSERT INTO bit_defaults DEFAULT VALUES;
569+
TABLE bit_defaults;
570+
b1 | b2 | b3 | b4
571+
------+------+------+------
572+
1001 | 0101 | 1001 | 0101
573+
(1 row)
574+

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ array_index_op_test|t
1919
array_op_test|f
2020
b|f
2121
b_star|f
22+
bit_defaults|f
2223
box_tbl|f
2324
bprime|f
2425
bt_f8_heap|t

‎src/test/regress/sql/bit.sql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,14 @@ SELECT overlay(B'0101011100' placing '001' from 2 for 3);
195195
SELECT overlay(B'0101011100' placing'101'from6);
196196
SELECT overlay(B'0101011100' placing'001'from11);
197197
SELECT overlay(B'0101011100' placing'001'from20);
198+
199+
-- This table is intentionally left around to exercise pg_dump/pg_upgrade
200+
CREATETABLEbit_defaults(
201+
b1bit(4) DEFAULT'1001',
202+
b2bit(4) DEFAULT B'0101',
203+
b3bit varying(5) DEFAULT'1001',
204+
b4bit varying(5) DEFAULT B'0101'
205+
);
206+
\d bit_defaults
207+
INSERT INTO bit_defaults DEFAULTVALUES;
208+
TABLE bit_defaults;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp