pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: istvan.endredy@gmail.com
To: pgsql-bugs@postgresql.org
Subject: BUG #6579: negative cost in a planning
Date: Tue, 10 Apr 2012 14:43:07 +0000
Message-ID: <E1SHcHj-000451-IT@wrigleys.postgresql.org> (raw)

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=-170.35..-170.31 rows=4 width=2) (actual time=17.399..17.401
rows=1 loops=1)
  ->  HashAggregate  (cost=-170.35..-170.31 rows=4 width=2) (actual
time=17.397..17.398 rows=1 loops=1)
        ->  Index Scan using negativecostbugreport_noaccent_idx on
negativecostbugreport t_  (cost=1.25..-171.22 rows=346 width=2) (actual
time=0.240..16.852 rows=346 loops=1)
              Index Cond: (((noaccent(name))::text >= '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




view thread (3+ messages)  latest in thread

Message-ID: <E1SHcHj-000451-IT@wrigleys.postgresql.org>
Permalink:  ../E1SHcHj-000451-IT@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/E1SHcHj-000451-IT@wrigleys.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: istvan.endredy@gmail.com
  Subject: Re: BUG #6579: negative cost in a planning
  In-Reply-To: <E1SHcHj-000451-IT@wrigleys.postgresql.org>
  References: <E1SHcHj-000451-IT@wrigleys.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox