diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2000-10-26 21:38:24 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2000-10-26 21:38:24 +0000 |
commit | 2f35b4efdbec6c161ca9bd491d6345134910c425 (patch) | |
tree | 2424351bcc12a8ddf2b716b28f53d2c37c79e507 /src/backend/optimizer/plan/planner.c | |
parent | c9476bafdb1b97d0d21d92788f93298962145479 (diff) | |
download | postgresql-2f35b4efdbec6c161ca9bd491d6345134910c425.tar.gz postgresql-2f35b4efdbec6c161ca9bd491d6345134910c425.zip |
Re-implement LIMIT/OFFSET as a plan node type, instead of a hack in
ExecutorRun. This allows LIMIT to work in a view. Also, LIMIT in a
cursor declaration will behave in a reasonable fashion, whereas before
it was overridden by the FETCH count.
Diffstat (limited to 'src/backend/optimizer/plan/planner.c')
-rw-r--r-- | src/backend/optimizer/plan/planner.c | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c index d73ca9a34ac..f9c70f7137d 100644 --- a/src/backend/optimizer/plan/planner.c +++ b/src/backend/optimizer/plan/planner.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.92 2000/10/05 19:11:29 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.93 2000/10/26 21:36:09 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -341,8 +341,6 @@ is_simple_subquery(Query *subquery) */ if (subquery->rowMarks) elog(ERROR, "FOR UPDATE is not supported in subselects"); - if (subquery->limitOffset || subquery->limitCount) - elog(ERROR, "LIMIT is not supported in subselects"); /* * Can't currently pull up a query with setops. * Maybe after querytree redesign... @@ -350,13 +348,16 @@ is_simple_subquery(Query *subquery) if (subquery->setOperations) return false; /* - * Can't pull up a subquery involving grouping, aggregation, or sorting. + * Can't pull up a subquery involving grouping, aggregation, sorting, + * or limiting. */ if (subquery->hasAggs || subquery->groupClause || subquery->havingQual || subquery->sortClause || - subquery->distinctClause) + subquery->distinctClause || + subquery->limitOffset || + subquery->limitCount) return false; /* * Hack: don't try to pull up a subquery with an empty jointree. @@ -831,7 +832,7 @@ union_planner(Query *parse, } else { - /* It's a PARAM ... punt ... */ + /* It's an expression ... punt ... */ tuple_fraction = 0.10; } } @@ -839,9 +840,8 @@ union_planner(Query *parse, } else { - /* - * COUNT is a PARAM ... don't know exactly what the + * COUNT is an expression ... don't know exactly what the * limit will be, but for lack of a better idea assume * 10% of the plan's result is wanted. */ @@ -1024,7 +1024,7 @@ union_planner(Query *parse, } /* - * Finally, if there is a DISTINCT clause, add the UNIQUE node. + * If there is a DISTINCT clause, add the UNIQUE node. */ if (parse->distinctClause) { @@ -1032,6 +1032,16 @@ union_planner(Query *parse, parse->distinctClause); } + /* + * Finally, if there is a LIMIT/OFFSET clause, add the LIMIT node. + */ + if (parse->limitOffset || parse->limitCount) + { + result_plan = (Plan *) make_limit(tlist, result_plan, + parse->limitOffset, + parse->limitCount); + } + return result_plan; } |