Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
085e5596
Commit
085e5596
authored
Jul 26, 2006
by
Bruce Momjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change LIMIT/OFFSET to use int8
Dhanaraj M
parent
796de9c1
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
89 additions
and
27 deletions
+89
-27
src/backend/executor/nodeLimit.c
src/backend/executor/nodeLimit.c
+27
-6
src/backend/optimizer/plan/createplan.c
src/backend/optimizer/plan/createplan.c
+2
-2
src/backend/optimizer/plan/planner.c
src/backend/optimizer/plan/planner.c
+8
-7
src/backend/parser/parse_clause.c
src/backend/parser/parse_clause.c
+2
-2
src/backend/parser/parse_coerce.c
src/backend/parser/parse_coerce.c
+40
-2
src/include/nodes/execnodes.h
src/include/nodes/execnodes.h
+4
-4
src/include/optimizer/planmain.h
src/include/optimizer/planmain.h
+2
-2
src/include/parser/parse_coerce.h
src/include/parser/parse_coerce.h
+4
-2
No files found.
src/backend/executor/nodeLimit.c
View file @
085e5596
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/executor/nodeLimit.c,v 1.2
5 2006/03/05 15:58:26
momjian Exp $
* $PostgreSQL: pgsql/src/backend/executor/nodeLimit.c,v 1.2
6 2006/07/26 00:34:48
momjian Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -23,6 +23,7 @@
...
@@ -23,6 +23,7 @@
#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
);
...
@@ -226,14 +227,24 @@ recompute_limits(LimitState *node)
...
@@ -226,14 +227,24 @@ 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
)
{
{
node
->
offset
=
type
=
((
Const
*
)
node
->
limitOffset
->
expr
)
->
consttype
;
DatumGetInt32
(
ExecEvalExprSwitchContext
(
node
->
limitOffset
,
if
(
type
==
INT8OID
)
node
->
offset
=
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
;
...
@@ -249,11 +260,21 @@ recompute_limits(LimitState *node)
...
@@ -249,11 +260,21 @@ recompute_limits(LimitState *node)
if
(
node
->
limitCount
)
if
(
node
->
limitCount
)
{
{
node
->
noCount
=
false
;
node
->
noCount
=
false
;
node
->
count
=
type
=
((
Const
*
)
node
->
limitCount
->
expr
)
->
consttype
;
DatumGetInt32
(
ExecEvalExprSwitchContext
(
node
->
limitCount
,
if
(
type
==
INT8OID
)
node
->
count
=
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
;
...
...
src/backend/optimizer/plan/createplan.c
View file @
085e5596
...
@@ -10,7 +10,7 @@
...
@@ -10,7 +10,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/plan/createplan.c,v 1.21
4 2006/07/14 14:52:20
momjian Exp $
* $PostgreSQL: pgsql/src/backend/optimizer/plan/createplan.c,v 1.21
5 2006/07/26 00:34:48
momjian Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -2863,7 +2863,7 @@ make_setop(SetOpCmd cmd, Plan *lefttree,
...
@@ -2863,7 +2863,7 @@ make_setop(SetOpCmd cmd, Plan *lefttree,
*/
*/
Limit
*
Limit
*
make_limit
(
Plan
*
lefttree
,
Node
*
limitOffset
,
Node
*
limitCount
,
make_limit
(
Plan
*
lefttree
,
Node
*
limitOffset
,
Node
*
limitCount
,
int
offset_est
,
int
count_est
)
int
64
offset_est
,
int64
count_est
)
{
{
Limit
*
node
=
makeNode
(
Limit
);
Limit
*
node
=
makeNode
(
Limit
);
Plan
*
plan
=
&
node
->
plan
;
Plan
*
plan
=
&
node
->
plan
;
...
...
src/backend/optimizer/plan/planner.c
View file @
085e5596
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/plan/planner.c,v 1.20
3 2006/07/14 14:52:20
momjian Exp $
* $PostgreSQL: pgsql/src/backend/optimizer/plan/planner.c,v 1.20
4 2006/07/26 00:34:48
momjian Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -59,7 +59,7 @@ static Plan *inheritance_planner(PlannerInfo *root);
...
@@ -59,7 +59,7 @@ static Plan *inheritance_planner(PlannerInfo *root);
static
Plan
*
grouping_planner
(
PlannerInfo
*
root
,
double
tuple_fraction
);
static
Plan
*
grouping_planner
(
PlannerInfo
*
root
,
double
tuple_fraction
);
static
double
preprocess_limit
(
PlannerInfo
*
root
,
static
double
preprocess_limit
(
PlannerInfo
*
root
,
double
tuple_fraction
,
double
tuple_fraction
,
int
*
offset_est
,
int
*
count_est
);
int
64
*
offset_est
,
int64
*
count_est
);
static
bool
choose_hashed_grouping
(
PlannerInfo
*
root
,
double
tuple_fraction
,
static
bool
choose_hashed_grouping
(
PlannerInfo
*
root
,
double
tuple_fraction
,
Path
*
cheapest_path
,
Path
*
sorted_path
,
Path
*
cheapest_path
,
Path
*
sorted_path
,
double
dNumGroups
,
AggClauseCounts
*
agg_counts
);
double
dNumGroups
,
AggClauseCounts
*
agg_counts
);
...
@@ -631,8 +631,8 @@ grouping_planner(PlannerInfo *root, double tuple_fraction)
...
@@ -631,8 +631,8 @@ grouping_planner(PlannerInfo *root, double tuple_fraction)
{
{
Query
*
parse
=
root
->
parse
;
Query
*
parse
=
root
->
parse
;
List
*
tlist
=
parse
->
targetList
;
List
*
tlist
=
parse
->
targetList
;
int
offset_est
=
0
;
int
64
offset_est
=
0
;
int
count_est
=
0
;
int
64
count_est
=
0
;
Plan
*
result_plan
;
Plan
*
result_plan
;
List
*
current_pathkeys
;
List
*
current_pathkeys
;
List
*
sort_pathkeys
;
List
*
sort_pathkeys
;
...
@@ -1080,7 +1080,7 @@ grouping_planner(PlannerInfo *root, double tuple_fraction)
...
@@ -1080,7 +1080,7 @@ grouping_planner(PlannerInfo *root, double tuple_fraction)
*/
*/
static
double
static
double
preprocess_limit
(
PlannerInfo
*
root
,
double
tuple_fraction
,
preprocess_limit
(
PlannerInfo
*
root
,
double
tuple_fraction
,
int
*
offset_est
,
int
*
count_est
)
int
64
*
offset_est
,
int64
*
count_est
)
{
{
Query
*
parse
=
root
->
parse
;
Query
*
parse
=
root
->
parse
;
Node
*
est
;
Node
*
est
;
...
@@ -1105,7 +1105,7 @@ preprocess_limit(PlannerInfo *root, double tuple_fraction,
...
@@ -1105,7 +1105,7 @@ preprocess_limit(PlannerInfo *root, double tuple_fraction,
}
}
else
else
{
{
*
count_est
=
DatumGetInt
32
(((
Const
*
)
est
)
->
constvalue
);
*
count_est
=
DatumGetInt
64
(((
Const
*
)
est
)
->
constvalue
);
if
(
*
count_est
<=
0
)
if
(
*
count_est
<=
0
)
*
count_est
=
1
;
/* force to at least 1 */
*
count_est
=
1
;
/* force to at least 1 */
}
}
...
@@ -1128,7 +1128,8 @@ preprocess_limit(PlannerInfo *root, double tuple_fraction,
...
@@ -1128,7 +1128,8 @@ preprocess_limit(PlannerInfo *root, double tuple_fraction,
}
}
else
else
{
{
*
offset_est
=
DatumGetInt32
(((
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 */
}
}
...
...
src/backend/parser/parse_clause.c
View file @
085e5596
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/parser/parse_clause.c,v 1.15
3 2006/07/14 14:52:21
momjian Exp $
* $PostgreSQL: pgsql/src/backend/parser/parse_clause.c,v 1.15
4 2006/07/26 00:34:48
momjian Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -1090,7 +1090,7 @@ transformLimitClause(ParseState *pstate, Node *clause,
...
@@ -1090,7 +1090,7 @@ transformLimitClause(ParseState *pstate, Node *clause,
qual
=
transformExpr
(
pstate
,
clause
);
qual
=
transformExpr
(
pstate
,
clause
);
qual
=
coerce_to_integer
(
pstate
,
qual
,
constructName
);
qual
=
coerce_to_integer
64
(
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
...
...
src/backend/parser/parse_coerce.c
View file @
085e5596
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/parser/parse_coerce.c,v 2.14
1 2006/07/14 14:52:22
momjian Exp $
* $PostgreSQL: pgsql/src/backend/parser/parse_coerce.c,v 2.14
2 2006/07/26 00:34:48
momjian Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -821,7 +821,7 @@ coerce_to_boolean(ParseState *pstate, Node *node,
...
@@ -821,7 +821,7 @@ coerce_to_boolean(ParseState *pstate, Node *node,
/* coerce_to_integer()
/* coerce_to_integer()
* Coerce an argument of a construct that requires integer input
* Coerce an argument of a construct that requires integer input
*
(LIMIT, OFFSET, etc).
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,7 +857,45 @@ coerce_to_integer(ParseState *pstate, Node *node,
...
@@ -857,7 +857,45 @@ coerce_to_integer(ParseState *pstate, Node *node,
return
node
;
return
node
;
}
}
/* coerce_to_integer64()
* Coerce an argument of a construct that requires integer input
* (LIMIT, OFFSET). Also check that input is not a set.
*
* Returns the possibly-transformed node tree.
*
* As with coerce_type, pstate may be NULL if no special unknown-Param
* processing is wanted.
*/
Node
*
coerce_to_integer64
(
ParseState
*
pstate
,
Node
*
node
,
const
char
*
constructName
)
{
Oid
inputTypeId
=
exprType
(
node
);
if
(
inputTypeId
!=
INT8OID
)
{
node
=
coerce_to_target_type
(
pstate
,
node
,
inputTypeId
,
INT8OID
,
-
1
,
COERCION_ASSIGNMENT
,
COERCE_IMPLICIT_CAST
);
if
(
node
==
NULL
)
ereport
(
ERROR
,
(
errcode
(
ERRCODE_DATATYPE_MISMATCH
),
/* translator: first %s is name of a SQL construct, eg LIMIT */
errmsg
(
"argument of %s must be type integer, not type %s"
,
constructName
,
format_type_be
(
inputTypeId
))));
}
if
(
expression_returns_set
(
node
))
ereport
(
ERROR
,
(
errcode
(
ERRCODE_DATATYPE_MISMATCH
),
/* translator: %s is name of a SQL construct, eg LIMIT */
errmsg
(
"argument of %s must not return a set"
,
constructName
)));
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.
...
...
src/include/nodes/execnodes.h
View file @
085e5596
...
@@ -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/execnodes.h,v 1.15
3 2006/07/13 16:49:19
momjian Exp $
* $PostgreSQL: pgsql/src/include/nodes/execnodes.h,v 1.15
4 2006/07/26 00:34:48
momjian Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -1325,11 +1325,11 @@ typedef struct LimitState
...
@@ -1325,11 +1325,11 @@ typedef struct LimitState
PlanState
ps
;
/* its first field is NodeTag */
PlanState
ps
;
/* its first field is NodeTag */
ExprState
*
limitOffset
;
/* OFFSET parameter, or NULL if none */
ExprState
*
limitOffset
;
/* OFFSET parameter, or NULL if none */
ExprState
*
limitCount
;
/* COUNT parameter, or NULL if none */
ExprState
*
limitCount
;
/* COUNT parameter, or NULL if none */
long
offset
;
/* current OFFSET value */
int64
offset
;
/* current OFFSET value */
long
count
;
/* current COUNT, if any */
int64
count
;
/* current COUNT, if any */
bool
noCount
;
/* if true, ignore count */
bool
noCount
;
/* if true, ignore count */
LimitStateCond
lstate
;
/* state machine status, as above */
LimitStateCond
lstate
;
/* state machine status, as above */
long
position
;
/* 1-based index of last tuple returned */
int64
position
;
/* 1-based index of last tuple returned */
TupleTableSlot
*
subSlot
;
/* tuple last obtained from subplan */
TupleTableSlot
*
subSlot
;
/* tuple last obtained from subplan */
}
LimitState
;
}
LimitState
;
...
...
src/include/optimizer/planmain.h
View file @
085e5596
...
@@ -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/optimizer/planmain.h,v 1.9
3 2006/07/01 18:38:33 tgl
Exp $
* $PostgreSQL: pgsql/src/include/optimizer/planmain.h,v 1.9
4 2006/07/26 00:34:48 momjian
Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -55,7 +55,7 @@ extern Material *make_material(Plan *lefttree);
...
@@ -55,7 +55,7 @@ extern Material *make_material(Plan *lefttree);
extern
Plan
*
materialize_finished_plan
(
Plan
*
subplan
);
extern
Plan
*
materialize_finished_plan
(
Plan
*
subplan
);
extern
Unique
*
make_unique
(
Plan
*
lefttree
,
List
*
distinctList
);
extern
Unique
*
make_unique
(
Plan
*
lefttree
,
List
*
distinctList
);
extern
Limit
*
make_limit
(
Plan
*
lefttree
,
Node
*
limitOffset
,
Node
*
limitCount
,
extern
Limit
*
make_limit
(
Plan
*
lefttree
,
Node
*
limitOffset
,
Node
*
limitCount
,
int
offset_est
,
int
count_est
);
int
64
offset_est
,
int64
count_est
);
extern
SetOp
*
make_setop
(
SetOpCmd
cmd
,
Plan
*
lefttree
,
extern
SetOp
*
make_setop
(
SetOpCmd
cmd
,
Plan
*
lefttree
,
List
*
distinctList
,
AttrNumber
flagColIdx
);
List
*
distinctList
,
AttrNumber
flagColIdx
);
extern
Result
*
make_result
(
List
*
tlist
,
Node
*
resconstantqual
,
Plan
*
subplan
);
extern
Result
*
make_result
(
List
*
tlist
,
Node
*
resconstantqual
,
Plan
*
subplan
);
...
...
src/include/parser/parse_coerce.h
View file @
085e5596
...
@@ -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.6
3 2006/07/13 16:49:19
momjian Exp $
* $PostgreSQL: pgsql/src/include/parser/parse_coerce.h,v 1.6
4 2006/07/26 00:34:48
momjian Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -57,7 +57,9 @@ extern Node *coerce_to_boolean(ParseState *pstate, Node *node,
...
@@ -57,7 +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
,
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
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment