fix empty table now suggest 1 page instead of 0 for empty table - zero causes unwilli...
[plantuner.git] / README.plantuner
1 Plantuner - enable planner hints
2
3    contrib/plantuner is a contribution module for PostgreSQL 8.4+, which
4    enable planner hints.
5
6    All work was done by Teodor Sigaev (teodor@sigaev.ru) and Oleg Bartunov
7    (oleg@sai.msu.su).
8
9    Sponsor: Nomao project (http://www.nomao.com)
10
11 Motivation
12
13    Whether somebody think it's bad or not, but sometime it's very
14    interesting to be able to control planner (provide hints, which tells
15    optimizer to ignore its algorithm in part), which is currently
16    impossible in POstgreSQL. Oracle, for example, has over 120 hints, SQL
17    Server also provides hints.
18
19    This first version of plantuner provides a possibility to hide
20    specified indexes from PostgreSQL planner, so it will not use them.
21
22    There are many situation, when developer want to temporarily disable
23    specific index(es), without dropping them, or to instruct planner to
24    use specific index.
25
26    Next, for some workload PostgreSQL could be too pessimistic for
27    newly created tables and assumes much more rows in table than
28    it actually has. If plantuner.fix_empty_table GUC variable is set
29    to true then module will set to zero number of pages/tuples of
30    table which hasn't blocks in file.
31
32 Installation
33
34      * Get latest source of plantuner from CVS Repository
35      * gmake && gmake install && gmake installcheck
36
37 Syntax
38         plantuner.forbid_index (deprecated)
39         plantuner.disable_index
40                 List of indexes invisible to planner
41         plantuner.enable_index
42                 List of indexes visible to planner even they are hided
43                 by plantuner.disable_index. 
44
45 Usage
46
47    To enable the module you can either load shared library 'plantuner' in
48    psql session or specify 'shared_preload_libraries' option in
49    postgresql.conf.
50 =# LOAD 'plantuner';
51 =# create table test(id int);
52 =# create index id_idx on test(id);
53 =# create index id_idx2 on test(id);
54 =# \d test
55      Table "public.test"
56  Column |  Type   | Modifiers
57 --------+---------+-----------
58  id     | integer |
59 Indexes:
60     "id_idx" btree (id)
61     "id_idx2" btree (id)
62 =# explain select id from test where id=1;
63                               QUERY PLAN
64 -----------------------------------------------------------------------
65  Bitmap Heap Scan on test  (cost=4.34..15.03 rows=12 width=4)
66    Recheck Cond: (id = 1)
67    ->  Bitmap Index Scan on id_idx2  (cost=0.00..4.34 rows=12 width=0)
68          Index Cond: (id = 1)
69 (4 rows)
70 =# set enable_seqscan=off;
71 =# set plantuner.disable_index='id_idx2';
72 =# explain select id from test where id=1;
73                               QUERY PLAN
74 ----------------------------------------------------------------------
75  Bitmap Heap Scan on test  (cost=4.34..15.03 rows=12 width=4)
76    Recheck Cond: (id = 1)
77    ->  Bitmap Index Scan on id_idx  (cost=0.00..4.34 rows=12 width=0)
78          Index Cond: (id = 1)
79 (4 rows)
80 =# set plantuner.disable_index='id_idx2,id_idx';
81 =# explain select id from test where id=1;
82                                QUERY PLAN
83 -------------------------------------------------------------------------
84  Seq Scan on test  (cost=10000000000.00..10000000040.00 rows=12 width=4)
85    Filter: (id = 1)
86 (2 rows)
87 =# set plantuner.enable_index='id_idx';
88 =# explain select id from test where id=1;
89                               QUERY PLAN
90 -----------------------------------------------------------------------
91  Bitmap Heap Scan on test  (cost=4.34..15.03 rows=12 width=4)
92    Recheck Cond: (id = 1)
93    ->  Bitmap Index Scan on id_idx  (cost=0.00..4.34 rows=12 width=0)
94          Index Cond: (id = 1)
95 (4 rows)
96