Re: expression index not used within function - Mailing list pgsql-general

From LPlateAndy
Subject Re: expression index not used within function
Date
Msg-id 1384427583861-5778321.post@n5.nabble.com
Whole thread Raw
In response to Re: expression index not used within function  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: expression index not used within function
List 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.


pgsql-general by date:

Previous
From: LPlateAndy
Date:
Subject: Re: expression index not used within function
Next
From: "Janek Sendrowski"
Date:
Subject: Re: pg_trgm module: no convertion into Trigrams on one side when comparing