Re: expression index not used within function

From: LPlateAndy <andy(at)centremaps(dot)co(dot)uk>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: expression index not used within function
Date: 2013-11-14 11:13:03
Message-ID: 1384427583861-5778321.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Thanks Tom. I'll try the "EXECUTE" method as well but my dev environment is
9.2 and the planner doesn't seem to be including the index so following are
the fairly basic table/index/function details. Thanks, Andy:

================================
TABLE (circa 300,000 rows):
================================

CREATE TABLE postcode
(
gid serial NOT NULL,
pcode text,
e integer,
n integer,
geometry geometry(Geometry,27700),
CONSTRAINT postcode_pkey PRIMARY KEY (gid)
)
WITH (
OIDS=FALSE
);
ALTER TABLE postcode
OWNER TO postgres;

================================
TABLE INDEX:
================================

CREATE INDEX idx_postcode_lc_pcode
ON postcode
USING btree
(replace(lower(pcode), ' '::text, ''::text) COLLATE pg_catalog."default"
text_pattern_ops);

================================
SELECT FUNCTION:
================================

CREATE OR REPLACE FUNCTION _search_pcode(IN text)
RETURNS TABLE(searchmatch text, geometry geometry) AS
$BODY$
SELECT pcode searchmatch, geometry FROM postcode
WHERE (replace(lower(pcode), ' '::text, ''::text)) LIKE
(replace((lower($1)::text),' '::text,''::text)||'%'::text)
LIMIT 20;

$BODY$
LANGUAGE sql IMMUTABLE SECURITY DEFINER
COST 100
ROWS 1000;
ALTER FUNCTION _search_pcode(text)
OWNER TO postgres;
GRANT EXECUTE ON FUNCTION _search_pcode(text) TO public;
GRANT EXECUTE ON FUNCTION _search_pcode(text) TO postgres;

--
View this message in context: http://postgresql.1045698.n5.nabble.com/expression-index-not-used-within-function-tp5778236p5778321.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Janek Sendrowski 2013-11-14 12:05:48 Re: pg_trgm module: no convertion into Trigrams on one side when comparing
Previous Message LPlateAndy 2013-11-14 10:59:49 Re: expression index not used within function