# 障害票 1705
# 索引を使わないNOTとジョイン条件の組み合わせ

Begin;
Initialize;
InitializeSession "TESTDB";

CreateThread "Prepare";
JoinThread "Prepare";

CreateThread "Test";
JoinThread "Test";

CreateThread "Finish";
JoinThread "Finish";

TerminateSession;
Terminate;
End;

Prepare
{
Command "drop database TESTDB if exists";
Command "create database TESTDB";

Command "CREATE TABLE bib (
	id              INT GENERATED BY DEFAULT AS IDENTITY ( START WITH 1 GET MAX),
	ncid            NVARCHAR(10) HINT 'FIXED',
	title_info      NVARCHAR(NO LIMIT) HINT HEAP,
	ptbid_for_search        NVARCHAR(10) ARRAY [32] HINT 'FIXED',
	PRIMARY KEY (id)
)";
Command "CREATE INDEX bib_ncid ON bib(ncid)";
Command "CREATE ARRAY INDEX bib_ptbid_for_search ON bib(ptbid_for_search)";

Command "insert bib(ncid, title_info, ptbid_for_search) values (1, 'title', array[2,3])";
Command "insert bib(ncid, title_info, ptbid_for_search) values (2, 'xxx', null)";
Command "insert bib(ncid, title_info, ptbid_for_search) values (3, 'xxx', null)";
Command "insert bib(ncid, title_info, ptbid_for_search) values (4, 'title', array[5,6,7])";
Command "insert bib(ncid, title_info, ptbid_for_search) values (5, 'xxx', null)";
Command "insert bib(ncid, title_info, ptbid_for_search) values (6, 'yyy', null)";
Command "insert bib(ncid, title_info, ptbid_for_search) values (7, 'zzz', null)";
}

Test
{
#期待結果：{1}
Command "select count(*) from bib bib2 where bib2.ptbid_for_search[] in (select bib1.ncid from bib bib1 where title_info not like '%x%')";
#期待結果：{2}
Command "select count(*) from bib bib2 where bib2.ptbid_for_search[] in (select bib1.ncid from bib bib1 where id < 1000000 and title_info not like '%y%')";
}

Finish
{
Command "drop database TESTDB";
}
