pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: kes-kes@yandex.ru
Subject: BUG #16968: Planner does not recognize optimization
Date: Fri, 16 Apr 2021 19:18:45 +0000
Message-ID: <16968-9c8a1708c1c04355@postgresql.org> (raw)

The following bug has been logged on the website:

Bug reference:      16968
Logged by:          Eugen Konkov
Email address:      kes-kes@yandex.ru
PostgreSQL version: 13.1
Operating system:   Linux Mint 19.3
Description:        

TLDR;
If I refer to same column by different ways planner may or may not recognize
optimization

select * from order_total_suma() ots where agreement_id = 3943;            
-- fast
select * from order_total_suma() ots where (ots.o).agreement_id = 3943;  --
slow

Where `order_total_suma` is sql function:

		SELECT
		 sum( ocd.item_suma     ) OVER( PARTITION BY (ocd.o).agreement_id         
       ) AS agreement_suma,
		 sum( ocd.item_suma     ) OVER( PARTITION BY (ocd.o).agreement_id,
(ocd.o).id                           ) AS order_suma,
		 sum( ocd.item_cost     ) OVER( PARTITION BY (ocd.o).agreement_id,
(ocd.o).id, (ocd.ic).consumed_period ) AS group_cost,
		 sum( ocd.item_suma     ) OVER( PARTITION BY (ocd.o).agreement_id,
(ocd.o).id, (ocd.ic).consumed_period ) AS group_suma,
		 max( (ocd.ic).consumed ) OVER( PARTITION BY (ocd.o).agreement_id,
(ocd.o).id, (ocd.ic).consumed_period ) AS consumed,
		 ocd.item_qty, ocd.item_price, ocd.item_cost, ocd.item_suma,
		 ocd.o, ocd.c, ocd.p, ocd.ic,
		 (ocd.o).id as order_id,
		 (ocd.o).agreement_id as agreement_id
		FROM order_cost_details( _target_range ) ocd

Problem is window function, because ID can not go through. But this occur
not always.
When I filter by field I partition result by then optimization occur 
BUT only when I create an alias for this field and do filtering via this
alias.

Expected: apply optimization not only when I do `WHERE agreement_id = XXX`

but and for `WHERE (ots.o).agreement_id = XXX`

Thank you.



view thread (10+ messages)  latest in thread

Message-ID: <16968-9c8a1708c1c04355@postgresql.org>
Permalink:  ../16968-9c8a1708c1c04355@postgresql.org/
Also on:    postgresql.org/message-id/16968-9c8a1708c1c04355@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 using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: noreply@postgresql.org, pgsql-bugs@lists.postgresql.org, kes-kes@yandex.ru
  Subject: Re: BUG #16968: Planner does not recognize optimization
  In-Reply-To: <16968-9c8a1708c1c04355@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