
delete from /ootest/test/basic/extend with version
-- { onerror(continue) }
;
delete from /ootest/test/basic with version
-- { onerror(continue) }
;
delete from /ootest/test with version
-- { onerror(continue) }
;
delete from /ootest with version
-- { onerror(continue) }
;

drop class if exists /ootest/test/basic/extend
-- { sleep(1s) }
;
drop class if exists /ootest/test/basic
-- { sleep(1s) }
;
drop class if exists /ootest/test
-- { sleep(1s) }
;
drop class if exists /ootest
-- { onerror(continue) sleep(1s) }
;

create class if not exists /ootest()
-- { sleep(1s) schema(/ootest) retry(3) }
;
create class if not exists /ootest/test(
    xid               int         "id",
    xcode             varchar     "code",
    xkey              varchar     "key",
    xextend           text        "",
    vtime             timestamp   "vtime",
    keys(xid),
    indexes(xid,xcode,xkey)
)
-- { sleep(1s) schema(/ootest/test) retry(3) }
;
create class if not exists /ootest/test/basic()
-- { sleep(1s) schema(/ootest/test/basic) retry(3) }
;
create class if not exists /ootest/test/basic/extend()
-- { sleep(1s) schema(/ootest/test/basic/extend) retry(3) }
;

alter class /ootest/test/basic/extend add index column 
    z0000name  varchar 'name',
    z0000desc  varchar 'desc',
    z0000type  varchar 'type'
-- { sleep(1s) }
;

insert into /ootest/test/basic/extend (xid,xcode,xkey,z0000name,z0000desc,z0000type,xextend)
values (10000,'10000','10000.10000','10000','10000','xxxx','...128 Bytes...')
;
insert into /ootest/test/basic/extend (xid,xcode,xkey,z0000name,z0000desc,z0000type,xextend)
values (20000,'20000','20000.20000','20000','20000','yyyy','...128 Bytes...')
;
insert into /ootest/test/basic/extend (xid,xcode,xkey,z0000name,z0000desc,z0000type,xextend)
values (30000,'30000','30000.30000','30000','30000','xxxx','...128 Bytes...')
;
insert into /ootest/test/basic/extend (xid,xcode,xkey,z0000name,z0000desc,z0000type,xextend)
values (40000,'40000','40000.40000','40000','40000','xxxx','...128 Bytes...')
;

select * from /ootest/test/basic/extend refresh
-- { output() count(4) }
;
select * from /ootest/test/basic/extend where xid=10000 refresh
-- { output() count(1) equal(0,z0000type,xxxx) }
;
select * from /ootest/test/basic/extend where xcode='10000' refresh
-- { output() count(1) equal(0,z0000type,xxxx) }
;
select * from /ootest/test/basic/extend where z0000type='xxxx' refresh
-- { output() count(3) }
;
select * from /ootest/test/basic/extend where z0000type='yyyy' refresh
-- { output() count(1) }
;
select * from /ootest/test/basic/extend where z0000type=null refresh
-- { output() count(0) }
;
select * from /ootest/test/basic/extend order by xcode refresh
-- { output() count(4) equal(2,z0000type,xxxx) }
;

select xcode,vtime from /ootest/test/basic/extend order by vtime desc refresh
-- { output() count(4) sleep(10s) equal(0,xcode,40000) }
;
