Skip to content

Commit 7a8b18d

Browse files
craig[bot]spilchen
andcommitted
Merge #145551
145551: sql: fix internal failure with temp tables during ALTER operations r=spilchen a=spilchen Certain operations—such as ALTER TYPE or ALTER DATABASE ... ADD REGION—could trigger an assertion failure if temporary tables were present. The failure occurred in planner.forEachMutableTableInDatabase, which used GetAllDescriptors. That method excludes temp schemas, so schema resolution for a temp table would fail. The fix replaces GetAllDescriptors with GetAll, which includes temp schemas and avoids the failure. Note: a broader catalog API issue around accessing temp objects across sessions (see issue #97822) remains unresolved. Fixes #97975 Epic: none Release note (bug fix): Fixed an internal assertion failure that could occur during operations like ALTER TYPE or ALTER DATABASE ... ADD REGION when temporary tables were present. Co-authored-by: Matt Spilchen <[email protected]>
2 parents 6817fdd + 38f888a commit 7a8b18d

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

pkg/ccl/logictestccl/testdata/logic_test/multi_region

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# knob-opt: sync-event-log
22
# LogicTest: multiregion-9node-3region-3azs multiregion-9node-3region-3azs-tenant multiregion-9node-3region-3azs-no-los
33

4+
statement ok
5+
SET experimental_enable_temp_tables=true
6+
47
query TTTTT colnames,rowsort
58
SHOW REGIONS
69
----
@@ -791,6 +794,14 @@ create database alter_survive_db
791794
statement ok
792795
use alter_survive_db
793796

797+
# Including a type and a temp to repro issue #97975. Prior to fixing that, ADD
798+
# REGION would fail because it couldn't find a temp schema
799+
statement ok
800+
create type my_enum as enum ('value1', 'value2');
801+
802+
statement ok
803+
CREATE TEMP TABLE tbl (a int)
804+
794805
statement error database must have associated regions before a survival goal can be set
795806
alter database alter_survive_db survive region failure
796807

@@ -806,6 +817,9 @@ alter database alter_survive_db add region "ap-southeast-2"
806817
statement ok
807818
alter database alter_survive_db add region "us-east-1"
808819

820+
statement ok
821+
drop type my_enum;
822+
809823
# Create some tables to validate that their zone configurations are adjusted appropriately.
810824
query TT
811825
SHOW ZONE CONFIGURATION FOR DATABASE alter_survive_db

pkg/sql/database.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func (p *planner) forEachMutableTableInDatabase(
106106
dbDesc catalog.DatabaseDescriptor,
107107
fn func(ctx context.Context, scName string, tbDesc *tabledesc.Mutable) error,
108108
) error {
109-
all, err := p.Descriptors().GetAllDescriptors(ctx, p.txn)
109+
all, err := p.Descriptors().GetAll(ctx, p.txn)
110110
if err != nil {
111111
return err
112112
}

pkg/sql/logictest/testdata/logic_test/temp_table

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,3 +511,29 @@ statement ok
511511
DROP DATABASE database_142780
512512

513513
subtest end
514+
515+
# Test ALTER TYPE when a temp table exists.
516+
subtest alter_type
517+
518+
statement ok
519+
USE defaultdb;
520+
521+
statement ok
522+
create type my_enum as enum ('value1', 'value2');
523+
524+
statement ok
525+
create temporary table tmp_table (id int primary key);
526+
527+
statement ok
528+
insert into tmp_table values (1), (2), (3);
529+
530+
statement ok
531+
ALTER TYPE my_enum ADD VALUE 'value3';
532+
533+
statement ok
534+
DROP TYPE my_enum;
535+
536+
statement ok
537+
DROP TABLE tmp_table;
538+
539+
subtest end

0 commit comments

Comments
 (0)