Skip to content

Commit 7bad8e8

Browse files
Merge pull request #159470 from cockroachdb/blathers/backport-release-25.3.6-rc-159442
release-25.3.6-rc: more routine dependency fixes
2 parents 86392ce + 327d5ea commit 7bad8e8

File tree

24 files changed

+1016
-431
lines changed

24 files changed

+1016
-431
lines changed

pkg/ccl/logictestccl/testdata/logic_test/triggers

Lines changed: 455 additions & 394 deletions
Large diffs are not rendered by default.

pkg/sql/exec_util.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4301,6 +4301,14 @@ func (m *sessionDataMutator) SetOptimizerUseMaxFrequencySelectivity(val bool) {
43014301
m.data.OptimizerUseMaxFrequencySelectivity = val
43024302
}
43034303

4304+
func (m *sessionDataMutator) SetPreventUpdateSetColumnDrop(val bool) {
4305+
m.data.PreventUpdateSetColumnDrop = val
4306+
}
4307+
4308+
func (m *sessionDataMutator) SetUseImprovedRoutineDepsTriggersAndComputedCols(val bool) {
4309+
m.data.UseImprovedRoutineDepsTriggersAndComputedCols = val
4310+
}
4311+
43044312
// Utility functions related to scrubbing sensitive information on SQL Stats.
43054313

43064314
// quantizeCounts ensures that the Count field in the

pkg/sql/logictest/testdata/logic_test/check_constraints

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,3 +494,39 @@ ALTER TABLE t_91697 ADD CHECK (a < 123);
494494

495495
statement error pgcode 23514 pq: failed to satisfy CHECK constraint \(a < 'public.t67100a'::REGCLASS\)
496496
INSERT INTO t_91697 VALUES (321);
497+
498+
# Regression test for #158154. Don't add transitive column dependencies to
499+
# routines that build check constraints.
500+
subtest regression_158154
501+
502+
statement ok
503+
SET use_improved_routine_deps_triggers_and_computed_cols = true;
504+
505+
statement ok
506+
CREATE TABLE t158154 (a INT, b INT, CONSTRAINT foo CHECK (b > 0));
507+
508+
statement ok
509+
CREATE PROCEDURE p158154() LANGUAGE SQL AS $$
510+
INSERT INTO t158154 (a) VALUES (1);
511+
UPDATE t158154 SET a = a + 1;
512+
$$;
513+
514+
statement ok
515+
CALL p158154();
516+
517+
# The procedure does not directly depend on column b, so dropping column b
518+
# should be allowed after dropping the check constraint.
519+
statement ok
520+
ALTER TABLE t158154 DROP CONSTRAINT foo, DROP COLUMN b;
521+
522+
statement ok
523+
CALL p158154();
524+
525+
statement ok
526+
DROP PROCEDURE p158154;
527+
DROP TABLE t158154;
528+
529+
statement ok
530+
RESET use_improved_routine_deps_triggers_and_computed_cols;
531+
532+
subtest end

pkg/sql/logictest/testdata/logic_test/enums

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1979,3 +1979,41 @@ CREATE TABLE public.t (
19791979
rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(),
19801980
CONSTRAINT t_pkey PRIMARY KEY (rowid ASC)
19811981
) WITH (schema_locked = true);
1982+
1983+
# Regression test for #158154. Don't add transitive column dependencies to
1984+
# routines that build check constraints for enum columns.
1985+
subtest regression_158154
1986+
1987+
statement ok
1988+
SET use_improved_routine_deps_triggers_and_computed_cols = true;
1989+
1990+
statement ok
1991+
CREATE TYPE typ158154 AS ENUM ('foo', 'bar');
1992+
1993+
statement ok
1994+
CREATE TABLE t158154 (a INT, b typ158154);
1995+
1996+
statement ok
1997+
CREATE PROCEDURE p158154() LANGUAGE SQL AS $$
1998+
INSERT INTO t158154 (a) VALUES (1);
1999+
UPDATE t158154 SET a = a + 1;
2000+
$$;
2001+
2002+
statement ok
2003+
CALL p158154();
2004+
2005+
statement ok
2006+
ALTER TABLE t158154 DROP COLUMN b;
2007+
2008+
statement ok
2009+
CALL p158154();
2010+
2011+
statement ok
2012+
DROP PROCEDURE p158154;
2013+
DROP TABLE t158154;
2014+
DROP TYPE typ158154;
2015+
2016+
statement ok
2017+
RESET use_improved_routine_deps_triggers_and_computed_cols;
2018+
2019+
subtest end

