【发布时间】:2017-04-03 08:16:33
【问题描述】:
我在为这个问题选择最佳索引时遇到了一些问题。给定一组查询:
-- 查询1
select CUSTOMERS.PID
from CUSTOMERS join
PARTICIP
on CUSTOMERS.PID = PARTICIP.PID
group by CUSTOMERS.PID
having COUNT(CUSTOMERS.PID) = 1;
-- 查询2
select CUSTOMERS.PID
from CUSTOMERS join
PARTICIP
on CUSTOMERS.PID = PARTICIP.PID
group by CUSTOMERS.PID
having COUNT(CUSTOMERS.PID) >= 2;
-- 查询 3
select hasa.pid,strno as "Street #", street, city, prov as Province
from ((addresses join hasa on hasa.addrid = addresses.addrid) join
customers
on customers.pid = hasa.pid
)
order by city;
-- 查询 4
select *
from guides
where pid in (select pid
from particip
where tid in (select unique tid
from itineraries
where date >= '2015-01-01' and date <= '2015-12-31'));
-- 查询 5
select age, gender
from persons
where persons.pid in (select hase.pid
from hase
where hase.pid in (select * from employees));
-- 查询 6
select provid
from isp
where provid NOT in (select provid as service
from isp
group by provid, svctype
having svctype = 'ACCOM');
-- 查询 7
select provid
from isp
where provid in (select provid
from isp
where ((svctype != 'ACCOM' and svctype = 'MEAL')
or (svctype = 'ACCOM' and svctype != 'MEAL'))
group by provid
having count(unique svctype) = 1);
-- 查询 8
select unique provid, svctype
from isp
where penalty = 100 or penalty = 200;
-- 查询 9
select pid, sum(amount) as "totalSalary", count(pid) as "numTours"
from hasco
group by pid
order by sum(amount) desc;
-- 查询 10
select distinct hasco.TID
from hasco
join (select *
from tours
where status = 'I' OR status = 'F') as table1 on hasco.tid = table1.tid
where amount >= 5000;
terminate;
和ER图: ER Diagram
我的任务是选择两个属性来索引,这将提供最大的好处。没有提及任何数量的查询或对表的修改。谢谢。
编辑:我只需要一两个属性来索引,并在其背后进行一些推理来帮助理解。
另外,非集群比集群更好吗?谢谢。
【问题讨论】:
-
我开始了,但您应该尝试格式化问题以便阅读。
-
现在正在尝试这样做,对不起。
-
非常感谢您帮助格式化它!