在PostgreSQL上对SDB内的两个集合进行关联(JOIN)查询。要求如下: 1.为两个集合在PG内创建两张外表; 2.查看创建的两张外表的表结构; 3.JOIN关联查询需要走索引;
进入环境
bin/psql -p 5432 foo
创建外表fstudent
create foreign table fstudent ( sid int, sname text, sage int, ssex int, cid int, prvn_nam text, city_nam text, phone int, email text ) server sdb_server options ( collectionspace 'mytest', collection 'student', decimal 'on' ) ;
创建外表fclass
create foreign table fclass ( cid int, cname text, avgChinese int, avgMath int, avgsEnglish int, avgsBiology int, avgsChemistry int, avgsPhysics int ) server sdb_server options ( collectionspace 'mytest', collection 'class3', decimal 'on' ) ;
查看两张外表的表结构
查看外表fstudent结构
foo=# \d fstudent;
查看外表fclass结构
foo=# \d fclass;
创建索引
sdb var db = new Sdb(); db.execUpdate("create index student_index1 on mytest.student (cid)");
join关联查询
select sid,fstudent.sname,ssex,sage,city_nam,cname from fstudent inner join fclass on fstudent.cid =fclass.cid limit 10;