pkg/sql/logictest/testdata/logic_test/hash_sharded_index

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,3 +1435,43 @@ SELECT crdb_internal_d_shard_16 AS shard, count(*) < 20 FROM decimals GROUP BY 1
14351435
15 false
14361436

14371437
subtest end
1438+
1439+
# Regression test for #158154. Don't add transitive column dependencies to
1440+
# routines that build check constraints.
1441+
subtest regression_158154
1442+
1443+
statement ok
1444+
SET use_improved_routine_deps_triggers_and_computed_cols = true;
1445+
1446+
statement ok
1447+
CREATE TABLE t158154 (col1 INT8 NOT NULL, col2 TIMESTAMP NOT NULL);
1448+
1449+
statement ok
1450+
CREATE INDEX idx1 ON t158154 (col2 ASC) USING HASH WITH (bucket_count = 6);
1451+
1452+
statement ok
1453+
CREATE OR REPLACE PROCEDURE p158154 () LANGUAGE PLpgSQL AS $proc$
1454+
BEGIN
1455+
UPDATE t158154 SET col1 = col1 + 1;
1456+
END;
1457+
$proc$;
1458+
1459+
statement ok
1460+
CALL p158154();
1461+
1462+
# The procedure does not directly depend on the hash-sharded index computed
1463+
# column, so dropping the index should succeed.
1464+
statement ok
1465+
DROP INDEX t158154@idx1;
1466+
1467+
statement ok
1468+
CALL p158154();
1469+
1470+
statement ok
1471+
DROP PROCEDURE p158154;
1472+
DROP TABLE t158154;
1473+
1474+
statement ok
1475+
RESET use_improved_routine_deps_triggers_and_computed_cols;
1476+
1477+
subtest end

pkg/sql/logictest/testdata/logic_test/information_schema

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4092,6 +4092,7 @@ plan_cache_mode auto
40924092
plpgsql_use_strict_into off
40934093
prefer_lookup_joins_for_fks off
40944094
prepared_statements_cache_size 0 B
4095+
prevent_update_set_column_drop off
40954096
propagate_admission_header_to_leaf_transactions on
40964097
propagate_input_ordering off
40974098
recursion_depth_limit 1000
@@ -4142,6 +4143,7 @@ unconstrained_non_covering_index_scan_enabled off
41424143
unsafe_allow_triggers_modifying_cascades off
41434144
use_cputs_on_non_unique_indexes off
41444145
use_improved_routine_dependency_tracking on
4146+
use_improved_routine_deps_triggers_and_computed_cols off
41454147
use_pre_25_2_variadic_builtins off
41464148
use_proc_txn_control_extended_protocol_fix on
41474149
use_soft_limit_for_distribute_scan off

