我有一个包含大约1500万条目的数据库。
这是它的结构:
SELECT count(*) FROM hash.list; ~ 77 seconds
SELECT * FROM hash.list where plain = "aaaa"; ~~ 94 seconds
我怎样才能让这个更快〜5秒或者其他什么?
答案 0 :(得分:1)
你可以做以下事情来加快速度 好的,我想你已经做到了 2.对此表进行分区,仅获取符合条件的记录。 3.同时选择解释以获取查询中大部分时间的内容。
答案 1 :(得分:0)
一些建议:
with your_table (name, priority, country, somedata) as (
select 'Paul', 1, 'USA', 456 from dual
union all select 'Paul', 2, 'England', 7898 from dual
union all select 'Paul', 3, 'Austria', 56 from dual
union all select 'Fred', 2, 'Belgium', 156 from dual
union all select 'Fred', 4, 'France', 8979 from dual
union all select 'Carl', 3, 'Canada', 569 from dual
union all select 'Jane', 1, 'Peru', 69 from dual
)
select name,
min(priority) as priority,
min(country) keep (dense_rank first order by priority) as country,
min(somedata) keep (dense_rank first order by priority) as somedata
from your_table
group by name;
NAME PRIORITY COUNTRY SOMEDATA
---- ---------- ------- ----------
Carl 3 Canada 569
Fred 2 Belgium 156
Jane 1 Peru 69
Paul 1 USA 456
列。