Skip to content

Commit 2c80e22

Browse files
Merge pull request #159469 from cockroachdb/blathers/backport-release-25.4.2-rc-159441
release-25.4.2-rc: more routine dependency fixes
2 parents fed2b83 + c5e87b4 commit 2c80e22

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
@@ -4547,6 +4547,14 @@ func (m *sessionDataMutator) SetOptimizerUseMaxFrequencySelectivity(val bool) {
45474547
m.data.OptimizerUseMaxFrequencySelectivity = val
45484548
}
45494549

4550+
func (m *sessionDataMutator) SetPreventUpdateSetColumnDrop(val bool) {
4551+
m.data.PreventUpdateSetColumnDrop = val
4552+
}
4553+
4554+
func (m *sessionDataMutator) SetUseImprovedRoutineDepsTriggersAndComputedCols(val bool) {
4555+
m.data.UseImprovedRoutineDepsTriggersAndComputedCols = val
4556+
}
4557+
45504558
// Utility functions related to scrubbing sensitive information on SQL Stats.
45514559

45524560
// 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
@@ -1987,3 +1987,41 @@ CREATE TABLE public.t (
19871987
rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(),
19881988
CONSTRAINT t_pkey PRIMARY KEY (rowid ASC)
19891989
) WITH (schema_locked = true);
1990+
1991+
# Regression test for #158154. Don't add transitive column dependencies to
1992+
# routines that build check constraints for enum columns.
1993+
subtest regression_158154
1994+
1995+
statement ok
1996+
SET use_improved_routine_deps_triggers_and_computed_cols = true;
1997+
1998+
statement ok
1999+
CREATE TYPE typ158154 AS ENUM ('foo', 'bar');
2000+
2001+
statement ok
2002+
CREATE TABLE t158154 (a INT, b typ158154);
2003+
2004+
statement ok
2005+
CREATE PROCEDURE p158154() LANGUAGE SQL AS $$
2006+
INSERT INTO t158154 (a) VALUES (1);
2007+
UPDATE t158154 SET a = a + 1;
2008+
$$;
2009+
2010+
statement ok
2011+
CALL p158154();
2012+
2013+
statement ok
2014+
ALTER TABLE t158154 DROP COLUMN b;
2015+
2016+
statement ok
2017+
CALL p158154();
2018+
2019+
statement ok
2020+
DROP PROCEDURE p158154;
2021+
DROP TABLE t158154;
2022+
DROP TYPE typ158154;
2023+
2024+
statement ok
2025+
RESET use_improved_routine_deps_triggers_and_computed_cols;
2026+
2027+
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
@@ -4238,6 +4238,7 @@ plan_cache_mode auto
42384238
plpgsql_use_strict_into off
42394239
prefer_lookup_joins_for_fks off
42404240
prepared_statements_cache_size 0 B
4241+
prevent_update_set_column_drop off
42414242
propagate_admission_header_to_leaf_transactions on
42424243
propagate_input_ordering off
42434244
recursion_depth_limit 1000
@@ -4288,6 +4289,7 @@ unconstrained_non_covering_index_scan_enabled off
42884289
unsafe_allow_triggers_modifying_cascades off
42894290
use_cputs_on_non_unique_indexes off
42904291
use_improved_routine_dependency_tracking on
4292+
use_improved_routine_deps_triggers_and_computed_cols off
42914293
use_pre_25_2_variadic_builtins off
42924294
use_proc_txn_control_extended_protocol_fix on
42934295
use_soft_limit_for_distribute_scan on

pkg/sql/logictest/testdata/logic_test/partial_index

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

