should be it

This commit is contained in:
2025-10-24 19:21:19 -05:00
parent a4b23fc57c
commit f09560c7b1
14047 changed files with 3161551 additions and 1 deletions

View File

@@ -0,0 +1,39 @@
# name: test/sql/catalog/view/recursive_view.test
# description: Issue #3017: Querying View of a View Crashes
# group: [view]
statement ok
set storage_compatibility_version='v0.10.2'
statement ok
CREATE TABLE IF NOT EXISTS test (val INTEGER);
statement ok
INSERT INTO test(val) VALUES (1), (2), (3);
# recursive view definition
statement ok
CREATE OR REPLACE VIEW foo AS (SELECT * FROM test);
statement ok
CREATE OR REPLACE VIEW foo AS (SELECT * FROM foo);
statement error
SELECT * FROM foo;
----
<REGEX>:.*Binder Error.*infinite recursion detected.*
# more complex recursive view definition
statement ok
CREATE OR REPLACE VIEW foo AS (SELECT * FROM test);
statement ok
CREATE OR REPLACE VIEW foo2 AS (SELECT * FROM foo);
statement ok
CREATE OR REPLACE VIEW foo AS (SELECT (SELECT * FROM foo2));
statement error
SELECT * FROM foo;
----
<REGEX>:.*Binder Error.*infinite recursion detected.*

View File

@@ -0,0 +1,36 @@
# name: test/sql/catalog/view/recursive_view_with_dependencies.test
# description: Issue #3017: Querying View of a View Crashes
# group: [view]
statement ok
set storage_compatibility_version='v1.0.0'
statement ok
set enable_view_dependencies=true
statement ok
CREATE TABLE IF NOT EXISTS test (val INTEGER);
statement ok
INSERT INTO test(val) VALUES (1), (2), (3);
# recursive view definition
statement ok
CREATE OR REPLACE VIEW foo AS (SELECT * FROM test);
statement error
CREATE OR REPLACE VIEW foo AS (SELECT * FROM foo);
----
Catalog Error: CREATE OR REPLACE is not allowed to depend on itself
# more complex recursive view definition
statement ok
CREATE OR REPLACE VIEW foo AS (SELECT * FROM test);
statement ok
CREATE OR REPLACE VIEW foo2 AS (SELECT * FROM foo);
statement error
CREATE OR REPLACE VIEW foo AS (SELECT (SELECT * FROM foo2));
----
Catalog Error: CREATE OR REPLACE is not allowed to depend on itself

View File

@@ -0,0 +1,25 @@
# name: test/sql/catalog/view/test_stacked_view.test
# description: Stacked views uh yeah
# group: [view]
# create a table
statement ok
CREATE TABLE t1(i INTEGER)
statement ok
INSERT INTO t1 VALUES (41), (42), (43), (44)
statement ok
CREATE VIEW v1 (v1c1, v1c2) AS SELECT i,i+1 FROM t1 WHERE i > 41
statement ok
CREATE VIEW v2 (v2c1, v2c2, v2c3) AS SELECT v1c1, v1c2, v1c1+v1c2 FROM v1 WHERE v1c2 > 42
statement ok
CREATE VIEW v3 (v3c1, v3c2) AS SELECT v2c1, v2c3 FROM v2 WHERE v2c1 > 43
query I
SELECT v3c2+1 FROM v3 WHERE v3c1 > 42
----
90

View File

@@ -0,0 +1,76 @@
# name: test/sql/catalog/view/test_view.test
# description: Test view creation
# group: [view]
# create a table
statement ok
CREATE TABLE t1(i INTEGER)
statement ok
INSERT INTO t1 VALUES (41), (42), (43)
statement ok
CREATE VIEW v1 AS SELECT
i AS j
FROM t1 WHERE i < 43
statement error
CREATE VIEW v1 AS SELECT 'whatever'
----
<REGEX>:.*Catalog Error.*already exists.*
query I
SELECT j FROM v1 WHERE j > 41
----
42
# name alias in view
query I
SELECT x FROM v1 t1(x) WHERE x > 41
----
42
statement ok
DROP VIEW v1
statement error
SELECT j FROM v1 WHERE j > 41
----
<REGEX>:.*Catalog Error.*does not exist.*
statement ok
CREATE VIEW v1 AS SELECT 'whatever'
query T
SELECT * FROM v1
----
whatever
statement ok
CREATE OR REPLACE VIEW v1 AS SELECT 42
query I
SELECT * FROM v1
----
42
statement error
INSERT INTO v1 VALUES (1)
----
<REGEX>:.*Catalog Error.*not an table.*
statement ok
DROP VIEW v1
statement error
DROP VIEW v1
----
<REGEX>:.*Catalog Error.*does not exist.*
statement ok
DROP VIEW IF EXISTS v1
statement error
CREATE VIEW v1 AS SELECT * FROM dontexist
----
<REGEX>:.*Catalog Error.*does not exist.*

