Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: use a simpler method for clamping OID hash #103547

Merged
merged 1 commit into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions pkg/ccl/logictestccl/testdata/logic_test/partitioning_implicit
Original file line number Diff line number Diff line change
Expand Up @@ -356,12 +356,12 @@ WHERE indrelid = (SELECT oid FROM pg_class WHERE relname = 't')
ORDER BY 1,2,3
----
indexrelid indrelid indkey indclass indoption indcollation
3428248192 107 5 0 2 0
3428248194 107 2 3 4 0 0 0 2 2 2 0 0 0
3428248195 107 6 0 2 0
3428248196 107 3 0 2 0
3428248197 107 4 0 2 0
3428248199 107 1 0 2 0
3428148192 107 5 0 2 0
3428148194 107 2 3 4 0 0 0 2 2 2 0 0 0
3428148195 107 6 0 2 0
3428148196 107 3 0 2 0
3428148197 107 4 0 2 0
3428148199 107 1 0 2 0

query TTB colnames
SELECT index_name, column_name, implicit FROM crdb_internal.index_columns
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/logictest/testdata/logic_test/alter_role_set
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ ORDER BY 1, 2
----
setdatabase setrole datname rolname setconfig
0 0 NULL NULL {application_name=d}
0 265480634 NULL test_set_role {application_name=a,custom_option.setting=e}
0 265380634 NULL test_set_role {application_name=a,custom_option.setting=e}
106 0 test_set_db NULL {application_name=c}
106 265480634 test_set_db test_set_role {application_name=b}
106 265380634 test_set_db test_set_role {application_name=b}

statement ok
ALTER ROLE test_set_role SET backslash_quote = 'safe_encoding'
Expand Down
1,478 changes: 739 additions & 739 deletions pkg/sql/logictest/testdata/logic_test/pg_catalog

Large diffs are not rendered by default.

382 changes: 191 additions & 191 deletions pkg/sql/logictest/testdata/logic_test/pg_catalog_pg_default_acl

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ query OOOTT colnames,rowsort
SELECT * FROM PG_CATALOG.PG_DEFAULT_ACL
----
oid defaclrole defaclnamespace defaclobjtype defaclacl
1451475629 1546606610 0 r {=r/}
1451475629 1546606610 0 S {=r/}
1451475629 1546606610 0 n {=U/}
1451375629 1546506610 0 r {=r/}
1451375629 1546506610 0 S {=r/}
1451375629 1546506610 0 n {=U/}

statement ok
CREATE USER foo
Expand All @@ -38,11 +38,11 @@ query OOOTT colnames,rowsort
SELECT * FROM PG_CATALOG.PG_DEFAULT_ACL
----
oid defaclrole defaclnamespace defaclobjtype defaclacl
1451475629 1546606610 0 r {bar=C*a*d*r*w*/,foo=C*a*d*r*w*/,=r/}
1451475629 1546606610 0 S {bar=C*U*a*d*r*w*/,foo=C*U*a*d*r*w*/,=r/}
1451475629 1546606610 0 T {bar=U*/,foo=U*/}
1451475629 1546606610 0 n {bar=C*U*/,foo=C*U*/,=U/}
1451475629 1546606610 0 f {bar=X*/,foo=X*/}
1451375629 1546506610 0 r {bar=C*a*d*r*w*/,foo=C*a*d*r*w*/,=r/}
1451375629 1546506610 0 S {bar=C*U*a*d*r*w*/,foo=C*U*a*d*r*w*/,=r/}
1451375629 1546506610 0 T {bar=U*/,foo=U*/}
1451375629 1546506610 0 n {bar=C*U*/,foo=C*U*/,=U/}
1451375629 1546506610 0 f {bar=X*/,foo=X*/}

statement ok
ALTER DEFAULT PRIVILEGES REVOKE GRANT OPTION FOR SELECT, DELETE ON TABLES FROM foo, bar;
Expand All @@ -55,11 +55,11 @@ query OOOTT colnames,rowsort
SELECT * FROM PG_CATALOG.PG_DEFAULT_ACL
----
oid defaclrole defaclnamespace defaclobjtype defaclacl
1451475629 1546606610 0 r {bar=C*a*drw*/,foo=C*a*drw*/,=r/}
1451475629 1546606610 0 S {bar=CU*a*d*r*w/,foo=CU*a*d*r*w/,=r/}
1451475629 1546606610 0 T {bar=U/,foo=U/}
1451475629 1546606610 0 n {bar=CU*/,foo=CU*/,=U/}
1451475629 1546606610 0 f {bar=X/,foo=X/}
1451375629 1546506610 0 r {bar=C*a*drw*/,foo=C*a*drw*/,=r/}
1451375629 1546506610 0 S {bar=CU*a*d*r*w/,foo=CU*a*d*r*w/,=r/}
1451375629 1546506610 0 T {bar=U/,foo=U/}
1451375629 1546506610 0 n {bar=CU*/,foo=CU*/,=U/}
1451375629 1546506610 0 f {bar=X/,foo=X/}

