Add scripts to enable/disable use of new LIKE/regexp selectivity
estimation operators. See contrib/likeplanning/README for info.
This commit is contained in:
parent
ea46ddcfa6
commit
bfabd4f052
@ -35,6 +35,12 @@ isbn_issn -
|
|||||||
PostgreSQL type extensions for ISBN (books) and ISSN (serials)
|
PostgreSQL type extensions for ISBN (books) and ISSN (serials)
|
||||||
by Garrett A. Wollman <wollman@khavrinen.lcs.mit.edu>
|
by Garrett A. Wollman <wollman@khavrinen.lcs.mit.edu>
|
||||||
|
|
||||||
|
likeplanning -
|
||||||
|
Scripts to enable/disable new planning code for LIKE and regexp
|
||||||
|
pattern match operators. These will go away again once the code
|
||||||
|
is mature enough to enable by default.
|
||||||
|
by Tom Lane <tgl@sss.pgh.pa.us>
|
||||||
|
|
||||||
linux -
|
linux -
|
||||||
Start postgres back end system
|
Start postgres back end system
|
||||||
by Thomas Lockhart <lockhart@alumni.caltech.edu>
|
by Thomas Lockhart <lockhart@alumni.caltech.edu>
|
||||||
|
51
contrib/likeplanning/README
Normal file
51
contrib/likeplanning/README
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
This directory contains three SQL scripts that control use of some new
|
||||||
|
code for planning/optimizing queries containing LIKE and
|
||||||
|
regular-expression operators. This code was added to Postgres 7.0 late in
|
||||||
|
beta test, and it hasn't gotten enough testing to warrant turning it on by
|
||||||
|
default in release 7.0 (although it probably will become default in 7.1).
|
||||||
|
So, here are some scripts to enable and disable it. You may want to run
|
||||||
|
these scripts if you have problems with the planner choosing bad plans for
|
||||||
|
queries involving LIKE or regexps in WHERE clauses.
|
||||||
|
|
||||||
|
|
||||||
|
HOW TO USE THE SCRIPTS
|
||||||
|
----------------------
|
||||||
|
|
||||||
|
All three scripts must be run as the Postgres superuser. The easiest
|
||||||
|
way to run an SQL script is
|
||||||
|
psql -f scriptfile databasename
|
||||||
|
or you can start psql interactively and enter
|
||||||
|
\i scriptfile
|
||||||
|
|
||||||
|
enablelike.sql enables use of the new planning code in the database in
|
||||||
|
which it is run. If you run it in template1, all subsequently-created
|
||||||
|
databases will use the new code by default.
|
||||||
|
|
||||||
|
disablelike.sql reverts to the old planning code for LIKE, in the database
|
||||||
|
in which it is run. If you run it in template1, all subsequently-created
|
||||||
|
databases will use the old code by default.
|
||||||
|
|
||||||
|
If your database was initdb'd with release 7.0beta5, you need to run
|
||||||
|
updatepgproc.sql before you can run enablelike.sql. Databases initdb'd
|
||||||
|
with 7.0RC1 or later already have pg_proc entries for the new code, so
|
||||||
|
updatepgproc.sql is unnecessary for them. If enablelike.sql produces
|
||||||
|
errors like "No procedure with name regexeqsel", then you need to run
|
||||||
|
updatepgproc.sql.
|
||||||
|
|
||||||
|
|
||||||
|
WHAT IT DOES
|
||||||
|
------------
|
||||||
|
|
||||||
|
These scripts install (or disable) new code for "selectivity estimation"
|
||||||
|
of LIKE and regexp operators. Selectivity estimation determines the
|
||||||
|
estimated number of rows produced by a query or subquery, and that in turn
|
||||||
|
determines the kind of plan the planner will use. The old selectivity
|
||||||
|
estimator ignored the pattern being searched for and just produced the
|
||||||
|
same estimate as for an "=" operator, which of course was usually too low
|
||||||
|
for a wildcard match. The new code has some knowledge of pattern matching
|
||||||
|
rules and generates an estimate based on the number of fixed characters and
|
||||||
|
wildcards present in the pattern. Also, if the pattern has a fixed prefix
|
||||||
|
that must be matched (such as LIKE 'foo%' or ~ '^foo'), an appropriate
|
||||||
|
range-query selectivity estimate is produced and factored into the result.
|
||||||
|
|
||||||
|
If you want to look at the code itself, see src/backend/utils/adt/selfuncs.c.
|
39
contrib/likeplanning/disablelike.sql
Normal file
39
contrib/likeplanning/disablelike.sql
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
-- This script disables use of the new LIKE-related selectivity estimation
|
||||||
|
-- functions, which are a little too new to be enabled by default in 7.0.
|
||||||
|
-- You can enable them again by running enablelike.sql.
|
||||||
|
|
||||||
|
-- Use of the functions will be disabled only in those databases you
|
||||||
|
-- run this script in. If you run it in template1,
|
||||||
|
-- all subsequently-created databases will not use the functions.
|
||||||
|
|
||||||
|
-- Be sure to run the script as the Postgres superuser!
|
||||||
|
|
||||||
|
UPDATE pg_operator SET
|
||||||
|
oprrest = 'eqsel'::regproc,
|
||||||
|
oprjoin = 'eqjoinsel'::regproc
|
||||||
|
WHERE oprrest = 'regexeqsel'::regproc;
|
||||||
|
|
||||||
|
UPDATE pg_operator SET
|
||||||
|
oprrest = 'eqsel'::regproc,
|
||||||
|
oprjoin = 'eqjoinsel'::regproc
|
||||||
|
WHERE oprrest = 'icregexeqsel'::regproc;
|
||||||
|
|
||||||
|
UPDATE pg_operator SET
|
||||||
|
oprrest = 'eqsel'::regproc,
|
||||||
|
oprjoin = 'eqjoinsel'::regproc
|
||||||
|
WHERE oprrest = 'likesel'::regproc;
|
||||||
|
|
||||||
|
UPDATE pg_operator SET
|
||||||
|
oprrest = 'neqsel'::regproc,
|
||||||
|
oprjoin = 'neqjoinsel'::regproc
|
||||||
|
WHERE oprrest = 'regexnesel'::regproc;
|
||||||
|
|
||||||
|
UPDATE pg_operator SET
|
||||||
|
oprrest = 'neqsel'::regproc,
|
||||||
|
oprjoin = 'neqjoinsel'::regproc
|
||||||
|
WHERE oprrest = 'icregexnesel'::regproc;
|
||||||
|
|
||||||
|
UPDATE pg_operator SET
|
||||||
|
oprrest = 'neqsel'::regproc,
|
||||||
|
oprjoin = 'neqjoinsel'::regproc
|
||||||
|
WHERE oprrest = 'nlikesel'::regproc;
|
43
contrib/likeplanning/enablelike.sql
Normal file
43
contrib/likeplanning/enablelike.sql
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
-- This script enables use of the new LIKE-related selectivity estimation
|
||||||
|
-- functions, which are a little too new to be enabled by default in 7.0.
|
||||||
|
-- You can disable them again by running disablelike.sql.
|
||||||
|
|
||||||
|
-- If your database was initdb'd with 7.0beta5, you need to run
|
||||||
|
-- updatepgproc.sql first. You can tell that is necessary if this
|
||||||
|
-- script produces errors like "No procedure with name regexeqsel".
|
||||||
|
|
||||||
|
-- Use of the functions will be enabled only in those databases you
|
||||||
|
-- run this script in. If you run it in template1,
|
||||||
|
-- all subsequently-created databases will use the functions.
|
||||||
|
|
||||||
|
-- Be sure to run the script as the Postgres superuser!
|
||||||
|
|
||||||
|
UPDATE pg_operator SET
|
||||||
|
oprrest = 'regexeqsel'::regproc,
|
||||||
|
oprjoin = 'regexeqjoinsel'::regproc
|
||||||
|
WHERE oprrest = 'eqsel'::regproc AND oprname = '~';
|
||||||
|
|
||||||
|
UPDATE pg_operator SET
|
||||||
|
oprrest = 'icregexeqsel'::regproc,
|
||||||
|
oprjoin = 'icregexeqjoinsel'::regproc
|
||||||
|
WHERE oprrest = 'eqsel'::regproc AND oprname = '~*';
|
||||||
|
|
||||||
|
UPDATE pg_operator SET
|
||||||
|
oprrest = 'likesel'::regproc,
|
||||||
|
oprjoin = 'likejoinsel'::regproc
|
||||||
|
WHERE oprrest = 'eqsel'::regproc AND oprname = '~~';
|
||||||
|
|
||||||
|
UPDATE pg_operator SET
|
||||||
|
oprrest = 'regexnesel'::regproc,
|
||||||
|
oprjoin = 'regexnejoinsel'::regproc
|
||||||
|
WHERE oprrest = 'neqsel'::regproc AND oprname = '!~';
|
||||||
|
|
||||||
|
UPDATE pg_operator SET
|
||||||
|
oprrest = 'icregexnesel'::regproc,
|
||||||
|
oprjoin = 'icregexnejoinsel'::regproc
|
||||||
|
WHERE oprrest = 'neqsel'::regproc AND oprname = '!~*';
|
||||||
|
|
||||||
|
UPDATE pg_operator SET
|
||||||
|
oprrest = 'nlikesel'::regproc,
|
||||||
|
oprjoin = 'nlikejoinsel'::regproc
|
||||||
|
WHERE oprrest = 'neqsel'::regproc AND oprname = '!~~';
|
25
contrib/likeplanning/updatepgproc.sql
Normal file
25
contrib/likeplanning/updatepgproc.sql
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
-- This script loads pg_proc entries for the 7.0 selectivity estimation
|
||||||
|
-- functions into a 7.0beta5 database. You should not run it if you
|
||||||
|
-- initdb'd with 7.0RC1 or later. If you do need it, run it in each
|
||||||
|
-- database you have, including template1. Once you have run it in
|
||||||
|
-- template1, all subsequently-created databases will contain the entries,
|
||||||
|
-- so you won't need to run it again.
|
||||||
|
-- Be sure to run the script as the Postgres superuser!
|
||||||
|
|
||||||
|
COPY pg_proc WITH OIDS FROM stdin;
|
||||||
|
1818 regexeqsel 0 11 f t f 5 f 701 26 26 21 0 23 100 0 0 100 regexeqsel -
|
||||||
|
1819 likesel 0 11 f t f 5 f 701 26 26 21 0 23 100 0 0 100 likesel -
|
||||||
|
1820 icregexeqsel 0 11 f t f 5 f 701 26 26 21 0 23 100 0 0 100 icregexeqsel -
|
||||||
|
1821 regexnesel 0 11 f t f 5 f 701 26 26 21 0 23 100 0 0 100 regexnesel -
|
||||||
|
1822 nlikesel 0 11 f t f 5 f 701 26 26 21 0 23 100 0 0 100 nlikesel -
|
||||||
|
1823 icregexnesel 0 11 f t f 5 f 701 26 26 21 0 23 100 0 0 100 icregexnesel -
|
||||||
|
1824 regexeqjoinsel 0 11 f t f 5 f 701 26 26 21 26 21 100 0 0 100 regexeqjoinsel -
|
||||||
|
1825 likejoinsel 0 11 f t f 5 f 701 26 26 21 26 21 100 0 0 100 likejoinsel -
|
||||||
|
1826 icregexeqjoinsel 0 11 f t f 5 f 701 26 26 21 26 21 100 0 0 100 icregexeqjoinsel -
|
||||||
|
1827 regexnejoinsel 0 11 f t f 5 f 701 26 26 21 26 21 100 0 0 100 regexnejoinsel -
|
||||||
|
1828 nlikejoinsel 0 11 f t f 5 f 701 26 26 21 26 21 100 0 0 100 nlikejoinsel -
|
||||||
|
1829 icregexnejoinsel 0 11 f t f 5 f 701 26 26 21 26 21 100 0 0 100 icregexnejoinsel -
|
||||||
|
\.
|
||||||
|
|
||||||
|
UPDATE pg_proc SET proowner = pg_shadow.usesysid
|
||||||
|
WHERE oid >= 1818 AND oid <= 1829 AND pg_shadow.usename = CURRENT_USER;
|
Loading…
x
Reference in New Issue
Block a user