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: tim3sp@gmail.com
Subject: BUG #17862: Overall query cost ignores window function
Date: Wed, 22 Mar 2023 17:42:03 +0000
Message-ID: <17862-1ab8f74b0f7b0611@postgresql.org> (raw)

The following bug has been logged on the website:

Bug reference:      17862
Logged by:          Tim Palmer
Email address:      tim3sp@gmail.com
PostgreSQL version: 15.2
Operating system:   Debian
Description:        

This query needs to read all of large_table to count the number of rows,
despite the LIMIT clause:

    SELECT large_table.*, count(*) OVER ()
    FROM generate_series(1, 1000000000000) large_table
    LIMIT 10

I would have expected a query plan something like this, with a large overall
cost:

 Limit  (cost=0.00..22500000000.00 rows=10 width=16)
   ->  WindowAgg  (cost=0.00..22500000000.00 rows=1000000000000 width=16)
         ->  Function Scan on generate_series large_table 
(cost=0.00..10000000000.00 rows=1000000000000 width=8)

But I actually get this query plan, with a cost of 0.23:

 Limit  (cost=0.00..0.23 rows=10 width=16)
   ->  WindowAgg  (cost=0.00..22500000000.00 rows=1000000000000 width=16)
         ->  Function Scan on generate_series large_table 
(cost=0.00..10000000000.00 rows=1000000000000 width=8)

I believe this (on a more complicated query) is affecting the plan chosen by
the optimizer.



view thread (5+ messages)  latest in thread

Message-ID: <17862-1ab8f74b0f7b0611@postgresql.org>
Permalink:  ../17862-1ab8f74b0f7b0611@postgresql.org/
Also on:    postgresql.org/message-id/17862-1ab8f74b0f7b0611@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, tim3sp@gmail.com
  Subject: Re: BUG #17862: Overall query cost ignores window function
  In-Reply-To: <17862-1ab8f74b0f7b0611@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