16aef5e48fc307ca82ff0f92bd29a500d0598952
[plantuner.git] / README.plantuner
1 Plantuner - enable planner hints
2
3 contrib/plantuner is a contribution module for PostgreSQL 8.4+, which enable 
4 planner hints.
5
6 All work was done by Teodor Sigaev (teodor@sigaev.ru) and 
7  Oleg Bartunov (oleg@sai.msu.su).
8
9 Sponsor: JFG Networks (www.jfg-networks.net)
10 Motivation
11
12 It's very interesting to be able to control planner (provide hints), which is 
13 currently impossible. This first version of plantuner provides a possibility to
14 hide specified indexes from PostgreSQL planner, so it will not use them.
15
16 There are many situation, when developer want to temporarily disable specific 
17 index(es), without dropping them, or to instruct planner to use specific index.
18 Installation
19
20     * Get latest source of plantuner from CVS Repository
21     * gmake && gmake install && gmake installcheck
22
23 Usage
24
25 To enable the module you can either load shared library 'plantuner' in psql 
26 session or specify 'shared_preload_libraries' option in postgresql.conf.
27
28 =# LOAD 'plantuner';
29 =# create table test(id int);
30 =# create index id_idx on test(id);
31 =# create index id_idx2 on test(id);
32 =# \d test
33      Table "public.test"
34  Column |  Type   | Modifiers
35 --------+---------+-----------
36  id     | integer |
37 Indexes:
38     "id_idx" btree (id)
39     "id_idx2" btree (id)
40 =# explain select id from test where id=1;
41                               QUERY PLAN
42 -----------------------------------------------------------------------
43  Bitmap Heap Scan on test  (cost=4.34..15.03 rows=12 width=4)
44    Recheck Cond: (id = 1)
45    ->  Bitmap Index Scan on id_idx2  (cost=0.00..4.34 rows=12 width=0)
46          Index Cond: (id = 1)
47 (4 rows)
48 =# set enable_seqscan=off;
49 =# set plantuner.forbid_index='id_idx2';
50 =# explain select id from test where id=1;
51                               QUERY PLAN
52 ----------------------------------------------------------------------
53  Bitmap Heap Scan on test  (cost=4.34..15.03 rows=12 width=4)
54    Recheck Cond: (id = 1)
55    ->  Bitmap Index Scan on id_idx  (cost=0.00..4.34 rows=12 width=0)
56          Index Cond: (id = 1)
57 (4 rows)
58 =# set plantuner.forbid_index='id_idx2,id_idx';
59 =# explain select id from test where id=1;
60                                QUERY PLAN
61 -------------------------------------------------------------------------
62  Seq Scan on test  (cost=10000000000.00..10000000040.00 rows=12 width=4)
63    Filter: (id = 1)
64 (2 rows)
65