pkg/sql/logictest/testdata/logic_test/partial_index

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2496,3 +2496,103 @@ DROP INDEX idx97551;
24962496
statement ok
24972497
DROP TABLE t97551;
24982498
DROP TYPE enum97551;
2499+
2500+
subtest end
2501+
2502+
# Regression test for #158154. Don't add transitive column dependencies to
2503+
# routines that build partial index predicate expressions.
2504+
subtest regression_158154
2505+
2506+
statement ok
2507+
SET use_improved_routine_deps_triggers_and_computed_cols = true;
2508+
2509+
# Simple case with INSERT and UPDATE into a table with a partial index.
2510+
statement ok
2511+
CREATE TABLE t158154 (a INT, b INT, INDEX b_idx (b) WHERE (b > 0));
2512+
2513+
statement ok
2514+
CREATE PROCEDURE p158154() LANGUAGE SQL AS $$
2515+
INSERT INTO t158154 (a) VALUES (1);
2516+
UPDATE t158154 SET a = a + 1;
2517+
$$;
2518+
2519+
statement ok
2520+
CALL p158154();
2521+
2522+
statement ok
2523+
DROP INDEX t158154@b_idx;
2524+
2525+
statement ok
2526+
ALTER TABLE t158154 DROP COLUMN b;
2527+
2528+
statement ok
2529+
CALL p158154();
2530+
2531+
statement ok
2532+
DROP PROCEDURE p158154;
2533+
DROP TABLE t158154;
2534+
2535+
# Case with a partial index used as an arbiter.
2536+
statement ok
2537+
CREATE TABLE t158154 (a INT, b INT);
2538+
2539+
statement ok
2540+
CREATE UNIQUE INDEX a_idx ON t158154 (a) WHERE (b > 0);
2541+
2542+
# WHERE false implies any partial index predicate.
2543+
statement ok
2544+
CREATE PROCEDURE p158154() LANGUAGE SQL AS $$
2545+
INSERT INTO t158154 (a) VALUES (1) ON CONFLICT (a) WHERE (false) DO NOTHING;
2546+
INSERT INTO t158154 (a) VALUES (2) ON CONFLICT (a) WHERE (false) DO UPDATE SET a = EXCLUDED.a + 1;
2547+
$$;
2548+
2549+
statement ok
2550+
CALL p158154();
2551+
2552+
statement ok
2553+
DROP INDEX t158154@a_idx;
2554+
2555+
statement ok
2556+
ALTER TABLE t158154 DROP COLUMN b;
2557+
2558+
statement ok
2559+
CREATE UNIQUE INDEX a_idx ON t158154 (a);
2560+
2561+
statement ok
2562+
CALL p158154();
2563+
2564+
statement ok
2565+
DROP PROCEDURE p158154;
2566+
DROP TABLE t158154;
2567+
2568+
# Verify that a SELECT statement inside a procedure does not add transitive
2569+
# dependencies from the partial index predicate.
2570+
statement ok
2571+
CREATE TABLE t158154 (a INT, b INT, INDEX b_idx (b) WHERE (b > 0));
2572+
2573+
statement ok
2574+
CREATE PROCEDURE p158154() LANGUAGE SQL AS $$
2575+
SELECT a FROM t158154;
2576+
SELECT count(*) FROM t158154 WHERE a > 5;
2577+
$$;
2578+
2579+
statement ok
2580+
CALL p158154();
2581+
2582+
statement ok
2583+
DROP INDEX t158154@b_idx;
2584+
2585+
statement ok
2586+
ALTER TABLE t158154 DROP COLUMN b;
2587+
2588+
statement ok
2589+
CALL p158154();
2590+
2591+
statement ok
2592+
DROP PROCEDURE p158154;
2593+
DROP TABLE t158154;
2594+
2595+
statement ok
2596+
RESET use_improved_routine_deps_triggers_and_computed_cols;
2597+
2598+
subtest end

pkg/sql/logictest/testdata/logic_test/pg_catalog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3095,6 +3095,7 @@ plan_cache_mode auto
30953095
plpgsql_use_strict_into off NULL NULL NULL string
30963096
prefer_lookup_joins_for_fks off NULL NULL NULL string
30973097
prepared_statements_cache_size 0 B NULL NULL NULL string
3098+
prevent_update_set_column_drop off NULL NULL NULL string
30983099
propagate_admission_header_to_leaf_transactions on NULL NULL NULL string
30993100
propagate_input_ordering off NULL NULL NULL string
31003101
recursion_depth_limit 1000 NULL NULL NULL string
@@ -3147,6 +3148,7 @@ unsafe_allow_triggers_modifying_cascades off
31473148
use_cputs_on_non_unique_indexes off NULL NULL NULL string
31483149
use_declarative_schema_changer on NULL NULL NULL string
31493150
use_improved_routine_dependency_tracking on NULL NULL NULL string
3151+
use_improved_routine_deps_triggers_and_computed_cols off NULL NULL NULL string
31503152
use_pre_25_2_variadic_builtins off NULL NULL NULL string
31513153
use_proc_txn_control_extended_protocol_fix on NULL NULL NULL string
31523154
use_soft_limit_for_distribute_scan off NULL NULL NULL string
@@ -3338,6 +3340,7 @@ plan_cache_mode auto
33383340
plpgsql_use_strict_into off NULL user NULL off off
33393341
prefer_lookup_joins_for_fks off NULL user NULL off off
33403342
prepared_statements_cache_size 0 B B user NULL 0 B 0 B
3343+
prevent_update_set_column_drop off NULL user NULL off off
33413344
propagate_admission_header_to_leaf_transactions on NULL user NULL on on
33423345
propagate_input_ordering off NULL user NULL off off
33433346
recursion_depth_limit 1000 NULL user NULL 1000 1000
@@ -3390,6 +3393,7 @@ unsafe_allow_triggers_modifying_cascades off
33903393
use_cputs_on_non_unique_indexes off NULL user NULL off off
33913394
use_declarative_schema_changer on NULL user NULL on on
33923395
use_improved_routine_dependency_tracking on NULL user NULL on on
3396+
use_improved_routine_deps_triggers_and_computed_cols off NULL user NULL off off
33933397
use_pre_25_2_variadic_builtins off NULL user NULL off off
33943398
use_proc_txn_control_extended_protocol_fix on NULL user NULL on on
33953399
use_soft_limit_for_distribute_scan off NULL user NULL off off
@@ -3572,6 +3576,7 @@ plan_cache_mode NULL NULL
35723576
plpgsql_use_strict_into NULL NULL NULL NULL NULL
35733577
prefer_lookup_joins_for_fks NULL NULL NULL NULL NULL
35743578
prepared_statements_cache_size NULL NULL NULL NULL NULL
3579+
prevent_update_set_column_drop NULL NULL NULL NULL NULL
35753580
propagate_admission_header_to_leaf_transactions NULL NULL NULL NULL NULL
35763581
propagate_input_ordering NULL NULL NULL NULL NULL
35773582
recursion_depth_limit NULL NULL NULL NULL NULL
@@ -3625,6 +3630,7 @@ unsafe_allow_triggers_modifying_cascades NULL NULL
36253630
use_cputs_on_non_unique_indexes NULL NULL NULL NULL NULL
36263631
use_declarative_schema_changer NULL NULL NULL NULL NULL
36273632
use_improved_routine_dependency_tracking NULL NULL NULL NULL NULL
3633+
use_improved_routine_deps_triggers_and_computed_cols NULL NULL NULL NULL NULL
36283634
use_pre_25_2_variadic_builtins NULL NULL NULL NULL NULL
36293635
use_proc_txn_control_extended_protocol_fix NULL NULL NULL NULL NULL
36303636
use_soft_limit_for_distribute_scan NULL NULL NULL NULL NULL