View File

@@ -0,0 +1,55 @@
# name: test/sql/catalog/view/test_view_alias.test
# description: Test view creation with alias
# group: [view]
# create a table
statement ok
CREATE TABLE t1(i INTEGER)
statement ok
INSERT INTO t1 VALUES (41), (42), (43)
# this should fail because there are more aliases for the view than columns in the query
statement error
CREATE VIEW v1 (j, "j2") AS SELECT * FROM t1
----
statement ok
CREATE VIEW v1 (j, "j2") AS SELECT i,i+1 FROM t1
query II
SELECT j, j2 FROM v1
----
41 42
42 43
43 44
statement ok
DROP VIEW v1
statement ok
CREATE VIEW v1 (j, "j2") AS SELECT i,i+1, i+2 FROM t1
query II
SELECT j, j2 FROM v1
----
41 42
42 43
43 44
statement ok
DROP VIEW v1
statement ok
CREATE VIEW v1 (j, "j2") AS SELECT i,i+1, i+2 as x FROM t1
query III
SELECT j, j2, x FROM v1
----
41 42 43
42 43 44
43 44 45
statement ok
DROP VIEW v1

View File

@@ -0,0 +1,26 @@
# name: test/sql/catalog/view/test_view_delete_update.test
# description: Test deleting/updating views
# group: [view]
# create a table
statement ok
CREATE TABLE t1(i INTEGER)
statement ok
INSERT INTO t1 VALUES (41), (42), (43)
# create a view
statement ok
CREATE VIEW v1 AS SELECT i AS j FROM t1 WHERE i < 43
# try to delete from the view
statement error
DELETE FROM v1;
----
<REGEX>:.*Binder Error: Can only delete.*
# try to update the view
statement error
UPDATE v1 SET j=1;
----
<REGEX>:.*Binder Error: Can only update.*

View File

@@ -0,0 +1,17 @@
# name: test/sql/catalog/view/test_view_drop_concurrent.test
# group: [view]
require 64bit
# Create 4000 threads that all run the contents of this loop
concurrentloop threadid 0 300
# Create the view
statement ok
CREATE TEMPORARY VIEW df AS select 0,0,0 from range(10);
# Drop the view
statement ok
DROP VIEW df;
endloop

View File

@@ -0,0 +1,98 @@
# name: test/sql/catalog/view/test_view_schema_change.test
# description: Test views with changing schema
# group: [view]
statement ok
set storage_compatibility_version='v0.10.2'
# create a table
statement ok
CREATE TABLE t1(i INTEGER)
statement ok
INSERT INTO t1 VALUES (41), (42), (43)
# create a view that queries that table
statement ok
CREATE VIEW v1 AS SELECT * FROM t1
query I
SELECT * FROM v1
----
41
42
43
# now drop the table and create a table that has a different schema
statement ok
DROP TABLE t1
statement ok
CREATE TABLE t1(i DATE)
# querying the view fails because the column types don't match the expected types
statement error
SELECT * FROM v1
----
# now drop the table and create one that has extra columns
statement ok
DROP TABLE t1
statement ok
CREATE TABLE t1(i INTEGER, j INTEGER)
# again querying the view fails: there are extra columns present
statement error
SELECT * FROM v1
----
# now drop the table and create one that has differently named columns
statement ok
DROP TABLE t1
statement ok
CREATE TABLE t1(k INTEGER)
# names returned by the view have changed
statement error
SELECT * FROM v1
----
Binder Error: Contents of view were altered: names don't match!
statement ok
DROP TABLE t1
statement ok
CREATE TABLE t1(i INTEGER)
# now we can query again!
query I
SELECT * FROM v1
----
# Changing the types of the table that the view references also makes the view unusable
statement ok
ALTER TABLE t1 ALTER i TYPE VARCHAR;
statement error
select * from v1;
----
Binder Error: Contents of view were altered: types don't match!
# reverting the types fixes the issue
statement ok
ALTER TABLE t1 ALTER i TYPE INTEGER
query I
SELECT * FROM v1
----
# changing the column names makes the view unusable again
statement ok
ALTER TABLE t1 RENAME i TO j
statement error
SELECT * FROM v1
----
Binder Error: Contents of view were altered: names don't match!

