X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id AC86D565D9 for ; Fri, 11 Mar 2005 14:25:18 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 45161-06 for ; Fri, 11 Mar 2005 14:25:15 +0000 (GMT) Received: from floppy.pyrenet.fr (news.pyrenet.fr [194.250.190.2]) by svr1.postgresql.org (Postfix) with ESMTP id 51D0E565B7 for ; Fri, 11 Mar 2005 14:25:13 +0000 (GMT) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id AC32431E24; Fri, 11 Mar 2005 15:25:17 +0100 (MET) From: Daniel Schuchardt X-Newsgroups: pgsql.performance Subject: cpu_tuple_cost Date: Fri, 11 Mar 2005 15:25:29 +0100 Organization: Hub.Org Networking Services Lines: 68 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@news.hub.org User-Agent: Mozilla Thunderbird 0.8 (Windows/20040913) X-Accept-Language: en-us, en To: pgsql-performance@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.204 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200503/236 X-Sequence-Number: 10941 Hi List, i have a query plan who is bad with standard cpu_tuple_costs and good if I raise cpu_tuple_costs. Is it is a good practice to raise them if i want to force postgres to use indexes more often? Or is it is better to disable sequence scans? CIMSOFT=# ANALYSE mitpln; ANALYZE CIMSOFT=# EXPLAIN ANALYSE SELECT * FROM mitpln WHERE date_to_yearmonth_dec(mpl_date)='20050'; QUERY PLAN -------------------------------------------------------------------------------- Seq Scan on mitpln (cost=0.00..1411.85 rows=2050 width=69) (actual time=562.000..1203.000 rows=1269 loops=1) Filter: ((date_to_yearmonth_dec((mpl_date)::timestamp without time zone))::text = '20050'::text) Total runtime: 1203.000 ms (3 rows) CIMSOFT=# SET cpu_tuple_cost = 0.07; SET CIMSOFT=# EXPLAIN ANALYSE SELECT * FROM mitpln WHERE date_to_yearmonth_dec(mpl_date)='20050'; QUERY PLAN -------------------------------------------------------------------------------- Index Scan using mitpln_yearmonth_dec on mitpln (cost=0.00..2962.86 rows=2050width=69) (actual time=0.000..0.000 rows=1269 loops=1) Index Cond: ((date_to_yearmonth_dec((mpl_date)::timestamp without time zone))::text = '20050'::text) Total runtime: 16.000 ms (3 rows) CIMSOFT=# \d mitpln Table "public.mitpln" Column | Type | Modifiers --------------+-----------------------+----------------------------------------- mpl_id | integer | not null default nextval('public.mitpln_mpl_id_seq'::text) mpl_date | date | mpl_minr | integer | not null mpl_tpl_name | character varying(20) | mpl_feiertag | character varying(50) | mpl_min | real | mpl_saldo | real | mpl_buch | boolean | not null default false mpl_absaldo | real | mpl_vhz | real | dbrid | character varying | default nextval('db_id_seq'::text) Indexes: "mitpln_pkey" PRIMARY KEY, btree (mpl_id) "mitpln_idindex" UNIQUE, btree (dbrid) "xtt5126" UNIQUE, btree (mpl_date, mpl_minr) "mitpln_yearmonth_dec" btree (date_to_yearmonth_dec(mpl_date::timestamp with out time zone)) CIMSOFT=# SELECT count(*) FROM mitpln; count ------- 26128 (1 row)