pkg/sql/logictest/testdata/logic_test/row_level_security

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5705,3 +5705,63 @@ statement ok
57055705
DROP ROLE alice;
57065706

57075707
subtest end
5708+
5709+
# Regression test for #158154. Don't add transitive column dependencies to
5710+
# routines that build RLS constraints.
5711+
subtest regression_158154
5712+
5713+
statement ok
5714+
SET use_improved_routine_deps_triggers_and_computed_cols = true;
5715+
5716+
statement ok
5717+
CREATE TABLE t158154 (c0 INT, c1 TEXT DEFAULT 'foobarbaz', FAMILY (c0, c1));
5718+
5719+
statement ok
5720+
CREATE ROLE user_158154
5721+
5722+
statement ok
5723+
GRANT ALL ON t158154 TO user_158154;
5724+
5725+
statement ok
5726+
ALTER TABLE t158154 ENABLE ROW LEVEL SECURITY, FORCE ROW LEVEL SECURITY;
5727+
5728+
statement ok
5729+
ALTER TABLE t158154 OWNER TO user_158154;
5730+
5731+
statement ok
5732+
SET ROLE user_158154;
5733+
5734+
statement ok
5735+
CREATE POLICY IF NOT EXISTS p1 on t158154 WITH CHECK (c0 > 0 AND c1 = 'foobarbaz');
5736+
5737+
statement ok
5738+
CREATE PROCEDURE p158154() LANGUAGE SQL AS $$
5739+
UPDATE t158154 SET c0 = 1 WHERE true;
5740+
$$;
5741+
5742+
statement ok
5743+
CALL p158154();
5744+
5745+
# The procedure does not directly depend on column b, so dropping column b
5746+
# should be allowed after dropping the RLS constraint.
5747+
statement ok
5748+
DROP POLICY p1 on t158154;
5749+
ALTER TABLE t158154 DROP COLUMN c1;
5750+
5751+
statement ok
5752+
CALL p158154();
5753+
5754+
statement ok
5755+
SET ROLE root;
5756+
5757+
statement ok
5758+
DROP PROCEDURE p158154;
5759+
DROP TABLE t158154;
5760+
5761+
statement ok
5762+
DROP ROLE user_158154;
5763+
5764+
statement ok
5765+
RESET use_improved_routine_deps_triggers_and_computed_cols;
5766+
5767+
subtest end

pkg/sql/logictest/testdata/logic_test/show_source

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ plan_cache_mode auto
199199
plpgsql_use_strict_into off
200200
prefer_lookup_joins_for_fks off
201201
prepared_statements_cache_size 0 B
202+
prevent_update_set_column_drop off
202203
propagate_admission_header_to_leaf_transactions on
203204
propagate_input_ordering off
204205
recursion_depth_limit 1000
@@ -251,6 +252,7 @@ unsafe_allow_triggers_modifying_cascades off
251252
use_cputs_on_non_unique_indexes off
252253
use_declarative_schema_changer on
253254
use_improved_routine_dependency_tracking on
255+
use_improved_routine_deps_triggers_and_computed_cols off
254256
use_pre_25_2_variadic_builtins off
255257
use_proc_txn_control_extended_protocol_fix on
256258
use_soft_limit_for_distribute_scan off

0 commit comments

Comments
 (0)