27
27
*
28
28
*
29
29
* IDENTIFICATION
30
- * $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.130 2000/10/16 17:08:06 momjian Exp $
30
+ * $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.131 2000/10/26 21:35:15 tgl Exp $
31
31
*
32
32
*-------------------------------------------------------------------------
33
33
*/
@@ -52,11 +52,10 @@ static TupleDesc InitPlan(CmdType operation,
52
52
EState * estate );
53
53
static void EndPlan (Plan * plan , EState * estate );
54
54
static TupleTableSlot * ExecutePlan (EState * estate , Plan * plan ,
55
- CmdType operation ,
56
- int offsetTuples ,
57
- int numberTuples ,
58
- ScanDirection direction ,
59
- DestReceiver * destfunc );
55
+ CmdType operation ,
56
+ long numberTuples ,
57
+ ScanDirection direction ,
58
+ DestReceiver * destfunc );
60
59
static void ExecRetrieve (TupleTableSlot * slot ,
61
60
DestReceiver * destfunc ,
62
61
EState * estate );
@@ -153,19 +152,18 @@ ExecutorStart(QueryDesc *queryDesc, EState *estate)
153
152
* EXEC_RETONE: return one tuple but don't 'retrieve' it
154
153
* used in postquel function processing
155
154
*
155
+ * Note: count = 0 is interpreted as "no limit".
156
+ *
156
157
* ----------------------------------------------------------------
157
158
*/
158
159
TupleTableSlot *
159
- ExecutorRun (QueryDesc * queryDesc , EState * estate , int feature ,
160
- Node * limoffset , Node * limcount )
160
+ ExecutorRun (QueryDesc * queryDesc , EState * estate , int feature , long count )
161
161
{
162
162
CmdType operation ;
163
163
Plan * plan ;
164
164
TupleTableSlot * result ;
165
165
CommandDest dest ;
166
166
DestReceiver * destfunc ;
167
- int offset = 0 ;
168
- int count = 0 ;
169
167
170
168
/*
171
169
* sanity checks
@@ -191,111 +189,21 @@ ExecutorRun(QueryDesc *queryDesc, EState *estate, int feature,
191
189
*/
192
190
(* destfunc -> setup ) (destfunc , (TupleDesc ) NULL );
193
191
194
- /*
195
- * if given get the offset of the LIMIT clause
196
- */
197
- if (limoffset != NULL )
198
- {
199
- Const * coffset ;
200
- Param * poffset ;
201
- ParamListInfo paramLI ;
202
- int i ;
203
-
204
- switch (nodeTag (limoffset ))
205
- {
206
- case T_Const :
207
- coffset = (Const * ) limoffset ;
208
- offset = (int ) (coffset -> constvalue );
209
- break ;
210
-
211
- case T_Param :
212
- poffset = (Param * ) limoffset ;
213
- paramLI = estate -> es_param_list_info ;
214
-
215
- if (paramLI == NULL )
216
- elog (ERROR , "parameter for limit offset not in executor state" );
217
- for (i = 0 ; paramLI [i ].kind != PARAM_INVALID ; i ++ )
218
- {
219
- if (paramLI [i ].kind == PARAM_NUM && paramLI [i ].id == poffset -> paramid )
220
- break ;
221
- }
222
- if (paramLI [i ].kind == PARAM_INVALID )
223
- elog (ERROR , "parameter for limit offset not in executor state" );
224
- if (paramLI [i ].isnull )
225
- elog (ERROR , "limit offset cannot be NULL value" );
226
- offset = (int ) (paramLI [i ].value );
227
-
228
- break ;
229
-
230
- default :
231
- elog (ERROR , "unexpected node type %d as limit offset" , nodeTag (limoffset ));
232
- }
233
-
234
- if (offset < 0 )
235
- elog (ERROR , "limit offset cannot be negative" );
236
- }
237
-
238
- /*
239
- * if given get the count of the LIMIT clause
240
- */
241
- if (limcount != NULL )
242
- {
243
- Const * ccount ;
244
- Param * pcount ;
245
- ParamListInfo paramLI ;
246
- int i ;
247
-
248
- switch (nodeTag (limcount ))
249
- {
250
- case T_Const :
251
- ccount = (Const * ) limcount ;
252
- count = (int ) (ccount -> constvalue );
253
- break ;
254
-
255
- case T_Param :
256
- pcount = (Param * ) limcount ;
257
- paramLI = estate -> es_param_list_info ;
258
-
259
- if (paramLI == NULL )
260
- elog (ERROR , "parameter for limit count not in executor state" );
261
- for (i = 0 ; paramLI [i ].kind != PARAM_INVALID ; i ++ )
262
- {
263
- if (paramLI [i ].kind == PARAM_NUM && paramLI [i ].id == pcount -> paramid )
264
- break ;
265
- }
266
- if (paramLI [i ].kind == PARAM_INVALID )
267
- elog (ERROR , "parameter for limit count not in executor state" );
268
- if (paramLI [i ].isnull )
269
- elog (ERROR , "limit count cannot be NULL value" );
270
- count = (int ) (paramLI [i ].value );
271
-
272
- break ;
273
-
274
- default :
275
- elog (ERROR , "unexpected node type %d as limit count" , nodeTag (limcount ));
276
- }
277
-
278
- if (count < 0 )
279
- elog (ERROR , "limit count cannot be negative" );
280
- }
281
-
282
192
switch (feature )
283
193
{
284
-
285
194
case EXEC_RUN :
286
195
result = ExecutePlan (estate ,
287
196
plan ,
288
197
operation ,
289
- offset ,
290
198
count ,
291
199
ForwardScanDirection ,
292
200
destfunc );
293
201
break ;
202
+
294
203
case EXEC_FOR :
295
204
result = ExecutePlan (estate ,
296
205
plan ,
297
206
operation ,
298
- offset ,
299
207
count ,
300
208
ForwardScanDirection ,
301
209
destfunc );
@@ -308,7 +216,6 @@ ExecutorRun(QueryDesc *queryDesc, EState *estate, int feature,
308
216
result = ExecutePlan (estate ,
309
217
plan ,
310
218
operation ,
311
- offset ,
312
219
count ,
313
220
BackwardScanDirection ,
314
221
destfunc );
@@ -322,14 +229,14 @@ ExecutorRun(QueryDesc *queryDesc, EState *estate, int feature,
322
229
result = ExecutePlan (estate ,
323
230
plan ,
324
231
operation ,
325
- 0 ,
326
232
ONE_TUPLE ,
327
233
ForwardScanDirection ,
328
234
destfunc );
329
235
break ;
236
+
330
237
default :
331
- result = NULL ;
332
238
elog (DEBUG , "ExecutorRun: Unknown feature %d" , feature );
239
+ result = NULL ;
333
240
break ;
334
241
}
335
242
@@ -917,33 +824,30 @@ EndPlan(Plan *plan, EState *estate)
917
824
/* ----------------------------------------------------------------
918
825
* ExecutePlan
919
826
*
920
- * processes the query plan to retrieve 'tupleCount ' tuples in the
827
+ * processes the query plan to retrieve 'numberTuples ' tuples in the
921
828
* direction specified.
922
829
* Retrieves all tuples if tupleCount is 0
923
830
*
924
- * result is either a slot containing a tuple in the case
831
+ * result is either a slot containing the last tuple in the case
925
832
* of a RETRIEVE or NULL otherwise.
926
833
*
834
+ * Note: the ctid attribute is a 'junk' attribute that is removed before the
835
+ * user can see it
927
836
* ----------------------------------------------------------------
928
837
*/
929
-
930
- /* the ctid attribute is a 'junk' attribute that is removed before the
931
- user can see it*/
932
-
933
838
static TupleTableSlot *
934
839
ExecutePlan (EState * estate ,
935
840
Plan * plan ,
936
841
CmdType operation ,
937
- int offsetTuples ,
938
- int numberTuples ,
842
+ long numberTuples ,
939
843
ScanDirection direction ,
940
844
DestReceiver * destfunc )
941
845
{
942
846
JunkFilter * junkfilter ;
943
847
TupleTableSlot * slot ;
944
848
ItemPointer tupleid = NULL ;
945
849
ItemPointerData tuple_ctid ;
946
- int current_tuple_count ;
850
+ long current_tuple_count ;
947
851
TupleTableSlot * result ;
948
852
949
853
/*
@@ -990,17 +894,6 @@ lnext: ;
990
894
break ;
991
895
}
992
896
993
- /*
994
- * For now we completely execute the plan and skip result tuples
995
- * if requested by LIMIT offset. Finally we should try to do it in
996
- * deeper levels if possible (during index scan) - Jan
997
- */
998
- if (offsetTuples > 0 )
999
- {
1000
- -- offsetTuples ;
1001
- continue ;
1002
- }
1003
-
1004
897
/*
1005
898
* if we have a junk filter, then project a new tuple with the
1006
899
* junk removed.
@@ -1152,10 +1045,10 @@ lnext: ;
1152
1045
}
1153
1046
1154
1047
/*
1155
- * check our tuple count.. if we've returned the proper number
1156
- * then return , else loop again and process more tuples..
1048
+ * check our tuple count.. if we've processed the proper number
1049
+ * then quit , else loop again and process more tuples..
1157
1050
*/
1158
- current_tuple_count += 1 ;
1051
+ current_tuple_count ++ ;
1159
1052
if (numberTuples == current_tuple_count )
1160
1053
break ;
1161
1054
}
0 commit comments