pkg/sql/logictest/testdata/logic_test/pg_catalog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3140,6 +3140,7 @@ plan_cache_mode auto
31403140
plpgsql_use_strict_into off NULL NULL NULL string
31413141
prefer_lookup_joins_for_fks off NULL NULL NULL string
31423142
prepared_statements_cache_size 0 B NULL NULL NULL string
3143+
prevent_update_set_column_drop off NULL NULL NULL string
31433144
propagate_admission_header_to_leaf_transactions on NULL NULL NULL string
31443145
propagate_input_ordering off NULL NULL NULL string
31453146
recursion_depth_limit 1000 NULL NULL NULL string
@@ -3192,6 +3193,7 @@ unsafe_allow_triggers_modifying_cascades off
31923193
use_cputs_on_non_unique_indexes off NULL NULL NULL string
31933194
use_declarative_schema_changer on NULL NULL NULL string
31943195
use_improved_routine_dependency_tracking on NULL NULL NULL string
3196+
use_improved_routine_deps_triggers_and_computed_cols off NULL NULL NULL string
31953197
use_pre_25_2_variadic_builtins off NULL NULL NULL string
31963198
use_proc_txn_control_extended_protocol_fix on NULL NULL NULL string
31973199
use_soft_limit_for_distribute_scan on NULL NULL NULL string
@@ -3388,6 +3390,7 @@ plan_cache_mode auto
33883390
plpgsql_use_strict_into off NULL user NULL off off
33893391
prefer_lookup_joins_for_fks off NULL user NULL off off
33903392
prepared_statements_cache_size 0 B B user NULL 0 B 0 B
3393+
prevent_update_set_column_drop off NULL user NULL off off
33913394
propagate_admission_header_to_leaf_transactions on NULL user NULL on on
33923395
propagate_input_ordering off NULL user NULL off off
33933396
recursion_depth_limit 1000 NULL user NULL 1000 1000
@@ -3440,6 +3443,7 @@ unsafe_allow_triggers_modifying_cascades off
34403443
use_cputs_on_non_unique_indexes off NULL user NULL off off
34413444
use_declarative_schema_changer on NULL user NULL on on
34423445
use_improved_routine_dependency_tracking on NULL user NULL on on
3446+
use_improved_routine_deps_triggers_and_computed_cols off NULL user NULL off off
34433447
use_pre_25_2_variadic_builtins off NULL user NULL off off
34443448
use_proc_txn_control_extended_protocol_fix on NULL user NULL on on
34453449
use_soft_limit_for_distribute_scan on NULL user NULL on on
@@ -3627,6 +3631,7 @@ plan_cache_mode NULL NULL
36273631
plpgsql_use_strict_into NULL NULL NULL NULL NULL
36283632
prefer_lookup_joins_for_fks NULL NULL NULL NULL NULL
36293633
prepared_statements_cache_size NULL NULL NULL NULL NULL
3634+
prevent_update_set_column_drop NULL NULL NULL NULL NULL
36303635
propagate_admission_header_to_leaf_transactions NULL NULL NULL NULL NULL
36313636
propagate_input_ordering NULL NULL NULL NULL NULL
36323637
recursion_depth_limit NULL NULL NULL NULL NULL
@@ -3680,6 +3685,7 @@ unsafe_allow_triggers_modifying_cascades NULL NULL
36803685
use_cputs_on_non_unique_indexes NULL NULL NULL NULL NULL
36813686
use_declarative_schema_changer NULL NULL NULL NULL NULL
36823687
use_improved_routine_dependency_tracking NULL NULL NULL NULL NULL
3688+
use_improved_routine_deps_triggers_and_computed_cols NULL NULL NULL NULL NULL
36833689
use_pre_25_2_variadic_builtins NULL NULL NULL NULL NULL
36843690
use_proc_txn_control_extended_protocol_fix NULL NULL NULL NULL NULL
36853691
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
@@ -5728,3 +5728,63 @@ statement ok
57285728
SET allow_view_with_security_invoker_clause = off
57295729

57305730
subtest end
5731+
5732+
# Regression test for #158154. Don't add transitive column dependencies to
5733+
# routines that build RLS constraints.
5734+
subtest regression_158154
5735+
5736+
statement ok
5737+
SET use_improved_routine_deps_triggers_and_computed_cols = true;
5738+
5739+
statement ok
5740+
CREATE TABLE t158154 (c0 INT, c1 TEXT DEFAULT 'foobarbaz', FAMILY (c0, c1));
5741+
5742+
statement ok
5743+
CREATE ROLE user_158154
5744+
5745+
statement ok
5746+
GRANT ALL ON t158154 TO user_158154;
5747+
5748+
statement ok
5749+
ALTER TABLE t158154 ENABLE ROW LEVEL SECURITY, FORCE ROW LEVEL SECURITY;
5750+
5751+
statement ok
5752+
ALTER TABLE t158154 OWNER TO user_158154;
5753+
5754+
statement ok
5755+
SET ROLE user_158154;
5756+
5757+
statement ok
5758+
CREATE POLICY IF NOT EXISTS p1 on t158154 WITH CHECK (c0 > 0 AND c1 = 'foobarbaz');
5759+
5760+
statement ok
5761+
CREATE PROCEDURE p158154() LANGUAGE SQL AS $$
5762+
UPDATE t158154 SET c0 = 1 WHERE true;
5763+
$$;
5764+
5765+
statement ok
5766+
CALL p158154();
5767+
5768+
# The procedure does not directly depend on column b, so dropping column b
5769+
# should be allowed after dropping the RLS constraint.
5770+
statement ok
5771+
DROP POLICY p1 on t158154;
5772+
ALTER TABLE t158154 DROP COLUMN c1;
5773+
5774+
statement ok
5775+
CALL p158154();
5776+
5777+
statement ok
5778+
SET ROLE root;
5779+
5780+
statement ok
5781+
DROP PROCEDURE p158154;
5782+
DROP TABLE t158154;
5783+
5784+
statement ok
5785+
DROP ROLE user_158154;
5786+
5787+
statement ok
5788+
RESET use_improved_routine_deps_triggers_and_computed_cols;
5789+
5790+
subtest end

pkg/sql/logictest/testdata/logic_test/show_source

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ plan_cache_mode auto
204204
plpgsql_use_strict_into off
205205
prefer_lookup_joins_for_fks off
206206
prepared_statements_cache_size 0 B
207+
prevent_update_set_column_drop off
207208
propagate_admission_header_to_leaf_transactions on
208209
propagate_input_ordering off
209210
recursion_depth_limit 1000
@@ -256,6 +257,7 @@ unsafe_allow_triggers_modifying_cascades off
256257
use_cputs_on_non_unique_indexes off
257258
use_declarative_schema_changer on
258259
use_improved_routine_dependency_tracking on
260+
use_improved_routine_deps_triggers_and_computed_cols off
259261
use_pre_25_2_variadic_builtins off
260262
use_proc_txn_control_extended_protocol_fix on
261263
use_soft_limit_for_distribute_scan on

0 commit comments

Comments
 (0)