Commit a998a692 authored by Tom Lane's avatar Tom Lane

Code review for bigint-LIMIT patch. Fix missed planner dependency,

eliminate unnecessary code, force initdb because stored rules change
(limit nodes are now supposed to be int8 not int4 expressions).
Update comments and error messages, which still all said 'integer'.
parent 5ffa0bb4
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/executor/nodeLimit.c,v 1.26 2006/07/26 00:34:48 momjian Exp $ * $PostgreSQL: pgsql/src/backend/executor/nodeLimit.c,v 1.27 2006/07/26 19:31:50 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -23,7 +23,6 @@ ...@@ -23,7 +23,6 @@
#include "executor/executor.h" #include "executor/executor.h"
#include "executor/nodeLimit.h" #include "executor/nodeLimit.h"
#include "catalog/pg_type.h"
static void recompute_limits(LimitState *node); static void recompute_limits(LimitState *node);
...@@ -227,24 +226,14 @@ recompute_limits(LimitState *node) ...@@ -227,24 +226,14 @@ recompute_limits(LimitState *node)
{ {
ExprContext *econtext = node->ps.ps_ExprContext; ExprContext *econtext = node->ps.ps_ExprContext;
bool isNull; bool isNull;
Oid type;
if (node->limitOffset) if (node->limitOffset)
{ {
type = ((Const *) node->limitOffset->expr)->consttype; node->offset =
if (type == INT8OID)
node->offset =
DatumGetInt64(ExecEvalExprSwitchContext(node->limitOffset, DatumGetInt64(ExecEvalExprSwitchContext(node->limitOffset,
econtext, econtext,
&isNull, &isNull,
NULL)); NULL));
else
node->offset = DatumGetInt32(ExecEvalExprSwitchContext(node->limitOffset,
econtext,
&isNull,
NULL));
/* Interpret NULL offset as no offset */ /* Interpret NULL offset as no offset */
if (isNull) if (isNull)
node->offset = 0; node->offset = 0;
...@@ -260,21 +249,11 @@ recompute_limits(LimitState *node) ...@@ -260,21 +249,11 @@ recompute_limits(LimitState *node)
if (node->limitCount) if (node->limitCount)
{ {
node->noCount = false; node->noCount = false;
type = ((Const *) node->limitCount->expr)->consttype; node->count =
if (type == INT8OID)
node->count =
DatumGetInt64(ExecEvalExprSwitchContext(node->limitCount, DatumGetInt64(ExecEvalExprSwitchContext(node->limitCount,
econtext, econtext,
&isNull, &isNull,
NULL)); NULL));
else
node->count = DatumGetInt32(ExecEvalExprSwitchContext(node->limitCount,
econtext,
&isNull,
NULL));
/* Interpret NULL count as no count (LIMIT ALL) */ /* Interpret NULL count as no count (LIMIT ALL) */
if (isNull) if (isNull)
node->noCount = true; node->noCount = true;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/plan/planagg.c,v 1.18 2006/07/14 14:52:20 momjian Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/plan/planagg.c,v 1.19 2006/07/26 19:31:50 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -459,9 +459,9 @@ make_agg_subplan(PlannerInfo *root, MinMaxAggInfo *info) ...@@ -459,9 +459,9 @@ make_agg_subplan(PlannerInfo *root, MinMaxAggInfo *info)
/* set up LIMIT 1 */ /* set up LIMIT 1 */
subparse->limitOffset = NULL; subparse->limitOffset = NULL;
subparse->limitCount = (Node *) makeConst(INT4OID, sizeof(int4), subparse->limitCount = (Node *) makeConst(INT8OID, sizeof(int64),
Int32GetDatum(1), Int64GetDatum(1),
false, true); false, false /* not by val */);
/* /*
* Generate the plan for the subquery. We already have a Path for the * Generate the plan for the subquery. We already have a Path for the
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/plan/planner.c,v 1.204 2006/07/26 00:34:48 momjian Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/plan/planner.c,v 1.205 2006/07/26 19:31:50 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -1129,7 +1129,6 @@ preprocess_limit(PlannerInfo *root, double tuple_fraction, ...@@ -1129,7 +1129,6 @@ preprocess_limit(PlannerInfo *root, double tuple_fraction,
else else
{ {
*offset_est = DatumGetInt64(((Const *) est)->constvalue); *offset_est = DatumGetInt64(((Const *) est)->constvalue);
if (*offset_est < 0) if (*offset_est < 0)
*offset_est = 0; /* less than 0 is same as 0 */ *offset_est = 0; /* less than 0 is same as 0 */
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/parser/parse_clause.c,v 1.154 2006/07/26 00:34:48 momjian Exp $ * $PostgreSQL: pgsql/src/backend/parser/parse_clause.c,v 1.155 2006/07/26 19:31:51 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -1074,9 +1074,12 @@ transformWhereClause(ParseState *pstate, Node *clause, ...@@ -1074,9 +1074,12 @@ transformWhereClause(ParseState *pstate, Node *clause,
/* /*
* transformLimitClause - * transformLimitClause -
* Transform the expression and make sure it is of type integer. * Transform the expression and make sure it is of type bigint.
* Used for LIMIT and allied clauses. * Used for LIMIT and allied clauses.
* *
* Note: as of Postgres 8.2, LIMIT expressions are expected to yield int8,
* rather than int4 as before.
*
* constructName does not affect the semantics, but is used in error messages * constructName does not affect the semantics, but is used in error messages
*/ */
Node * Node *
...@@ -1090,7 +1093,7 @@ transformLimitClause(ParseState *pstate, Node *clause, ...@@ -1090,7 +1093,7 @@ transformLimitClause(ParseState *pstate, Node *clause,
qual = transformExpr(pstate, clause); qual = transformExpr(pstate, clause);
qual = coerce_to_integer64(pstate, qual, constructName); qual = coerce_to_bigint(pstate, qual, constructName);
/* /*
* LIMIT can't refer to any vars or aggregates of the current query; we * LIMIT can't refer to any vars or aggregates of the current query; we
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/parser/parse_coerce.c,v 2.142 2006/07/26 00:34:48 momjian Exp $ * $PostgreSQL: pgsql/src/backend/parser/parse_coerce.c,v 2.143 2006/07/26 19:31:51 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -780,7 +780,8 @@ coerce_record_to_complex(ParseState *pstate, Node *node, ...@@ -780,7 +780,8 @@ coerce_record_to_complex(ParseState *pstate, Node *node,
return (Node *) rowexpr; return (Node *) rowexpr;
} }
/* coerce_to_boolean() /*
* coerce_to_boolean()
* Coerce an argument of a construct that requires boolean input * Coerce an argument of a construct that requires boolean input
* (AND, OR, NOT, etc). Also check that input is not a set. * (AND, OR, NOT, etc). Also check that input is not a set.
* *
...@@ -819,8 +820,9 @@ coerce_to_boolean(ParseState *pstate, Node *node, ...@@ -819,8 +820,9 @@ coerce_to_boolean(ParseState *pstate, Node *node,
return node; return node;
} }
/* coerce_to_integer() /*
* Coerce an argument of a construct that requires integer input * coerce_to_integer()
* Coerce an argument of a construct that requires integer input.
* Also check that input is not a set. * Also check that input is not a set.
* *
* Returns the possibly-transformed node tree. * Returns the possibly-transformed node tree.
...@@ -857,10 +859,11 @@ coerce_to_integer(ParseState *pstate, Node *node, ...@@ -857,10 +859,11 @@ coerce_to_integer(ParseState *pstate, Node *node,
return node; return node;
} }
/* coerce_to_integer64() /*
* Coerce an argument of a construct that requires integer input * coerce_to_bigint()
* (LIMIT, OFFSET). Also check that input is not a set. * Coerce an argument of a construct that requires int8 input.
* Also check that input is not a set.
* *
* Returns the possibly-transformed node tree. * Returns the possibly-transformed node tree.
* *
...@@ -868,34 +871,35 @@ coerce_to_integer(ParseState *pstate, Node *node, ...@@ -868,34 +871,35 @@ coerce_to_integer(ParseState *pstate, Node *node,
* processing is wanted. * processing is wanted.
*/ */
Node * Node *
coerce_to_integer64(ParseState *pstate, Node *node, coerce_to_bigint(ParseState *pstate, Node *node,
const char *constructName) const char *constructName)
{ {
Oid inputTypeId = exprType(node); Oid inputTypeId = exprType(node);
if (inputTypeId != INT8OID) if (inputTypeId != INT8OID)
{ {
node = coerce_to_target_type(pstate, node, inputTypeId, node = coerce_to_target_type(pstate, node, inputTypeId,
INT8OID, -1, COERCION_ASSIGNMENT, INT8OID, -1,
COERCION_ASSIGNMENT,
COERCE_IMPLICIT_CAST); COERCE_IMPLICIT_CAST);
if (node == NULL) if (node == NULL)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH), (errcode(ERRCODE_DATATYPE_MISMATCH),
/* translator: first %s is name of a SQL construct, eg LIMIT */ /* translator: first %s is name of a SQL construct, eg LIMIT */
errmsg("argument of %s must be type integer, not type %s", errmsg("argument of %s must be type bigint, not type %s",
constructName, format_type_be(inputTypeId)))); constructName, format_type_be(inputTypeId))));
} }
if (expression_returns_set(node)) if (expression_returns_set(node))
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH), (errcode(ERRCODE_DATATYPE_MISMATCH),
/* translator: %s is name of a SQL construct, eg LIMIT */ /* translator: %s is name of a SQL construct, eg LIMIT */
errmsg("argument of %s must not return a set", errmsg("argument of %s must not return a set",
constructName))); constructName)));
return node; return node;
} }
/* select_common_type() /* select_common_type()
* Determine the common supertype of a list of input expression types. * Determine the common supertype of a list of input expression types.
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.340 2006/07/25 03:51:21 tgl Exp $ * $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.341 2006/07/26 19:31:51 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -53,6 +53,6 @@ ...@@ -53,6 +53,6 @@
*/ */
/* yyyymmddN */ /* yyyymmddN */
#define CATALOG_VERSION_NO 200607241 #define CATALOG_VERSION_NO 200607261
#endif #endif
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.317 2006/07/13 16:49:19 momjian Exp $ * $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.318 2006/07/26 19:31:51 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -112,8 +112,8 @@ typedef struct Query ...@@ -112,8 +112,8 @@ typedef struct Query
List *sortClause; /* a list of SortClause's */ List *sortClause; /* a list of SortClause's */
Node *limitOffset; /* # of result tuples to skip */ Node *limitOffset; /* # of result tuples to skip (int8 expr) */
Node *limitCount; /* # of result tuples to return */ Node *limitCount; /* # of result tuples to return (int8 expr) */
List *rowMarks; /* a list of RowMarkClause's */ List *rowMarks; /* a list of RowMarkClause's */
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/nodes/plannodes.h,v 1.83 2006/03/05 15:58:57 momjian Exp $ * $PostgreSQL: pgsql/src/include/nodes/plannodes.h,v 1.84 2006/07/26 19:31:51 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -463,6 +463,9 @@ typedef struct SetOp ...@@ -463,6 +463,9 @@ typedef struct SetOp
/* ---------------- /* ----------------
* limit node * limit node
*
* Note: as of Postgres 8.2, the offset and count expressions are expected
* to yield int8, rather than int4 as before.
* ---------------- * ----------------
*/ */
typedef struct Limit typedef struct Limit
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/parser/parse_coerce.h,v 1.64 2006/07/26 00:34:48 momjian Exp $ * $PostgreSQL: pgsql/src/include/parser/parse_coerce.h,v 1.65 2006/07/26 19:31:51 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -57,9 +57,9 @@ extern Node *coerce_to_boolean(ParseState *pstate, Node *node, ...@@ -57,9 +57,9 @@ extern Node *coerce_to_boolean(ParseState *pstate, Node *node,
const char *constructName); const char *constructName);
extern Node *coerce_to_integer(ParseState *pstate, Node *node, extern Node *coerce_to_integer(ParseState *pstate, Node *node,
const char *constructName); const char *constructName);
extern Node *coerce_to_integer64(ParseState *pstate, Node *node, extern Node *coerce_to_bigint(ParseState *pstate, Node *node,
const char *constructName); const char *constructName);
extern Oid select_common_type(List *typeids, const char *context); extern Oid select_common_type(List *typeids, const char *context);
extern Node *coerce_to_common_type(ParseState *pstate, Node *node, extern Node *coerce_to_common_type(ParseState *pstate, Node *node,
Oid targetTypeId, Oid targetTypeId,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment