Re: How can I make PostgreSQL to select another quey plan?

From: Yangyang <yangyangbm(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: How can I make PostgreSQL to select another quey plan?
Date: 2011-11-30 21:19:49
Message-ID: CAN3HncxdCAgoBxofuXkhmE26W80DQuLOCR4-du75+9L50g-jbA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Thank you for the advice, Tom.
My proposal is like this:
Suppose for the same query, Plan A consumes 10 units of I/O and 50
units of CPU. Plan B consumes 20 units of I/O and 40 units of CPU.
If A has less total cost than B, A will be selected as best plan.
If the database has less CPU available, I would prefer it to select
Plan B, which consumes less units of CPU.
I tried to limit the CPU to DB and modify cpu_tupe_cost, but no good.
I'm wondering if I need a particular query to do so.
The query I used is :
select
l_returnflag,
l_linestatus,
sum(l_quantity) as sum_qty,
sum(l_extendedprice) as sum_base_price,
sum(l_extendedprice * (1 - l_discount)) as sum_disc_price,
sum(l_extendedprice * (1 - l_discount) * (1 + l_tax)) as sum_charge,
avg(l_quantity) as avg_qty,
avg(l_extendedprice) as avg_price,
avg(l_discount) as avg_disc,
count(*) as count_order
from
lineitem
where
l_shipdate <= date('1998-12-01') - interval '90 days'
group by
l_returnflag,
l_linestatus
order by
l_returnflag,
l_linestatus;
Hope this time I made it clear.
I apologize for any inconvenience caused by my post.

On Wed, Nov 30, 2011 at 11:23 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Yangyang <yangyangbm(at)gmail(dot)com> writes:
>> If I don't change the database structures (like index), and only
>> modify "Planner cost constants", is it possible to make DB change the
>> query plan?
>
> Yes, but usually these don't have huge impacts on estimated costs,
> so you will only be able to get it to switch to plans that (it thinks)
> are relatively close in cost anyway.
>
> A bigger question is what sort of plan you think would be better, and
> whether the planner is even capable of building that plan from the
> given query.  You didn't show the particular query you're concerned
> about, but I gather from the EXPLAIN output that it involves
> sub-selects, and those can act as optimization fences ...
>
>                        regards, tom lane

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Tom Lane 2011-12-01 02:58:33 Re: How can I make PostgreSQL to select another quey plan?
Previous Message Tom Lane 2011-11-30 16:23:39 Re: How can I make PostgreSQL to select another quey plan?