View File

@@ -0,0 +1,114 @@
# name: test/sql/catalog/view/test_view_schema_change_with_dependencies.test
# description: Test views with changing schema
# group: [view]
require skip_reload
statement ok
set storage_compatibility_version='v1.0.0'
statement ok
set enable_view_dependencies=true
# create a table
statement ok
CREATE TABLE t1(i INTEGER)
statement ok
INSERT INTO t1 VALUES (41), (42), (43)
# create a view that queries that table
statement ok
CREATE VIEW v1 AS SELECT * FROM t1
query I
SELECT * FROM v1
----
41
42
43
# now drop the table and create a table that has a different schema
statement error
DROP TABLE t1
----
view "v1" depends on table "t1".
statement ok
DROP TABLE t1 CASCADE
statement ok
CREATE TABLE t1(i DATE)
# querying the view fails because the column types don't match the expected types
statement error
SELECT * FROM v1
----
# now drop the table and create one that has extra columns
statement ok
DROP TABLE t1
statement ok
CREATE TABLE t1(i INTEGER, j INTEGER)
# again querying the view fails: there are extra columns present
statement error
SELECT * FROM v1
----
# now drop the table and create one that has differently named columns
statement ok
DROP TABLE t1
statement ok
CREATE TABLE t1(k INTEGER)
# Was dropped by the CASCADE from earlier
statement error
SELECT * FROM v1
----
Catalog Error: Table with name v1 does not exist!
statement ok
DROP TABLE t1
statement ok
CREATE TABLE t1(i INTEGER)
statement error
SELECT * FROM v1
----
Table with name v1 does not exist!
# Recreate the VIEW
statement ok
CREATE VIEW v1 AS SELECT * FROM t1
# Changing the types of the table can't be done because we have dependencies
statement error
ALTER TABLE t1 ALTER i TYPE VARCHAR;
----
Dependency Error: Cannot alter entry "t1" because there are entries that depend on it.
statement ok
drop view v1;
statement ok
ALTER TABLE t1 ALTER i TYPE VARCHAR;
# Recreate the VIEW
statement ok
CREATE VIEW v1 AS SELECT * FROM t1
# Changing the column names is also not possible while V1 is alive
statement error
ALTER TABLE t1 RENAME i TO j
----
Dependency Error: Cannot alter entry "t1" because there are entries that depend on it.
statement ok
drop view v1;
statement ok
ALTER TABLE t1 RENAME i TO j

View File