statement ok
ALTER DEFAULT PRIVILEGES REVOKE GRANT OPTION FOR ALL ON TABLES FROM foo, bar;
Expand All @@ -72,11 +72,11 @@ query OOOTT colnames,rowsort
SELECT * FROM PG_CATALOG.PG_DEFAULT_ACL
----
oid defaclrole defaclnamespace defaclobjtype defaclacl
1451475629 1546606610 0 r {bar=Cadrw/,foo=Cadrw/,=r/}
1451475629 1546606610 0 S {bar=CUadrw/,foo=CUadrw/,=r/}
1451475629 1546606610 0 T {bar=U/,foo=U/}
1451475629 1546606610 0 n {bar=CU/,foo=CU/,=U/}
1451475629 1546606610 0 f {bar=X/,foo=X/}
1451375629 1546506610 0 r {bar=Cadrw/,foo=Cadrw/,=r/}
1451375629 1546506610 0 S {bar=CUadrw/,foo=CUadrw/,=r/}
1451375629 1546506610 0 T {bar=U/,foo=U/}
1451375629 1546506610 0 n {bar=CU/,foo=CU/,=U/}
1451375629 1546506610 0 f {bar=X/,foo=X/}

statement ok
GRANT foo, bar TO root;
Expand All @@ -93,21 +93,21 @@ query OOOTT colnames,rowsort
SELECT * FROM PG_CATALOG.PG_DEFAULT_ACL
----
oid defaclrole defaclnamespace defaclobjtype defaclacl
97489596 1791317281 0 r {bar=C*a*d*r*w*/,foo=C*a*d*r*w*/}
97489596 1791317281 0 S {bar=C*U*a*d*r*w*/,foo=C*U*a*d*r*w*/}
97489596 1791317281 0 T {bar=U*/,foo=U*/,=U/}
97489596 1791317281 0 n {bar=C*U*/,foo=C*U*/}
97489596 1791317281 0 f {bar=X*/,foo=X*/}
3755598903 2026895574 0 r {bar=C*a*d*r*w*/,foo=C*a*d*r*w*/}
3755598903 2026895574 0 S {bar=C*U*a*d*r*w*/,foo=C*U*a*d*r*w*/}
3755598903 2026895574 0 T {bar=U*/,foo=U*/,=U/}
3755598903 2026895574 0 n {bar=C*U*/,foo=C*U*/}
3755598903 2026895574 0 f {bar=X*/,foo=X*/}
1451475629 1546606610 0 r {bar=Cadrw/,foo=Cadrw/,=r/}
1451475629 1546606610 0 S {bar=CUadrw/,foo=CUadrw/,=r/}
1451475629 1546606610 0 T {bar=U/,foo=U/}
1451475629 1546606610 0 n {bar=CU/,foo=CU/,=U/}
1451475629 1546606610 0 f {bar=X/,foo=X/}
97389596 1791217281 0 r {bar=C*a*d*r*w*/,foo=C*a*d*r*w*/}
97389596 1791217281 0 S {bar=C*U*a*d*r*w*/,foo=C*U*a*d*r*w*/}
97389596 1791217281 0 T {bar=U*/,foo=U*/,=U/}
97389596 1791217281 0 n {bar=C*U*/,foo=C*U*/}
97389596 1791217281 0 f {bar=X*/,foo=X*/}
3755498903 2026795574 0 r {bar=C*a*d*r*w*/,foo=C*a*d*r*w*/}
3755498903 2026795574 0 S {bar=C*U*a*d*r*w*/,foo=C*U*a*d*r*w*/}
3755498903 2026795574 0 T {bar=U*/,foo=U*/,=U/}
3755498903 2026795574 0 n {bar=C*U*/,foo=C*U*/}
3755498903 2026795574 0 f {bar=X*/,foo=X*/}
1451375629 1546506610 0 r {bar=Cadrw/,foo=Cadrw/,=r/}
1451375629 1546506610 0 S {bar=CUadrw/,foo=CUadrw/,=r/}
1451375629 1546506610 0 T {bar=U/,foo=U/}
1451375629 1546506610 0 n {bar=CU/,foo=CU/,=U/}
1451375629 1546506610 0 f {bar=X/,foo=X/}

