BUG #17862: Overall query cost ignores window function - Mailing list pgsql-bugs

From PG Bug reporting form
Subject BUG #17862: Overall query cost ignores window function
Date
Msg-id 17862-1ab8f74b0f7b0611@postgresql.org
Whole thread Raw
Responses Re: BUG #17862: Overall query cost ignores window function  (David Rowley <dgrowleyml@gmail.com>)
List pgsql-bugs
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.


pgsql-bugs by date:

Previous
From: PG Bug reporting form
Date:
Subject: BUG #17861: Disappearance of packages in repo for rhel-8
Next
From: David Rowley
Date:
Subject: Re: BUG #17862: Overall query cost ignores window function