Skip to content

Commit

Permalink
Add tests for toast in ENR change (#2291)
Browse files Browse the repository at this point in the history
Adding toasts to ENR for temp tables. This was originally introduced as part of #2259 .

Signed-off-by: Tim Chang <[email protected]>
  • Loading branch information
timchang514 authored Jan 25, 2024
1 parent ffd3b17 commit b03fd54
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 0 deletions.
2 changes: 2 additions & 0 deletions test/JDBC/expected/BABEL-4554-vu-cleanup.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DROP TYPE babel_4554_type
GO
64 changes: 64 additions & 0 deletions test/JDBC/expected/BABEL-4554-vu-prepare.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@

-- Verify that newly created temp tables have toasts in ENR.
CREATE TABLE #babel_4554_temp_table(a varchar(4000), b nvarchar(MAX), c sysname)
GO

-- 3: table, toast, index on toast
SELECT COUNT(*) FROM sys.babelfish_get_enr_list()
GO
~~START~~
int
3
~~END~~


DROP TABLE #babel_4554_temp_table
GO

-- 4: table, toast, index on toast, pkey
CREATE TABLE #babel_4554_temp_table_2(a sysname primary key, b nvarchar(MAX))
GO

SELECT COUNT(*) FROM sys.babelfish_get_enr_list()
GO
~~START~~
int
4
~~END~~


-- 1: index
CREATE INDEX #babel_4554_idx1 ON #babel_4554_temp_table_2(b)
GO

SELECT COUNT(*) FROM sys.babelfish_get_enr_list()
GO
~~START~~
int
5
~~END~~


DROP INDEX #babel_4554_idx1 ON #babel_4554_temp_table_2
GO

DROP TABLE #babel_4554_temp_table_2
GO

-- Verify that non-ENR tables don't put their toasts in ENR.
CREATE TYPE babel_4554_type FROM INT
GO

CREATE TABLE #babel_4554_temp_table_not_enr(a babel_4554_type, b nvarchar(MAX))
GO

SELECT COUNT(*) FROM sys.babelfish_get_enr_list()
GO
~~START~~
int
0
~~END~~


DROP TABLE #babel_4554_temp_table_not_enr
GO
25 changes: 25 additions & 0 deletions test/JDBC/expected/BABEL-4554-vu-verify.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

-- We should have no dangling entries here (taken from BABEL-4554 DA)
select *
from pg_class where relname in
(
select relname
from pg_class c
where not exists
(
SELECT * from pg_class d
WHERE c.oid = d.reltoastrelid
)
AND relname in
(
select s.relname from pg_stat_all_tables s where s.relname LIKE 'pg_toast_%'
)
AND pg_table_size(c.oid) = 0
AND c.relkind = 't'
AND c.relpersistence = 't'
)
GO
~~START~~
int#!#varchar#!#int#!#int#!#int#!#int#!#int#!#int#!#int#!#int#!#real#!#int#!#int#!#bit#!#bit#!#varchar#!#varchar#!#smallint#!#smallint#!#bit#!#bit#!#bit#!#bit#!#bit#!#bit#!#varchar#!#bit#!#int#!#int#!#int#!#varchar#!#varchar#!#varchar
~~END~~

2 changes: 2 additions & 0 deletions test/JDBC/input/BABEL-4554-vu-cleanup.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DROP TYPE babel_4554_type
GO
44 changes: 44 additions & 0 deletions test/JDBC/input/BABEL-4554-vu-prepare.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
-- Verify that newly created temp tables have toasts in ENR.

CREATE TABLE #babel_4554_temp_table(a varchar(4000), b nvarchar(MAX), c sysname)
GO

-- 3: table, toast, index on toast
SELECT COUNT(*) FROM sys.babelfish_get_enr_list()
GO

DROP TABLE #babel_4554_temp_table
GO

-- 4: table, toast, index on toast, pkey
CREATE TABLE #babel_4554_temp_table_2(a sysname primary key, b nvarchar(MAX))
GO

SELECT COUNT(*) FROM sys.babelfish_get_enr_list()
GO

-- 1: index
CREATE INDEX #babel_4554_idx1 ON #babel_4554_temp_table_2(b)
GO

SELECT COUNT(*) FROM sys.babelfish_get_enr_list()
GO

DROP INDEX #babel_4554_idx1 ON #babel_4554_temp_table_2
GO

DROP TABLE #babel_4554_temp_table_2
GO

-- Verify that non-ENR tables don't put their toasts in ENR.
CREATE TYPE babel_4554_type FROM INT
GO

CREATE TABLE #babel_4554_temp_table_not_enr(a babel_4554_type, b nvarchar(MAX))
GO

SELECT COUNT(*) FROM sys.babelfish_get_enr_list()
GO

DROP TABLE #babel_4554_temp_table_not_enr
GO
21 changes: 21 additions & 0 deletions test/JDBC/input/BABEL-4554-vu-verify.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-- We should have no dangling entries here (taken from BABEL-4554 DA)

select *
from pg_class where relname in
(
select relname
from pg_class c
where not exists
(
SELECT * from pg_class d
WHERE c.oid = d.reltoastrelid
)
AND relname in
(
select s.relname from pg_stat_all_tables s where s.relname LIKE 'pg_toast_%'
)
AND pg_table_size(c.oid) = 0
AND c.relkind = 't'
AND c.relpersistence = 't'
)
GO

0 comments on commit b03fd54

Please sign in to comment.