statement ok
ALTER DEFAULT PRIVILEGES FOR ROLE foo, bar REVOKE ALL ON TABLES FROM foo, bar;
Expand All @@ -122,21 +122,21 @@ query OOOTT colnames,rowsort
SELECT * FROM PG_CATALOG.PG_DEFAULT_ACL
----
oid defaclrole defaclnamespace defaclobjtype defaclacl
97489596 1791317281 0 r {}
97489596 1791317281 0 S {}
97489596 1791317281 0 T {=U/}
97489596 1791317281 0 n {}
97489596 1791317281 0 f {}
3755598903 2026895574 0 r {}
3755598903 2026895574 0 S {}
3755598903 2026895574 0 T {=U/}
3755598903 2026895574 0 n {}
3755598903 2026895574 0 f {}
1451475629 1546606610 0 r {bar=Cadrw/,foo=Cadrw/,=r/}
1451475629 1546606610 0 S {bar=CUadrw/,foo=CUadrw/,=r/}
1451475629 1546606610 0 T {bar=U/,foo=U/}
1451475629 1546606610 0 n {bar=CU/,foo=CU/,=U/}
1451475629 1546606610 0 f {bar=X/,foo=X/}
97389596 1791217281 0 r {}
97389596 1791217281 0 S {}
97389596 1791217281 0 T {=U/}
97389596 1791217281 0 n {}
97389596 1791217281 0 f {}
3755498903 2026795574 0 r {}
3755498903 2026795574 0 S {}
3755498903 2026795574 0 T {=U/}
3755498903 2026795574 0 n {}
3755498903 2026795574 0 f {}
1451375629 1546506610 0 r {bar=Cadrw/,foo=Cadrw/,=r/}
1451375629 1546506610 0 S {bar=CUadrw/,foo=CUadrw/,=r/}
1451375629 1546506610 0 T {bar=U/,foo=U/}
1451375629 1546506610 0 n {bar=CU/,foo=CU/,=U/}
1451375629 1546506610 0 f {bar=X/,foo=X/}

statement ok
ALTER DEFAULT PRIVILEGES FOR ROLE foo GRANT ALL ON TABLES TO foo;
Expand Down Expand Up @@ -169,11 +169,11 @@ query OOOTT colnames,rowsort
SELECT * FROM PG_CATALOG.PG_DEFAULT_ACL
----
oid defaclrole defaclnamespace defaclobjtype defaclacl
1451475629 1546606610 0 r {bar=Cadrw/,foo=Cadrw/,=r/}
1451475629 1546606610 0 S {bar=CUadrw/,foo=CUadrw/,=r/}
1451475629 1546606610 0 T {bar=U/,foo=U/}
1451475629 1546606610 0 n {bar=CU/,foo=CU/,=U/}
1451475629 1546606610 0 f {bar=X/,foo=X/}
1451375629 1546506610 0 r {bar=Cadrw/,foo=Cadrw/,=r/}
1451375629 1546506610 0 S {bar=CUadrw/,foo=CUadrw/,=r/}
1451375629 1546506610 0 T {bar=U/,foo=U/}
1451375629 1546506610 0 n {bar=CU/,foo=CU/,=U/}
1451375629 1546506610 0 f {bar=X/,foo=X/}

statement ok
ALTER DEFAULT PRIVILEGES FOR ROLE foo GRANT USAGE ON TYPES TO foo WITH GRANT OPTION
Expand All @@ -183,12 +183,12 @@ query OOOTT colnames,rowsort
SELECT * FROM PG_CATALOG.PG_DEFAULT_ACL
----
oid defaclrole defaclnamespace defaclobjtype defaclacl
3755598903 2026895574 0 T {foo=U*/,=U/}
1451475629 1546606610 0 r {bar=Cadrw/,foo=Cadrw/,=r/}
1451475629 1546606610 0 S {bar=CUadrw/,foo=CUadrw/,=r/}
1451475629 1546606610 0 T {bar=U/,foo=U/}
1451475629 1546606610 0 n {bar=CU/,foo=CU/,=U/}
1451475629 1546606610 0 f {bar=X/,foo=X/}
3755498903 2026795574 0 T {foo=U*/,=U/}
1451375629 1546506610 0 r {bar=Cadrw/,foo=Cadrw/,=r/}
1451375629 1546506610 0 S {bar=CUadrw/,foo=CUadrw/,=r/}
1451375629 1546506610 0 T {bar=U/,foo=U/}
1451375629 1546506610 0 n {bar=CU/,foo=CU/,=U/}
1451375629 1546506610 0 f {bar=X/,foo=X/}

