blob: 56e56de27a8d226d0b3151c3908f61d90d8a486a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
create language plpgsql;
drop schema if exists test cascade;
drop user if exists test;
create user test;
create schema test authorization test;
\c postgres test
load '$libdir/plugins/index_adviser';
drop view if exists select_index_advisory;
drop function if exists show_index_advisory(index_advisory.backend_pid%type);
drop table if exists index_advisory;
\i contrib/pgadviser/resources/index_advisory.create.sql
\i contrib/pgadviser/resources/show_index_advisory.create.sql
\i contrib/pgadviser/resources/select_index_advisory.create.sql
drop table if exists t, t1;
create table t( a int, b int );
insert into t select s, 99999-s from generate_series(0,99999) as s;
analyze t;
create table t1 as select * from t;
/* notice no ANALYZE for T1 */;
select count(*) from t;
select count(*) from t1;
/* stop here if you wish to run only pg_advise tool */;
/* set the client to see the log messages generated by the Adviser */;
set client_min_messages to log;
explain select * from t where a = 100;
explain select * from t where b = 100;
explain select * from t where a = 100 and b = 100;
explain select * from t where a = 100 or b = 100;
/* now we shall test with T1 */;
explain select * from t1 where a = 100;
explain select * from t1 where b = 100;
explain select * from t1 where a = 100 and b = 100;
explain select * from t1 where a = 100 or b = 100;
/* let's do some sensible join over these two tables */;
explain
select *
from t,
t1
where t.a = 100
and t1.a = 100
or t.b = 100
and t1.b = 100;
/* following are the contents of the advise_index table */;
select * from index_advisory;
/* And following is the summary of the advices generated */;
select * from select_index_advisory;
|