--
-- ### Nested plan ( works from version 2.51.1 )  
-- 

drop if exists table teacher;
create table teacher ( primary tchid int not null,
  tchname string(20),
  gradeid int);

drop if exists table grade;
create table grade ( primary gradeid int not null,
  gradename string(20),
  cltid int);

drop if exists table clt;
create table clt ( primary cltid int not null,
  cltname string(20));

drop if exists view gradeview;
create view gradeview as
select
   g.gradeid as gradeid,
   g.gradename as gradename,
   c.cltname as cltname
from grade g
inner join clt c on g.cltid = c.cltid;

-- drop if exists view tchview;
-- create view tchview as
plan select
   t.tchid,
   t.tchname,
   gv.gradeid,
   gv.gradename
from teacher t
left outer join gradeview gv on t.gradeid = gv.gradeid;

-- plan select * from gradeview where gradeid = 1;

-- no index trace on gradeid, why ?
-- plan select * from tchview;