statement ok
ALTER DEFAULT PRIVILEGES FOR ROLE foo REVOKE GRANT OPTION FOR USAGE ON TYPES FROM foo
Expand All @@ -198,8 +198,8 @@ query OOOTT colnames,rowsort
SELECT * FROM PG_CATALOG.PG_DEFAULT_ACL
----
oid defaclrole defaclnamespace defaclobjtype defaclacl
1451475629 1546606610 0 r {bar=Cadrw/,foo=Cadrw/,=r/}
1451475629 1546606610 0 S {bar=CUadrw/,foo=CUadrw/,=r/}
1451475629 1546606610 0 T {bar=U/,foo=U/}
1451475629 1546606610 0 n {bar=CU/,foo=CU/,=U/}
1451475629 1546606610 0 f {bar=X/,foo=X/}
1451375629 1546506610 0 r {bar=Cadrw/,foo=Cadrw/,=r/}
1451375629 1546506610 0 S {bar=CUadrw/,foo=CUadrw/,=r/}
1451375629 1546506610 0 T {bar=U/,foo=U/}
1451375629 1546506610 0 n {bar=CU/,foo=CU/,=U/}
1451375629 1546506610 0 f {bar=X/,foo=X/}
2 changes: 1 addition & 1 deletion pkg/sql/logictest/testdata/logic_test/pgoidtype
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public 105
query OO
SELECT 'root'::REGROLE, 'root'::REGROLE::OID
----
root 1546606610
root 1546506610

query OO
SELECT 'bool'::REGTYPE, 'bool'::REGTYPE::OID
Expand Down
32 changes: 16 additions & 16 deletions pkg/sql/logictest/testdata/logic_test/reassign_owned_by
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ ALTER DATABASE d OWNER TO testuser
query TT
SELECT datname, datdba FROM pg_database WHERE datname='d'
----
d 2265019399
d 2264919399

# Switch to database d so it can reassign from current db
statement ok
Expand All @@ -96,7 +96,7 @@ REASSIGN OWNED BY testuser TO testuser2
query TT
SELECT datname, datdba FROM pg_database WHERE datname='d'
----
d 3957604279
d 3957504279

user testuser2

Expand Down Expand Up @@ -132,8 +132,8 @@ CREATE SCHEMA s2
query TT
SELECT nspname, nspowner FROM pg_namespace WHERE nspname='s1' OR nspname='s2'
----
s1 2265019399
s2 1546606610
s1 2264919399
s2 1546506610

# root / superusers can always perform REASSIGN OWNED BY.
user root
Expand All @@ -147,8 +147,8 @@ user testuser2
query TT
SELECT nspname, nspowner FROM pg_namespace WHERE nspname='s1' OR nspname='s2'
----
s1 3957604279
s2 3957604279
s1 3957504279
s2 3957504279

# Ensure testuser2 is new owner by dropping.
statement ok
Expand Down Expand Up @@ -196,7 +196,7 @@ ALTER TYPE s.typ OWNER to testuser
query TT
SELECT nspname, nspowner FROM pg_namespace WHERE nspname='s'
----
s 2265019399
s 2264919399

query TT
SELECT tablename, tableowner FROM pg_tables WHERE tablename='t'
Expand All @@ -206,8 +206,8 @@ t testuser
query TT
SELECT typname, typowner FROM pg_type WHERE typname='_typ' OR typname='typ'
----
typ 2265019399
_typ 2265019399
typ 2264919399
_typ 2264919399

statement ok
REASSIGN OWNED BY testuser TO testuser2
Expand All @@ -216,7 +216,7 @@ REASSIGN OWNED BY testuser TO testuser2
query TT
SELECT nspname, nspowner FROM pg_namespace WHERE nspname='s'
----
s 3957604279
s 3957504279

query TT
SELECT tablename, tableowner FROM pg_tables WHERE tablename='t'
Expand All @@ -226,8 +226,8 @@ t testuser2
query TT
SELECT typname, typowner FROM pg_type WHERE typname='_typ' OR typname='typ'
----
typ 3957604279
_typ 3957604279
typ 3957504279
_typ 3957504279

# Ensure testuser2 is owner by dropping as member of testuser2.
user testuser2
Expand Down Expand Up @@ -272,8 +272,8 @@ ALTER TABLE d.t2 OWNER TO testuser
query TT
SELECT datname, datdba FROM pg_database WHERE datname='d' OR datname='test'
----
d 2265019399
test 1546606610
d 2264919399
test 1546506610

