1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-07 00:36:50 +03:00

Add text-vs-name cross-type operators, and unify name_ops with text_ops.

Now that name comparison has effectively the same behavior as text
comparison, we might as well merge the name_ops opfamily into text_ops,
allowing cross-type comparisons to be processed without forcing a
datatype coercion first.  We need do little more than add cross-type
operators to make the opfamily complete, and fix one or two places
in the planner that assumed text_ops was a single-datatype opfamily.

I chose to unify hash name_ops into hash text_ops as well, since the
types have compatible hashing semantics.  This allows marking the
new cross-type equality operators as oprcanhash.

(Note: this doesn't remove the name_ops opclasses, so there's no
breakage of index definitions.  Those opclasses are just reparented
into the text_ops opfamily.)

Discussion: https://postgr.es/m/15938.1544377821@sss.pgh.pa.us
This commit is contained in:
Tom Lane
2018-12-19 17:46:07 -05:00
parent 586b98fdf1
commit 2ece7c07dc
13 changed files with 389 additions and 89 deletions

View File

@ -525,6 +525,20 @@ int24ge(smallint,integer)
int42ge(integer,smallint)
oideq(oid,oid)
oidne(oid,oid)
nameeqtext(name,text)
namelttext(name,text)
nameletext(name,text)
namegetext(name,text)
namegttext(name,text)
namenetext(name,text)
btnametextcmp(name,text)
texteqname(text,name)
textltname(text,name)
textlename(text,name)
textgename(text,name)
textgtname(text,name)
textnename(text,name)
bttextnamecmp(text,name)
float4eq(real,real)
float4ne(real,real)
float4lt(real,real)

View File

@ -299,7 +299,7 @@ explain (costs off) select * from pg_proc where proname ~ '^abc';
QUERY PLAN
----------------------------------------------------------------------
Index Scan using pg_proc_proname_args_nsp_index on pg_proc
Index Cond: ((proname >= 'abc'::name) AND (proname < 'abd'::name))
Index Cond: ((proname >= 'abc'::text) AND (proname < 'abd'::text))
Filter: (proname ~ '^abc'::text)
(3 rows)
@ -307,7 +307,7 @@ explain (costs off) select * from pg_proc where proname ~ '^abc$';
QUERY PLAN
------------------------------------------------------------
Index Scan using pg_proc_proname_args_nsp_index on pg_proc
Index Cond: (proname = 'abc'::name)
Index Cond: (proname = 'abc'::text)
Filter: (proname ~ '^abc$'::text)
(3 rows)
@ -315,7 +315,7 @@ explain (costs off) select * from pg_proc where proname ~ '^abcd*e';
QUERY PLAN
----------------------------------------------------------------------
Index Scan using pg_proc_proname_args_nsp_index on pg_proc
Index Cond: ((proname >= 'abc'::name) AND (proname < 'abd'::name))
Index Cond: ((proname >= 'abc'::text) AND (proname < 'abd'::text))
Filter: (proname ~ '^abcd*e'::text)
(3 rows)
@ -323,7 +323,7 @@ explain (costs off) select * from pg_proc where proname ~ '^abc+d';
QUERY PLAN
----------------------------------------------------------------------
Index Scan using pg_proc_proname_args_nsp_index on pg_proc
Index Cond: ((proname >= 'abc'::name) AND (proname < 'abd'::name))
Index Cond: ((proname >= 'abc'::text) AND (proname < 'abd'::text))
Filter: (proname ~ '^abc+d'::text)
(3 rows)
@ -331,7 +331,7 @@ explain (costs off) select * from pg_proc where proname ~ '^(abc)(def)';
QUERY PLAN
----------------------------------------------------------------------------
Index Scan using pg_proc_proname_args_nsp_index on pg_proc
Index Cond: ((proname >= 'abcdef'::name) AND (proname < 'abcdeg'::name))
Index Cond: ((proname >= 'abcdef'::text) AND (proname < 'abcdeg'::text))
Filter: (proname ~ '^(abc)(def)'::text)
(3 rows)
@ -339,7 +339,7 @@ explain (costs off) select * from pg_proc where proname ~ '^(abc)$';
QUERY PLAN
------------------------------------------------------------
Index Scan using pg_proc_proname_args_nsp_index on pg_proc
Index Cond: (proname = 'abc'::name)
Index Cond: (proname = 'abc'::text)
Filter: (proname ~ '^(abc)$'::text)
(3 rows)
@ -354,7 +354,7 @@ explain (costs off) select * from pg_proc where proname ~ '^abcd(x|(?=\w\w)q)';
QUERY PLAN
------------------------------------------------------------------------
Index Scan using pg_proc_proname_args_nsp_index on pg_proc
Index Cond: ((proname >= 'abcd'::name) AND (proname < 'abce'::name))
Index Cond: ((proname >= 'abcd'::text) AND (proname < 'abce'::text))
Filter: (proname ~ '^abcd(x|(?=\w\w)q)'::text)
(3 rows)

