# LogicTest: local local-opt local-parallel-stmts fakedist fakedist-opt fakedist-metadata

statement ok
CREATE TABLE t (a INT PRIMARY KEY, b INT, c INT, d INT, INDEX (b) STORING (d))

# Empty data
query TT
SHOW EXPERIMENTAL_FINGERPRINTS FROM TABLE t
----
primary  NULL
t_b_idx  NULL

statement ok
INSERT INTO t VALUES (1, 2, 3, 4), (5, 6, 7, 8), (9, 10, 11, 12)

# Add some initial data
query TT
SHOW EXPERIMENTAL_FINGERPRINTS FROM TABLE t
----
primary  -7903300865687235210
t_b_idx  -5073888452016928166

statement ok
UPDATE t SET b = 9

# b is encoded in both indexes, so both should change
query TT
SHOW EXPERIMENTAL_FINGERPRINTS FROM TABLE t
----
primary  3722816579880544080
t_b_idx  -8494698744159250398

statement ok
UPDATE t SET c = 10

# c is encoded only in primary, so t_b_idx shouldn't change
query TT
SHOW EXPERIMENTAL_FINGERPRINTS FROM TABLE t
----
primary  4547357529681250049
t_b_idx  -8494698744159250398

statement ok
UPDATE t SET d = 10

# d is encoded in both indexes, so both should change
query TT
SHOW EXPERIMENTAL_FINGERPRINTS FROM TABLE t
----
primary  492416650140211287
t_b_idx  -8497500299788131628

statement ok
ALTER TABLE t ADD COLUMN e string;

# Table changed, but the new column is all NULLs so neither fingerprint should
# change
query TT
SHOW EXPERIMENTAL_FINGERPRINTS FROM TABLE t
----
primary  492416650140211287
t_b_idx  -8497500299788131628

statement ok
UPDATE t SET e = 'foo' WHERE a = 1;

# Column e is not in index t_b_idx so its fingerprint shouldn't change
query TT
SHOW EXPERIMENTAL_FINGERPRINTS FROM TABLE t
----
primary  1205834892498753533
t_b_idx  -8497500299788131628

statement ok
DROP INDEX t@t_b_idx

# Double check that dropping an index doesn't affect the fingerprint of primary
query TT
SHOW EXPERIMENTAL_FINGERPRINTS FROM TABLE t
----
primary  1205834892498753533

# Make sure fully qualified table names work
query TT
SHOW EXPERIMENTAL_FINGERPRINTS FROM TABLE test.t
----
primary  1205834892498753533

statement ok
CREATE TABLE "foo""bar" ("a""b" INT PRIMARY KEY, b INT, INDEX "id""x" (b))

statement ok
INSERT INTO "foo""bar" VALUES (1, 2), (3, 4), (5, 6)

# Make sure we handle table, index, and column name escaping correctly in the
# internally generated query.
query TT
SHOW EXPERIMENTAL_FINGERPRINTS FROM TABLE "foo""bar"
----
primary  590693963425091008
id"x     590692863913460538

# BYTES is special cased so make sure tables with both BYTES and non-BYTES
# columns work
statement ok
CREATE TABLE blocks (block_id INT PRIMARY KEY, raw_bytes BYTES NOT NULL)

statement ok
INSERT INTO blocks VALUES (1, b'\x01')

query TT
SHOW EXPERIMENTAL_FINGERPRINTS FROM TABLE blocks
----
primary  590700560494856555