@@ -0,0 +1,92 @@
# name: test/sql/catalog/view/test_view_sql.test
# description: Test behavior of 'sql' on various different views
# group: [view]
statement ok
set storage_compatibility_version='v0.10.2'
statement ok
create schema my_schema;
# X contains columns `a` and `y`
statement ok
CREATE VIEW my_schema.X (a) AS SELECT 'x' as x, 'y' as y;
query I
select trim(sql, chr(10)) from duckdb_views() where internal = false;
----
CREATE VIEW my_schema.X (a) AS SELECT 'x' AS x, 'y' AS y;
statement ok
alter view my_schema.X rename to Y;
# Properly renamed to Y
query I
select trim(sql, chr(10)) from duckdb_views() where internal = false;
----
CREATE VIEW my_schema.Y (a) AS SELECT 'x' AS x, 'y' AS y;
statement ok
drop schema my_schema cascade;
query I
select trim(sql, chr(10)) from duckdb_views() where internal = false;
----
statement ok
create table tbl (
a integer,
b varchar
)
statement ok
create view vw as select * from tbl;
# sql is not affected by the column names of the table
query I
select trim(sql, chr(10)) from duckdb_views() where internal = false;
----
CREATE VIEW vw AS SELECT * FROM tbl;
statement ok
alter table tbl rename column b to x;
# sql is not affected by the column names of the table
query I
select trim(sql, chr(10)) from duckdb_views() where internal = false;
----
CREATE VIEW vw AS SELECT * FROM tbl;
statement ok
create or replace view vw (c1, c2) as select * from tbl;
statement ok
create or replace table "table name" (
"column name 1" integer,
"column name 2" varchar
)
statement ok
create or replace view "view name" as select * from "table name";
statement ok
drop view vw;
query I
select trim(sql, chr(10)) from duckdb_views() where internal = false;
----
CREATE VIEW "view name" AS SELECT * FROM "table name";
statement ok
drop view "view name"
statement ok
create schema "schema name";
statement ok
CREATE VIEW "schema name"."view name" ("other name 1", "column name 2") AS SELECT * FROM "table name";
query I
select trim(sql, chr(10)) from duckdb_views() where internal = false;
----
CREATE VIEW "schema name"."view name" ("other name 1", "column name 2") AS SELECT * FROM "table name";

View File

@@ -0,0 +1,110 @@
# name: test/sql/catalog/view/test_view_sql_with_dependencies.test
# description: Test behavior of 'sql' on various different views
# group: [view]
require skip_reload
statement ok
set storage_compatibility_version='v1.0.0'
statement ok
set enable_view_dependencies=true
statement ok
create schema my_schema;
# X contains columns `a` and `y`
statement ok
CREATE VIEW my_schema.X (a) AS SELECT 'x' as x, 'y' as y;
query I
select trim(sql, chr(10)) from duckdb_views() where internal = false;
----
CREATE VIEW my_schema.X (a) AS SELECT 'x' AS x, 'y' AS y;
statement ok
alter view my_schema.X rename to Y;
# Properly renamed to Y
query I
select trim(sql, chr(10)) from duckdb_views() where internal = false;
----
CREATE VIEW my_schema.Y (a) AS SELECT 'x' AS x, 'y' AS y;
statement ok
drop schema my_schema cascade;
query I
select trim(sql, chr(10)) from duckdb_views() where internal = false;
----
statement ok
create table tbl (
a integer,
b varchar
)
statement ok
create view vw as select * from tbl;
# sql is not affected by the column names of the table
query I
select trim(sql, chr(10)) from duckdb_views() where internal = false;
----
CREATE VIEW vw AS SELECT * FROM tbl;
statement error
alter table tbl rename column b to x;
----
Dependency Error: Cannot alter entry "tbl" because there are entries that depend on it.
# The VIEW has to be dropped before the table can be altered
statement ok
drop view vw;
statement ok
alter table tbl rename column b to x;
# Recreate the view
statement ok
CREATE VIEW vw AS SELECT * FROM tbl;
# sql is not affected by the column names of the table
query I
select trim(sql, chr(10)) from duckdb_views() where internal = false;
----
CREATE VIEW vw AS SELECT * FROM tbl;
statement ok
create or replace view vw (c1, c2) as select * from tbl;
statement ok
create or replace table "table name" (
"column name 1" integer,
"column name 2" varchar
)
statement ok
create or replace view "view name" as select * from "table name";
statement ok
drop view vw;
query I
select trim(sql, chr(10)) from duckdb_views() where internal = false;
----
CREATE VIEW "view name" AS SELECT * FROM "table name";
statement ok
drop view "view name"
statement ok
create schema "schema name";
statement ok
CREATE VIEW "schema name"."view name" ("other name 1", "column name 2") AS SELECT * FROM "table name";
query I
select trim(sql, chr(10)) from duckdb_views() where internal = false;
----
CREATE VIEW "schema name"."view name" ("other name 1", "column name 2") AS SELECT * FROM "table name";

View File

@@ -0,0 +1,15 @@
# name: test/sql/catalog/view/view_if_not_exists.test
# description: Test view if not exists
# group: [view]
# create a table
statement ok
CREATE VIEW v1 AS SELECT 42
statement ok
CREATE VIEW IF NOT EXISTS v1 AS SELECT 84;
query I
SELECT * FROM v1
----
42