@@ -297,12 +297,20 @@ CREATE TABLE t_computed (
297
297
INDEX i (a ASC) USING HASH
298
298
)
299
299
300
+ # An insert routine created with use_improved_routine_dependency_tracking = true
301
+ # should not depend on columns other than the target column "a".
302
+ statement ok
303
+ SET use_improved_routine_dependency_tracking = true;
304
+
300
305
statement ok
301
306
CREATE FUNCTION f145098() RETURNS INT LANGUAGE SQL AS $$
302
307
INSERT INTO t_computed VALUES (100);
303
308
SELECT 1;
304
309
$$;
305
310
311
+ statement ok
312
+ RESET use_improved_routine_dependency_tracking;
313
+
306
314
statement ok
307
315
SELECT f145098();
308
316
@@ -361,6 +369,43 @@ DROP FUNCTION f145098;
361
369
statement ok
362
370
DROP TABLE t_computed;
363
371
372
+ statement ok
373
+ CREATE TABLE t_computed (
374
+ a INT NOT NULL,
375
+ b INT AS (a + 1) STORED,
376
+ c INT AS (a * 2) VIRTUAL,
377
+ INDEX i (a ASC) USING HASH
378
+ )
379
+
380
+ # With use_improved_routine_dependency_tracking = false, the insert routine
381
+ # will depend on all columns in the table.
382
+ statement ok
383
+ SET use_improved_routine_dependency_tracking = false;
384
+
385
+ statement ok
386
+ CREATE FUNCTION f145098() RETURNS INT LANGUAGE SQL AS $$
387
+ INSERT INTO t_computed VALUES (100);
388
+ SELECT 1;
389
+ $$;
390
+
391
+ statement ok
392
+ RESET use_improved_routine_dependency_tracking;
393
+
394
+ statement error pgcode 2BP01 pq: cannot drop column "crdb_internal_a_shard_16" because function "f145098" depends on it
395
+ DROP INDEX i;
396
+
397
+ statement error pgcode 2BP01 pq: cannot drop column "c" because function "f145098" depends on it
398
+ ALTER TABLE t_computed DROP COLUMN c;
399
+
400
+ statement error pgcode 2BP01 pq: cannot drop column "b" because function "f145098" depends on it
401
+ ALTER TABLE t_computed DROP COLUMN b;
402
+
403
+ statement ok
404
+ DROP FUNCTION f145098;
405
+
406
+ statement ok
407
+ DROP TABLE t_computed;
408
+
364
409
# Case where the INSERT statement has a RETURNING clause that references the
365
410
# hash-sharded index column. In this case, a dependency *should* be added.
366
411
statement ok
@@ -369,12 +414,18 @@ CREATE TABLE t_hash_sharded (
369
414
INDEX i (a ASC) USING HASH
370
415
)
371
416
417
+ statement ok
418
+ SET use_improved_routine_dependency_tracking = true;
419
+
372
420
statement ok
373
421
CREATE FUNCTION f145098() RETURNS INT LANGUAGE SQL AS $$
374
422
INSERT INTO t_hash_sharded VALUES (100) RETURNING crdb_internal_a_shard_16;
375
423
SELECT 1;
376
424
$$;
377
425
426
+ statement ok
427
+ RESET use_improved_routine_dependency_tracking;
428
+
378
429
statement error pgcode 2BP01 pq: cannot drop column "crdb_internal_a_shard_16" because function "f145098" depends on it
379
430
DROP INDEX i;
380
431
0 commit comments