query TT
SELECT tablename, tableowner FROM pg_tables WHERE tablename='t1'
Expand Down Expand Up @@ -303,8 +303,8 @@ REASSIGN OWNED BY testuser TO testuser2
query TT
SELECT datname, datdba FROM pg_database WHERE datname='d' OR datname='test'
----
d 2265019399
test 1546606610
d 2264919399
test 1546506610

query TT
SELECT tablename, tableowner FROM pg_tables WHERE tablename='t1'
Expand Down
14 changes: 7 additions & 7 deletions pkg/sql/logictest/testdata/logic_test/udf
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ query TTTTTBBBTITTTTTT
SELECT oid, proname, pronamespace, proowner, prolang, proleakproof, proisstrict, proretset, provolatile, pronargs, prorettype, proargtypes, proargmodes, proargnames, prokind, prosrc
FROM pg_catalog.pg_proc WHERE proname IN ('proc_f', 'proc_f_2');
----
100118 proc_f 105 1546606610 14 false false false v 1 20 20 {i} NULL f SELECT 1;
100119 proc_f 105 1546606610 14 true true false i 2 25 25 20 {i,i} {"",b} f SELECT 'hello';
100121 proc_f_2 120 1546606610 14 false false false v 1 25 25 {i} NULL f SELECT 'hello';
100118 proc_f 105 1546506610 14 false false false v 1 20 20 {i} NULL f SELECT 1;
100119 proc_f 105 1546506610 14 true true false i 2 25 25 20 {i,i} {"",b} f SELECT 'hello';
100121 proc_f_2 120 1546506610 14 false false false v 1 25 25 {i} NULL f SELECT 'hello';

# Ensure that the pg_proc virtual index works properly.

Expand Down Expand Up @@ -3088,10 +3088,10 @@ SELECT oid, proname, pronamespace, proowner, prolang, proleakproof, proisstrict,
FROM pg_catalog.pg_proc WHERE proname IN ('f_93314', 'f_93314_alias', 'f_93314_comp', 'f_93314_comp_t')
ORDER BY oid;
----
100272 f_93314 105 1546606610 14 false false false v 0 100271 · {} NULL SELECT i, e FROM test.public.t_93314 ORDER BY i LIMIT 1;
100274 f_93314_alias 105 1546606610 14 false false false v 0 100273 · {} NULL SELECT i, e FROM test.public.t_93314_alias ORDER BY i LIMIT 1;
100278 f_93314_comp 105 1546606610 14 false false false v 0 100275 · {} NULL SELECT (1, 2);
100279 f_93314_comp_t 105 1546606610 14 false false false v 0 100277 · {} NULL SELECT a, c FROM test.public.t_93314_comp LIMIT 1;
100272 f_93314 105 1546506610 14 false false false v 0 100271 · {} NULL SELECT i, e FROM test.public.t_93314 ORDER BY i LIMIT 1;
100274 f_93314_alias 105 1546506610 14 false false false v 0 100273 · {} NULL SELECT i, e FROM test.public.t_93314_alias ORDER BY i LIMIT 1;
100278 f_93314_comp 105 1546506610 14 false false false v 0 100275 · {} NULL SELECT (1, 2);
100279 f_93314_comp_t 105 1546506610 14 false false false v 0 100277 · {} NULL SELECT a, c FROM test.public.t_93314_comp LIMIT 1;

# Regression test for #95240. Strict UDFs that are inlined should result in NULL
# when presented with NULL arguments.
Expand Down
9 changes: 4 additions & 5 deletions pkg/sql/pg_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"fmt"
"hash"
"hash/fnv"
"math"
"strings"
"time"
"unicode"
Expand Down Expand Up @@ -4747,10 +4746,10 @@ func (h oidHasher) writeTypeTag(tag oidTypeTag) {

func (h oidHasher) getOid() *tree.DOid {
i := h.h.Sum32()
// Ensure generated OID hashes are above the pre-defined max limit,
// this gives us a cheap filter.
i = i%(math.MaxUint32-oidext.CockroachPredefinedOIDMax) +
oidext.CockroachPredefinedOIDMax
// Ensure generated OID hashes are above the pre-defined max limit.
if i <= oidext.CockroachPredefinedOIDMax {
i += oidext.CockroachPredefinedOIDMax
}
h.h.Reset()
return tree.NewDOid(oid.Oid(i))
}
Expand Down