Skip to content

ORCA: limit is not pushed down to the segment if table is not analyzed #1638

@gfphoenix78

Description

@gfphoenix78
gpadmin=# CREATE TABLE mv_large (a int, b int, c text) USING PAX DISTRIBUTED BY (a);
INSERT INTO mv_large SELECT i, i % 1000, 'large_' || (i % 10000) FROM generate_series(1, 1000000) i;
CREATE TABLE
INSERT 0 1000000

gpadmin=# explain SELECT count(*) FROM (SELECT * FROM mv_large ORDER BY a LIMIT 100000) sub;
                                        QUERY PLAN
------------------------------------------------------------------------------------------
 Aggregate  (cost=0.00..431.00 rows=1 width=8)
   ->  Limit  (cost=0.00..431.00 rows=1 width=1)
         ->  Gather Motion 3:1  (slice1; segments: 3)  (cost=0.00..431.00 rows=1 width=4)
               Merge Key: a
               ->  Sort  (cost=0.00..431.00 rows=1 width=4)
                     Sort Key: a
                     ->  Seq Scan on mv_large  (cost=0.00..431.00 rows=1 width=4)
 Optimizer: GPORCA
(8 rows)

gpadmin=# set optimizer=off;
SET
gpadmin=# explain SELECT count(*) FROM (SELECT * FROM mv_large ORDER BY a LIMIT 100000) sub;
                                            QUERY PLAN
---------------------------------------------------------------------------------------------------
 Aggregate  (cost=2518.92..2518.93 rows=1 width=8)
   ->  Limit  (cost=1273.59..1935.17 rows=46700 width=40)
         ->  Gather Motion 3:1  (slice1; segments: 3)  (cost=1273.59..1935.17 rows=46700 width=40)
               Merge Key: mv_large.a
               ->  Limit  (cost=1273.59..1312.50 rows=15567 width=40)
                     ->  Sort  (cost=1273.59..1312.50 rows=15567 width=40)
                           Sort Key: mv_large.a
                           ->  Seq Scan on mv_large  (cost=0.00..189.67 rows=15567 width=40)
 Optimizer: Postgres query optimizer
(9 rows)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions