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,63 @@
# name: test/sql/index/art/create_drop/test_art_create_if_exists.test
# description: Test ART creation with the same index already existing
# group: [create_drop]
statement ok
PRAGMA enable_verification;
statement ok
PRAGMA immediate_transaction_mode = True;
statement ok
CREATE TABLE tbl AS SELECT range AS i FROM range(100);
# Trigger write-write conflict.
statement ok con1
BEGIN;
statement ok con1
CREATE INDEX IF NOT EXISTS my_idx ON tbl(i);
statement ok con2
BEGIN;
statement error con2
CREATE INDEX IF NOT EXISTS my_idx ON tbl(i);
----
<REGEX>:TransactionContext Error.*write-write.*
statement ok con1
COMMIT;
statement ok con2
COMMIT;
query I
SELECT COUNT(*) FROM duckdb_indexes;
----
1
statement ok
DROP INDEX my_idx;
# Trigger early-out.
statement ok
CREATE INDEX IF NOT EXISTS my_idx ON tbl(i);
statement ok
CREATE INDEX IF NOT EXISTS my_idx ON tbl(i);
statement error
CREATE INDEX my_idx ON tbl(i);
----
<REGEX>:Catalog Error.*already exists.*
query I
SELECT COUNT(*) FROM duckdb_indexes;
----
1
statement ok
DROP INDEX my_idx;

View File

@@ -0,0 +1,54 @@
# name: test/sql/index/art/create_drop/test_art_create_index_delete.test
# description: Test ART creation with deletions and multiple connections
# group: [create_drop]
statement ok
PRAGMA enable_verification
statement ok
SET immediate_transaction_mode=true
statement ok
CREATE TABLE integers(i INTEGER)
statement ok
INSERT INTO integers SELECT * FROM range(10)
statement ok con1
BEGIN
statement ok
DELETE FROM integers WHERE i=2 OR i=7
query I con1
SELECT * FROM integers WHERE i=1;
----
1
query I con1
SELECT * FROM integers WHERE i=2;
----
2
statement ok
CREATE INDEX i_index ON integers(i)
query I
SELECT * FROM integers WHERE i=1;
----
1
query I
SELECT * FROM integers WHERE i=2;
----
# connection 1 still sees the old state
query I con1
SELECT * FROM integers WHERE i=1;
----
1
query I con1
SELECT * FROM integers WHERE i=2;
----
2

View File

@@ -0,0 +1,31 @@
# name: test/sql/index/art/create_drop/test_art_create_index_duplicate_deletes.test
# description: Test ART index creation with deletes
# group: [create_drop]
statement ok
PRAGMA enable_verification
statement ok
CREATE TABLE integers(i INTEGER)
statement ok
INSERT INTO integers SELECT * FROM range(10)
statement ok
DELETE FROM integers
statement ok
INSERT INTO integers SELECT * FROM range(10)
statement ok
CREATE INDEX i_index ON integers(i)
query I
SELECT * FROM integers WHERE i=1;
----
1
query I
SELECT * FROM integers WHERE i=2;
----
2

View File

@@ -0,0 +1,62 @@
# name: test/sql/index/art/create_drop/test_art_create_many_duplicates.test
# description: Test ART creation with many duplicates in leaves
# group: [create_drop]
statement ok
PRAGMA enable_verification
statement ok
CREATE TABLE integers(i INTEGER)
statement ok
BEGIN TRANSACTION
statement ok
INSERT INTO integers SELECT * FROM repeat(1, 1500) t1(i)
statement ok
INSERT INTO integers SELECT * FROM repeat(2, 1500) t1(i)
statement ok
INSERT INTO integers SELECT * FROM repeat(3, 1500) t1(i)
statement ok
INSERT INTO integers SELECT * FROM repeat(4, 1500) t1(i)
statement ok
COMMIT
statement ok
CREATE INDEX i_index ON integers(i)
query I
SELECT count(i) FROM integers WHERE i > 1 AND i < 3
----
1500
query I
SELECT count(i) FROM integers WHERE i >= 1 AND i < 3
----
3000
query I
SELECT count(i) FROM integers WHERE i > 1
----
4500
query I
SELECT count(i) FROM integers WHERE i < 4
----
4500
query I
SELECT count(i) FROM integers WHERE i < 5
----
6000
statement ok
DROP INDEX i_index
statement ok
DROP TABLE integers

View File

@@ -0,0 +1,61 @@
# name: test/sql/index/art/create_drop/test_art_create_many_duplicates_deletes.test
# description: Test ART creation with many duplicates in leaves and deletions
# group: [create_drop]
statement ok
PRAGMA enable_verification
statement ok
BEGIN TRANSACTION
statement ok
CREATE TABLE integers(i integer)
statement ok
INSERT INTO integers SELECT * FROM repeat(1, 1500) t1(i)
statement ok
INSERT INTO integers SELECT * FROM repeat(2, 1500) t1(i)
statement ok
INSERT INTO integers SELECT * FROM repeat(3, 1500) t1(i)
statement ok
INSERT INTO integers SELECT * FROM repeat(4, 1500) t1(i)
statement ok
INSERT INTO integers SELECT * FROM repeat(5, 1500) t1(i)
statement ok
COMMIT
statement ok
DELETE FROM integers WHERE i = 5
statement ok
CREATE INDEX i_index ON integers(i)
query I
SELECT count(i) FROM integers WHERE i > 1 AND i < 3
----
1500
query I
SELECT count(i) FROM integers WHERE i >= 1 AND i < 3
----
3000
query I
SELECT count(i) FROM integers WHERE i > 1
----
4500
query I
SELECT count(i) FROM integers WHERE i < 4
----
4500
query I
SELECT count(i) FROM integers WHERE i < 5
----
6000

View File

@@ -0,0 +1,42 @@
# name: test/sql/index/art/create_drop/test_art_create_unique.test
# description: Test unique ART creation
# group: [create_drop]
statement ok
PRAGMA enable_verification
statement ok
CREATE TABLE t0(c0 INTEGER);
statement ok
CREATE UNIQUE INDEX i0 ON t0(c0);
statement ok
INSERT INTO t0(c0) VALUES (1);
statement error
INSERT INTO t0(c0) VALUES (1);
----
<REGEX>:.*Constraint Error.*Duplicate key.*
query I
SELECT * FROM t0 WHERE t0.c0 = 1;
----
1
statement ok
CREATE TABLE merge_violation (id INT);
statement ok
INSERT INTO merge_violation SELECT range FROM range(2048);
statement ok
INSERT INTO merge_violation SELECT range + 10000 FROM range(2048);
statement ok
INSERT INTO merge_violation VALUES (2047);
statement error
CREATE UNIQUE INDEX idx ON merge_violation(id);
----
<REGEX>:.*Constraint Error.*contains duplicates on indexed column.*

View File

@@ -0,0 +1,71 @@
# name: test/sql/index/art/create_drop/test_art_drop_index.test
# description: Test the DROP INDEX statement
# group: [create_drop]
statement ok
PRAGMA enable_verification
statement ok
CREATE TABLE A (A1 INTEGER,A2 VARCHAR, A3 INTEGER)
statement ok
INSERT INTO A VALUES (1, 1, 1)
statement ok
INSERT INTO A VALUES (2, 2, 2)
statement ok
CREATE TABLE B (B1 INTEGER,B2 INTEGER, B3 INTEGER)
statement ok
INSERT INTO B VALUES (1, 1, 1)
statement ok
INSERT INTO B VALUES (2, 2, 2)
statement ok
CREATE TABLE C (C1 VARCHAR, C2 INTEGER, C3 INTEGER)
statement ok
INSERT INTO C VALUES ('t1', 1, 1)
statement ok
INSERT INTO C VALUES ('t2', 2, 2)
query T
SELECT A2 FROM A WHERE A1=1
----
1
statement ok
CREATE INDEX A_index ON A (A1)
query T
SELECT A2 FROM A WHERE A1=1
----
1
statement ok
CREATE INDEX B_index ON B (B1)
query T
SELECT A2 FROM A WHERE A1=1
----
1
statement ok
CREATE INDEX C_index ON C (C2)
query T
SELECT A2 FROM A WHERE A1=1
----
1
statement ok
DROP INDEX IF EXISTS A_index
query T
SELECT A2 FROM A WHERE A1=1
----
1

View File

@@ -0,0 +1,54 @@
# name: test/sql/index/art/create_drop/test_art_invalid_create_index.test
# description: Test triggering different exceptions
# group: [create_drop]
statement ok
PRAGMA enable_verification
statement ok
CREATE TABLE integers(i integer, j integer, k BOOLEAN)
statement error
CREATE INDEX ON integers(i)
----
<REGEX>:.*Not implemented Error.*provide an index name.*
statement error
CREATE INDEX i_index ON integers(i COLLATE "NOCASE")
----
<REGEX>:.*Not implemented Error.*Index with collation not supported yet.*
statement error
CREATE INDEX i_index ON integers(i COLLATE "de_DE")
----
<REGEX>:.*Not implemented Error.*Index with collation not supported yet.*
statement error
CREATE INDEX i_index ON integers using blabla(i)
----
<REGEX>:.*Binder Error.*Unknown index type.*
statement error
CREATE INDEX i_index ON integers(f)
----
<REGEX>:.*Binder Error.*does not have a column.*
# index on list columns
statement ok
create table lists(id int, l int[]);
statement error
create index i_index on lists(l);
----
<REGEX>:.*Invalid type Error.*Invalid type for index key.*
statement error
create index i_index on lists(id, l);
----
<REGEX>:.*Invalid type Error.*Invalid type for index key.*
# index on constant columns
statement error
create index i_index on integers(('hello'));
----
<REGEX>:.*Binder Error.*does not refer to any columns.*

View File

@@ -0,0 +1,49 @@
# name: test/sql/index/art/create_drop/test_art_long_keys.test_slow
# description: Test ART creation very long BLOBs.
# group: [create_drop]
# Try creating an index with identical long keys.
statement ok
CREATE TABLE long_strings (id BLOB);
statement ok
INSERT INTO long_strings SELECT repeat('k', 1000000);
statement ok
INSERT INTO long_strings SELECT range::VARCHAR::BLOB FROM range(100000);
statement ok
INSERT INTO long_strings SELECT repeat('k', 1000000);
statement ok
INSERT INTO long_strings SELECT range::VARCHAR::BLOB || 'other' FROM range(100000);
statement ok
INSERT INTO long_strings SELECT repeat('k', 1000000);
statement error
CREATE INDEX idx ON long_strings(id);
----
<REGEX>:Invalid Input Error.*exceeds the maximum size.*
# Now we try medium-sized keys.
statement ok
CREATE TABLE medium_strings (id BLOB);
statement ok
INSERT INTO medium_strings SELECT repeat('k', 122879);
statement ok
INSERT INTO medium_strings SELECT range::VARCHAR::BLOB FROM range(100000);
statement ok
INSERT INTO medium_strings SELECT repeat('k', 122879);
statement ok
INSERT INTO medium_strings SELECT range::VARCHAR::BLOB || 'other' FROM range(100000);
statement ok
INSERT INTO medium_strings SELECT repeat('k', 122879);
statement ok
CREATE INDEX idx ON medium_strings(id);

View File

@@ -0,0 +1,90 @@
# name: test/sql/index/art/create_drop/test_art_many_versions.test
# description: Test ART index creation with many versions
# group: [create_drop]
statement ok
SET immediate_transaction_mode=true
statement ok
PRAGMA enable_verification
# insert the values [1...20001]
statement ok con1
CREATE TABLE integers(i INTEGER)
statement ok con1
INSERT INTO integers SELECT * FROM range(1, 20001, 1)
# now start a transaction in con2
statement ok con2
BEGIN TRANSACTION
# increment values by 1
statement ok con1
UPDATE integers SET i=i+1
# now start a transaction in con3
statement ok con3
BEGIN TRANSACTION
# increment values by 1 again
statement ok con1
UPDATE integers SET i=i+1
# now start a transaction in con4
statement ok con4
BEGIN TRANSACTION
# increment values by 1 again
statement ok con1
UPDATE integers SET i=i+1
# create an index, this fails because we have outstanding updates
statement error con1
CREATE INDEX i_index ON integers using art(i)
----
# con2
query R con2
SELECT SUM(i) FROM integers
----
200010000.000000
query R con2
SELECT SUM(i) FROM integers WHERE i > 0
----
200010000.000000
# con3
query R con3
SELECT SUM(i) FROM integers
----
200030000.000000
query R con3
SELECT SUM(i) FROM integers WHERE i > 0
----
200030000.000000
# con4
query R con4
SELECT SUM(i) FROM integers
----
200050000.000000
query R con4
SELECT SUM(i) FROM integers WHERE i > 0
----
200050000.000000
# total sum
query R con1
SELECT SUM(i) FROM integers
----
200070000.000000
query R con1
SELECT SUM(i) FROM integers WHERE i > 0
----
200070000.000000

View File

@@ -0,0 +1,61 @@
# name: test/sql/index/art/create_drop/test_art_single_value.test
# description: Test an ART containing a single value
# group: [create_drop]
statement ok
PRAGMA enable_verification
statement ok
CREATE TABLE integers(i INTEGER)
statement ok
CREATE INDEX i_index ON integers using art(i)
statement ok
INSERT INTO integers VALUES (1)
query I
SELECT * FROM integers WHERE i < 3
----
1
query I
SELECT * FROM integers WHERE i <= 1
----
1
query I
SELECT * FROM integers WHERE i > 0
----
1
query I
SELECT * FROM integers WHERE i >= 1
----
1
query I
SELECT * FROM integers WHERE i = 1
----
1
query I
SELECT * FROM integers WHERE i < 1
----
query I
SELECT * FROM integers WHERE i <= 0
----
query I
SELECT * FROM integers WHERE i > 1
----
query I
SELECT * FROM integers WHERE i >= 2
----
query I
SELECT * FROM integers WHERE i = 2
----