Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id A7FA7189E83A for ; Tue, 10 Apr 2012 11:43:24 -0300 (ADT) Received: from mahout.postgresql.org ([98.129.198.123]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SHcHw-0000fk-DJ for pgsql-bugs@postgresql.org; Tue, 10 Apr 2012 14:43:24 +0000 Received: from [204.145.124.246] (helo=wrigleys.postgresql.org) by mahout.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SHcHj-0005WR-UR for pgsql-bugs@postgresql.org; Tue, 10 Apr 2012 14:43:08 +0000 Received: from www-data by wrigleys.postgresql.org with local (Exim 4.72) (envelope-from ) id 1SHcHj-000451-IT for pgsql-bugs@postgresql.org; Tue, 10 Apr 2012 14:43:07 +0000 Date: Tue, 10 Apr 2012 14:43:07 +0000 Message-Id: Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #6579: negative cost in a planning To: pgsql-bugs@postgresql.org From: istvan.endredy@gmail.com X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201204/59 X-Sequence-Number: 32810 The following bug has been logged on the website: Bug reference: 6579 Logged by: Istvan Endredy Email address: istvan.endredy@gmail.com PostgreSQL version: 9.1.3 Operating system: linux Description: = Hi, I've reduced the problem to this situation: = there is a table with 3000 rows, and a custom index with a function. This query gives negative cost: select distinct name from negativeCostBugReport t_ = where noaccent(t_.name) like 'B%' limit 10 plan: Limit (cost=3D-170.35..-170.31 rows=3D4 width=3D2) (actual time=3D17.399..= 17.401 rows=3D1 loops=3D1) -> HashAggregate (cost=3D-170.35..-170.31 rows=3D4 width=3D2) (actual time=3D17.397..17.398 rows=3D1 loops=3D1) -> Index Scan using negativecostbugreport_noaccent_idx on negativecostbugreport t_ (cost=3D1.25..-171.22 rows=3D346 width=3D2) (actu= al time=3D0.240..16.852 rows=3D346 loops=3D1) Index Cond: (((noaccent(name))::text >=3D 'B'::text) AND ((noaccent(name))::text < 'C'::text)) Filter: ((noaccent(name))::text ~~ 'B%'::text) Total runtime: 17.450 ms (sorry, but http://explain.depesz.com/ cannot parse this) schema: = CREATE TABLE negativecostbugreport ( id integer NOT NULL DEFAULT nextval('product_parent_id_seq'::regclass), name character varying NOT NULL, CONSTRAINT negativecostbugreport_pkey PRIMARY KEY (id ) ); CREATE INDEX negativecostbugreport_noaccent_idx ON negativecostbugreport USING btree (noaccent(name) COLLATE pg_catalog."C" ); CREATE OR REPLACE FUNCTION noaccent(character varying) RETURNS character varying AS $BODY$select to_ascii(convert_to($1, 'latin2'), 'latin2')$BODY$ LANGUAGE sql IMMUTABLE STRICT COST 250; CREATE OR REPLACE FUNCTION to_ascii(bytea, name) RETURNS text AS 'to_ascii_encname' LANGUAGE internal VOLATILE COST 1; If you need any further details, feel free to ask. Thanks for your work! :) Best Regards, Istvan