View File

@ -1326,10 +1326,10 @@ NOTICE: f_leak => hamburger
(1 row)
EXPLAIN (COSTS OFF) SELECT * FROM my_property_normal WHERE f_leak(passwd);
QUERY PLAN
--------------------------------------------------------------
QUERY PLAN
------------------------------------------------------
Seq Scan on customer
Filter: (f_leak(passwd) AND (name = (CURRENT_USER)::text))
Filter: (f_leak(passwd) AND (name = CURRENT_USER))
(2 rows)
SELECT * FROM my_property_secure WHERE f_leak(passwd);
@ -1340,12 +1340,12 @@ NOTICE: f_leak => passwd123
(1 row)
EXPLAIN (COSTS OFF) SELECT * FROM my_property_secure WHERE f_leak(passwd);
QUERY PLAN
-----------------------------------------------
QUERY PLAN
---------------------------------------------
Subquery Scan on my_property_secure
Filter: f_leak(my_property_secure.passwd)
-> Seq Scan on customer
Filter: (name = (CURRENT_USER)::text)
Filter: (name = CURRENT_USER)
(4 rows)
--
@ -1367,10 +1367,10 @@ NOTICE: f_leak => hamburger
EXPLAIN (COSTS OFF) SELECT * FROM my_property_normal v
WHERE f_leak('passwd') AND f_leak(passwd);
QUERY PLAN
-----------------------------------------------------------------------------------------
QUERY PLAN
---------------------------------------------------------------------------------
Seq Scan on customer
Filter: (f_leak('passwd'::text) AND f_leak(passwd) AND (name = (CURRENT_USER)::text))
Filter: (f_leak('passwd'::text) AND f_leak(passwd) AND (name = CURRENT_USER))
(2 rows)
SELECT * FROM my_property_secure v
@ -1386,12 +1386,12 @@ NOTICE: f_leak => passwd
EXPLAIN (COSTS OFF) SELECT * FROM my_property_secure v
WHERE f_leak('passwd') AND f_leak(passwd);
QUERY PLAN
----------------------------------------------------------------------------
QUERY PLAN
--------------------------------------------------------------------
Subquery Scan on v
Filter: f_leak(v.passwd)
-> Seq Scan on customer
Filter: (f_leak('passwd'::text) AND (name = (CURRENT_USER)::text))
Filter: (f_leak('passwd'::text) AND (name = CURRENT_USER))
(4 rows)
--
@ -1409,15 +1409,15 @@ NOTICE: f_leak => 9801-2345-6789-0123
(1 row)
EXPLAIN (COSTS OFF) SELECT * FROM my_credit_card_normal WHERE f_leak(cnum);
QUERY PLAN
-----------------------------------------------------
QUERY PLAN
---------------------------------------------
Hash Join
Hash Cond: (r.cid = l.cid)
-> Seq Scan on credit_card r
Filter: f_leak(cnum)
-> Hash
-> Seq Scan on customer l
Filter: (name = (CURRENT_USER)::text)
Filter: (name = CURRENT_USER)
(7 rows)
SELECT * FROM my_credit_card_secure WHERE f_leak(cnum);
@ -1428,8 +1428,8 @@ NOTICE: f_leak => 1111-2222-3333-4444
(1 row)
EXPLAIN (COSTS OFF) SELECT * FROM my_credit_card_secure WHERE f_leak(cnum);
QUERY PLAN
-----------------------------------------------------------
QUERY PLAN
---------------------------------------------------
Subquery Scan on my_credit_card_secure
Filter: f_leak(my_credit_card_secure.cnum)
-> Hash Join
@ -1437,7 +1437,7 @@ EXPLAIN (COSTS OFF) SELECT * FROM my_credit_card_secure WHERE f_leak(cnum);
-> Seq Scan on credit_card r
-> Hash
-> Seq Scan on customer l
Filter: (name = (CURRENT_USER)::text)
Filter: (name = CURRENT_USER)
(8 rows)
--
@ -1471,7 +1471,7 @@ EXPLAIN (COSTS OFF) SELECT * FROM my_credit_card_usage_normal
-> Seq Scan on credit_card r_1
-> Hash
-> Seq Scan on customer l_1
Filter: (name = (CURRENT_USER)::text)
Filter: (name = CURRENT_USER)
(13 rows)
SELECT * FROM my_credit_card_usage_secure
@ -1502,7 +1502,7 @@ EXPLAIN (COSTS OFF) SELECT * FROM my_credit_card_usage_secure
-> Seq Scan on credit_card r_1
-> Hash
-> Seq Scan on customer l
Filter: (name = (CURRENT_USER)::text)
Filter: (name = CURRENT_USER)
(13 rows)
--