# This test ensures that online restore restores the backed up auto stats
# settings

reset test-nodelocal
----

new-cluster name=s1 disable-tenant
----

exec-sql
USE data;
CREATE TABLE reg (i INT PRIMARY KEY, s STRING);
INSERT INTO reg VALUES (1, 'x'),(2,'y'),(3,'z');
CREATE TABLE stats (i INT PRIMARY KEY, s STRING);
CREATE TABLE nostats (i INT PRIMARY KEY, s STRING);
ALTER TABLE stats SET (sql_stats_automatic_collection_enabled = true);
ALTER TABLE nostats SET (sql_stats_automatic_collection_enabled = false);
----

exec-sql
BACKUP INTO 'nodelocal://1/cluster/';
----


new-cluster name=s2 share-io-dir=s1 allow-implicit-access disable-tenant
----


exec-sql
RESTORE DATABASE data FROM LATEST IN 'nodelocal://1/cluster/' with EXPERIMENTAL DEFERRED COPY;
----

# Wait for download job to complete

query-sql retry
SELECT count(*) FROM [SHOW JOBS] WHERE job_type='RESTORE' and status='succeeded';
----
2

query-sql
SHOW CREATE TABLE data.reg
----
data.public.reg CREATE TABLE public.reg (
	i INT8 NOT NULL,
	s STRING NULL,
	CONSTRAINT reg_pkey PRIMARY KEY (i ASC)
)

query-sql
SHOW CREATE TABLE data.stats
----
data.public.stats CREATE TABLE public.stats (
	i INT8 NOT NULL,
	s STRING NULL,
	CONSTRAINT stats_pkey PRIMARY KEY (i ASC)
) WITH (sql_stats_automatic_collection_enabled = true)

query-sql
SHOW CREATE TABLE data.nostats
----
data.public.nostats CREATE TABLE public.nostats (
	i INT8 NOT NULL,
	s STRING NULL,
	CONSTRAINT nostats_pkey PRIMARY KEY (i ASC)
) WITH (sql_stats_automatic_collection_enabled = false)
