---
--case 1:  unsupported index test
---
DROP TABLE if exists cstore_insert_t1;
DROP TABLE if exists row_table;
CREATE TABLE cstore_insert_t1(c1 int, c2 float, c3 text) WITH (orientation = column);
COPY cstore_insert_t1 FROM '@abs_srcdir@/data/cstore_copy_t2.data' DELIMITER ',';
CREATE UNIQUE INDEX unsupport1_idx ON cstore_insert_t1(c1);
CREATE INDEX CONCURRENTLY unsupport2_idx ON cstore_insert_t1(c1);
CREATE INDEX unsupport3_idx ON cstore_insert_t1(lower(c2));
CREATE INDEX unsupport4_idx ON cstore_insert_t1(c1) where c1 > 1;
CREATE INDEX unsupport5_idx ON cstore_insert_t1(c2 NULLS FIRST);
CREATE INDEX unsupport6_idx ON cstore_insert_t1 USING hash (c1);
CREATE INDEX unsupport7_idx ON cstore_insert_t1 USING gist (c1);
CREATE INDEX unsupport9_idx ON cstore_insert_t1 USING spgist (c1);
CREATE INDEX unsupport10_idx ON cstore_insert_t1 USING btree (c1);
COPY cstore_insert_t1 FROM '@abs_srcdir@/data/cstore_copy_t2.data' DELIMITER ',';
DROP TABLE if exists cstore_insert_t1;

CREATE TABLE row_table(c1 int, c2 float, c3 text);
CREATE INDEX unsupport11_idx ON row_table USING psort (c1);
DROP TABLE if exists row_table;

-----------
---case 2: partition table create index test
-----------
CREATE TABLE LINEITEM
(
    L_ORDERKEY    BIGINT NOT NULL
  , L_PARTKEY     BIGINT NOT NULL
  , L_SUPPKEY     BIGINT NOT NULL
  , L_LINENUMBER  BIGINT NOT NULL
  , L_QUANTITY    DECIMAL(15,2) NOT NULL
  , L_EXTENDEDPRICE  DECIMAL(15,2) NOT NULL
  , L_DISCOUNT    DECIMAL(15,2) NOT NULL
  , L_TAX         DECIMAL(15,2) NOT NULL
  , L_RETURNFLAG  CHAR(1) NOT NULL
  , L_LINESTATUS  CHAR(1) NOT NULL
  , L_SHIPDATE    DATE NOT NULL
  , L_COMMITDATE  DATE NOT NULL
  , L_RECEIPTDATE DATE NOT NULL
  , L_SHIPINSTRUCT CHAR(25) NOT NULL
  , L_SHIPMODE     CHAR(10) NOT NULL
  , L_COMMENT      VARCHAR(44) NOT NULL
  --, primary key (L_ORDERKEY, L_LINENUMBER)
)
with (orientation = column)

PARTITION BY RANGE(L_SHIPDATE)
(
    PARTITION p1 VALUES LESS THAN('1993-01-01 00:00:00'),
    PARTITION p2 VALUES LESS THAN('1994-01-01 00:00:00'),
    PARTITION p3 VALUES LESS THAN('1995-01-01 00:00:00'),
        PARTITION p4 VALUES LESS THAN('1996-01-01 00:00:00'),
        PARTITION p5 VALUES LESS THAN('1997-01-01 00:00:00'),
        PARTITION p6 VALUES LESS THAN('1998-01-01 00:00:00'),
        PARTITION p7 VALUES LESS THAN('2030-01-01 00:00:00')
);
COPY LINEITEM FROM '@abs_srcdir@/data/lineitem_index.data' DELIMITER '|';
create index idx1 on lineitem(L_ORDERKEY) local;
create index idx2 on lineitem(L_PARTKEY) local;
create index idx3 on lineitem(L_LINENUMBER, L_SHIPDATE) local;
create index idx4 on lineitem(L_RETURNFLAG) local;
create index idx5 on lineitem(L_LINESTATUS, L_SHIPINSTRUCT) local;
COPY LINEITEM FROM '@abs_srcdir@/data/lineitem_index.data' DELIMITER '|';
set enable_bitmapscan=off;
set enable_seqscan=off;
select count(*) from lineitem where L_ORDERKEY > 100 and L_ORDERKEY < 200;
truncate table lineitem;
drop index if exists idx1;
drop index if exists idx2;
drop index if exists idx3;
drop index if exists idx4;
drop index if exists idx5;
drop table if exists lineitem;

----
--case 3:  check reserve column
----
CREATE TABLE check_column(id int, tid int) with (orientation = column);
CREATE TABLE check_column(id int, tid_test int, ti int) with (orientation = column);
ALTER TABLE check_column ADD COLUMN tid int;
drop table if exists check_column;

-----
--- case 6: truncate and delete cstore relation with index
-----
create table IDEX_PARTITION_TABLE_001(COL_INT int) with(orientation=column);
CREATE INDEX STORAGE_IDEX_PARTITION_IDEX_001 ON IDEX_PARTITION_TABLE_001(COL_INT);
insert into IDEX_PARTITION_TABLE_001 values(1000);
truncate table IDEX_PARTITION_TABLE_001;
select * from IDEX_PARTITION_TABLE_001;

insert into IDEX_PARTITION_TABLE_001 values(1000);
delete from IDEX_PARTITION_TABLE_001 where col_int=1000;
select * from IDEX_PARTITION_TABLE_001 where col_int=1000;

drop table if exists IDEX_PARTITION_TABLE_001;