Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit23a27b0

Browse files
committed
Widen query numbers-of-tuples-processed counters to uint64.
This patch widens SPI_processed, EState's es_processed field, PortalData'sportalPos field, FuncCallContext's call_cntr and max_calls fields,ExecutorRun's count argument, PortalRunFetch's result, and the max numberof rows in a SPITupleTable to uint64, and deals with (I hope) all theensuing fallout. Some of these values were declared uint32 before, andothers "long".I also removed PortalData's posOverflow field, since that logic seemspretty useless given that portalPos is now always 64 bits.The user-visible results are that command tags for SELECT etc willcorrectly report tuple counts larger than 4G, as will plpgsql's GETGET DIAGNOSTICS ... ROW_COUNT command. Queries processing more tuplesthan that are still not exactly the norm, but they're becoming morecommon.Most values associated with FETCH/MOVE distances, such as PortalRun's countargument and the count argument of most SPI functions that have one, remaindeclared as "long". It's not clear whether it would be worth promotingthose to int64; but it would definitely be a large dollop of additionalAPI churn on top of this, and it would only help 32-bit platforms whichseem relatively less likely to see any benefit.Andreas Scherbaum, reviewed by Christian Ullrich, additional hacking by me
1 parente011575 commit23a27b0

File tree

32 files changed

+273
-181
lines changed

32 files changed

+273
-181
lines changed

‎contrib/auto_explain/auto_explain.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ void_PG_fini(void);
6161
staticvoidexplain_ExecutorStart(QueryDesc*queryDesc,inteflags);
6262
staticvoidexplain_ExecutorRun(QueryDesc*queryDesc,
6363
ScanDirectiondirection,
64-
longcount);
64+
uint64count);
6565
staticvoidexplain_ExecutorFinish(QueryDesc*queryDesc);
6666
staticvoidexplain_ExecutorEnd(QueryDesc*queryDesc);
6767

@@ -257,7 +257,7 @@ explain_ExecutorStart(QueryDesc *queryDesc, int eflags)
257257
* ExecutorRun hook: all we need do is track nesting depth
258258
*/
259259
staticvoid
260-
explain_ExecutorRun(QueryDesc*queryDesc,ScanDirectiondirection,longcount)
260+
explain_ExecutorRun(QueryDesc*queryDesc,ScanDirectiondirection,uint64count)
261261
{
262262
nesting_level++;
263263
PG_TRY();

‎contrib/pg_stat_statements/pg_stat_statements.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ static void pgss_post_parse_analyze(ParseState *pstate, Query *query);
289289
staticvoidpgss_ExecutorStart(QueryDesc*queryDesc,inteflags);
290290
staticvoidpgss_ExecutorRun(QueryDesc*queryDesc,
291291
ScanDirectiondirection,
292-
longcount);
292+
uint64count);
293293
staticvoidpgss_ExecutorFinish(QueryDesc*queryDesc);
294294
staticvoidpgss_ExecutorEnd(QueryDesc*queryDesc);
295295
staticvoidpgss_ProcessUtility(Node*parsetree,constchar*queryString,
@@ -866,7 +866,7 @@ pgss_ExecutorStart(QueryDesc *queryDesc, int eflags)
866866
* ExecutorRun hook: all we need do is track nesting depth
867867
*/
868868
staticvoid
869-
pgss_ExecutorRun(QueryDesc*queryDesc,ScanDirectiondirection,longcount)
869+
pgss_ExecutorRun(QueryDesc*queryDesc,ScanDirectiondirection,uint64count)
870870
{
871871
nested_level++;
872872
PG_TRY();
@@ -1001,13 +1001,7 @@ pgss_ProcessUtility(Node *parsetree, const char *queryString,
10011001
/* parse command tag to retrieve the number of affected rows. */
10021002
if (completionTag&&
10031003
strncmp(completionTag,"COPY ",5)==0)
1004-
{
1005-
#ifdefHAVE_STRTOULL
1006-
rows=strtoull(completionTag+5,NULL,10);
1007-
#else
1008-
rows=strtoul(completionTag+5,NULL,10);
1009-
#endif
1010-
}
1004+
rows=pg_strtouint64(completionTag+5,NULL,10);
10111005
else
10121006
rows=0;
10131007

‎contrib/spi/refint.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ check_foreign_key(PG_FUNCTION_ARGS)
593593
else
594594
{
595595
#ifdefREFINT_VERBOSE
596-
elog(NOTICE,"%s:%d tuple(s) of %s are %s",
596+
elog(NOTICE,"%s:"UINT64_FORMAT" tuple(s) of %s are %s",
597597
trigger->tgname,SPI_processed,relname,
598598
(action=='c') ?"deleted" :"set to null");
599599
#endif

‎contrib/tablefunc/tablefunc.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ typedef struct
120120
typedefstructcrosstab_cat_desc
121121
{
122122
char*catname;/* full category name */
123-
intattidx;/* zero based */
123+
uint64attidx;/* zero based */
124124
}crosstab_cat_desc;
125125

126126
#defineMAX_CATNAME_LENNAMEDATALEN
@@ -174,8 +174,8 @@ Datum
174174
normal_rand(PG_FUNCTION_ARGS)
175175
{
176176
FuncCallContext*funcctx;
177-
intcall_cntr;
178-
intmax_calls;
177+
uint64call_cntr;
178+
uint64max_calls;
179179
normal_rand_fctx*fctx;
180180
float8mean;
181181
float8stddev;
@@ -352,8 +352,8 @@ crosstab(PG_FUNCTION_ARGS)
352352
ReturnSetInfo*rsinfo= (ReturnSetInfo*)fcinfo->resultinfo;
353353
Tuplestorestate*tupstore;
354354
TupleDesctupdesc;
355-
intcall_cntr;
356-
intmax_calls;
355+
uint64call_cntr;
356+
uint64max_calls;
357357
AttInMetadata*attinmeta;
358358
SPITupleTable*spi_tuptable;
359359
TupleDescspi_tupdesc;
@@ -364,7 +364,7 @@ crosstab(PG_FUNCTION_ARGS)
364364
MemoryContextper_query_ctx;
365365
MemoryContextoldcontext;
366366
intret;
367-
intproc;
367+
uint64proc;
368368

369369
/* check to see if caller supports us returning a tuplestore */
370370
if (rsinfo==NULL|| !IsA(rsinfo,ReturnSetInfo))
@@ -389,7 +389,7 @@ crosstab(PG_FUNCTION_ARGS)
389389
proc=SPI_processed;
390390

391391
/* If no qualifying tuples, fall out early */
392-
if (ret!=SPI_OK_SELECT||proc<=0)
392+
if (ret!=SPI_OK_SELECT||proc==0)
393393
{
394394
SPI_finish();
395395
rsinfo->isDone=ExprEndResult;
@@ -708,7 +708,7 @@ load_categories_hash(char *cats_sql, MemoryContext per_query_ctx)
708708
HTAB*crosstab_hash;
709709
HASHCTLctl;
710710
intret;
711-
intproc;
711+
uint64proc;
712712
MemoryContextSPIcontext;
713713

714714
/* initialize the category hash table */
@@ -740,7 +740,7 @@ load_categories_hash(char *cats_sql, MemoryContext per_query_ctx)
740740
{
741741
SPITupleTable*spi_tuptable=SPI_tuptable;
742742
TupleDescspi_tupdesc=spi_tuptable->tupdesc;
743-
inti;
743+
uint64i;
744744

745745
/*
746746
* The provided categories SQL query must always return one column:
@@ -800,7 +800,7 @@ get_crosstab_tuplestore(char *sql,
800800
char**values;
801801
HeapTupletuple;
802802
intret;
803-
intproc;
803+
uint64proc;
804804

805805
/* initialize our tuplestore (while still in query context!) */
806806
tupstore=tuplestore_begin_heap(randomAccess, false,work_mem);
@@ -823,8 +823,8 @@ get_crosstab_tuplestore(char *sql,
823823
char*rowid;
824824
char*lastrowid=NULL;
825825
boolfirstpass= true;
826-
inti,
827-
j;
826+
uint64i;
827+
intj;
828828
intresult_ncols;
829829

830830
if (num_categories==0)
@@ -1220,7 +1220,7 @@ build_tuplestore_recursively(char *key_fld,
12201220
{
12211221
TupleDesctupdesc=attinmeta->tupdesc;
12221222
intret;
1223-
intproc;
1223+
uint64proc;
12241224
intserial_column;
12251225
StringInfoDatasql;
12261226
char**values;
@@ -1313,7 +1313,7 @@ build_tuplestore_recursively(char *key_fld,
13131313
HeapTuplespi_tuple;
13141314
SPITupleTable*tuptable=SPI_tuptable;
13151315
TupleDescspi_tupdesc=tuptable->tupdesc;
1316-
inti;
1316+
uint64i;
13171317
StringInfoDatabranchstr;
13181318
StringInfoDatachk_branchstr;
13191319
StringInfoDatachk_current_key;

‎contrib/xml2/xpath.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -553,8 +553,7 @@ xpath_table(PG_FUNCTION_ARGS)
553553

554554
intnumpaths;
555555
intret;
556-
intproc;
557-
inti;
556+
uint64proc;
558557
intj;
559558
intrownr;/* For issuing multiple rows from one original
560559
* document */
@@ -664,7 +663,6 @@ xpath_table(PG_FUNCTION_ARGS)
664663
query_buf.data);
665664

666665
proc=SPI_processed;
667-
/* elog(DEBUG1,"xpath_table: SPI returned %d rows",proc); */
668666
tuptable=SPI_tuptable;
669667
spi_tupdesc=tuptable->tupdesc;
670668

@@ -692,6 +690,8 @@ xpath_table(PG_FUNCTION_ARGS)
692690
PG_TRY();
693691
{
694692
/* For each row i.e. document returned from SPI */
693+
uint64i;
694+
695695
for (i=0;i<proc;i++)
696696
{
697697
char*pkey;

‎doc/src/sgml/spi.sgml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,8 @@ SPI_execute("INSERT INTO foo SELECT * FROM bar RETURNING *", false, 5);
400400
typedef struct
401401
{
402402
MemoryContext tuptabcxt; /* memory context of result table */
403-
uint32 alloced; /* number of alloced vals */
404-
uint32 free; /* number of free vals */
403+
uint64 alloced; /* number of alloced vals */
404+
uint64 free; /* number of free vals */
405405
TupleDesc tupdesc; /* row descriptor */
406406
HeapTuple *vals; /* rows */
407407
} SPITupleTable;
@@ -4116,14 +4116,14 @@ INSERT INTO a SELECT * FROM a;
41164116
PG_MODULE_MAGIC;
41174117
#endif
41184118

4119-
int execq(text *sql, int cnt);
4119+
int64 execq(text *sql, int cnt);
41204120

4121-
int
4121+
int64
41224122
execq(text *sql, int cnt)
41234123
{
41244124
char *command;
41254125
int ret;
4126-
int proc;
4126+
uint64 proc;
41274127

41284128
/* Convert given text object to a C string */
41294129
command = text_to_cstring(sql);
@@ -4141,11 +4141,12 @@ execq(text *sql, int cnt)
41414141
TupleDesc tupdesc = SPI_tuptable-&gt;tupdesc;
41424142
SPITupleTable *tuptable = SPI_tuptable;
41434143
char buf[8192];
4144-
int i, j;
4144+
uint64 j;
41454145

41464146
for (j = 0; j &lt; proc; j++)
41474147
{
41484148
HeapTuple tuple = tuptable-&gt;vals[j];
4149+
int i;
41494150

41504151
for (i = 1, buf[0] = 0; i &lt;= tupdesc-&gt;natts; i++)
41514152
snprintf(buf + strlen (buf), sizeof(buf) - strlen(buf), " %s%s",
@@ -4173,9 +4174,9 @@ execq(text *sql, int cnt)
41734174
a shared library (details are in <xref linkend="dfunc">.):
41744175

41754176
<programlisting>
4176-
CREATE FUNCTION execq(text, integer) RETURNSinteger
4177+
CREATE FUNCTION execq(text, integer) RETURNSint8
41774178
AS '<replaceable>filename</replaceable>'
4178-
LANGUAGE C;
4179+
LANGUAGE C STRICT;
41794180
</programlisting>
41804181
</para>
41814182

‎src/backend/commands/createas.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString,
197197
/* save the rowcount if we're given a completionTag to fill */
198198
if (completionTag)
199199
snprintf(completionTag,COMPLETION_TAG_BUFSIZE,
200-
"SELECT%u",queryDesc->estate->es_processed);
200+
"SELECT"UINT64_FORMAT,queryDesc->estate->es_processed);
201201

202202
/* and clean up */
203203
ExecutorFinish(queryDesc);

‎src/backend/commands/portalcmds.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ PerformPortalFetch(FetchStmt *stmt,
148148
char*completionTag)
149149
{
150150
Portalportal;
151-
longnprocessed;
151+
uint64nprocessed;
152152

153153
/*
154154
* Disallow empty-string cursor name (conflicts with protocol-level
@@ -181,7 +181,7 @@ PerformPortalFetch(FetchStmt *stmt,
181181

182182
/* Return command status if wanted */
183183
if (completionTag)
184-
snprintf(completionTag,COMPLETION_TAG_BUFSIZE,"%s%ld",
184+
snprintf(completionTag,COMPLETION_TAG_BUFSIZE,"%s"UINT64_FORMAT,
185185
stmt->ismove ?"MOVE" :"FETCH",
186186
nprocessed);
187187
}
@@ -392,20 +392,14 @@ PersistHoldablePortal(Portal portal)
392392
if (portal->atEnd)
393393
{
394394
/*
395-
* We can handle this case even if posOverflow: just force the
396-
* tuplestore forward to its end. The size of the skip request
397-
* here is arbitrary.
395+
* Just force the tuplestore forward to its end. The size of the
396+
* skip request here is arbitrary.
398397
*/
399398
while (tuplestore_skiptuples(portal->holdStore,1000000, true))
400399
/* continue */ ;
401400
}
402401
else
403402
{
404-
if (portal->posOverflow)/* oops, cannot trust portalPos */
405-
ereport(ERROR,
406-
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
407-
errmsg("could not reposition held cursor")));
408-
409403
tuplestore_rescan(portal->holdStore);
410404

411405
if (!tuplestore_skiptuples(portal->holdStore,

‎src/backend/executor/execMain.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ static void ExecutePlan(EState *estate, PlanState *planstate,
7979
booluse_parallel_mode,
8080
CmdTypeoperation,
8181
boolsendTuples,
82-
longnumberTuples,
82+
uint64numberTuples,
8383
ScanDirectiondirection,
8484
DestReceiver*dest);
8585
staticboolExecCheckRTEPerms(RangeTblEntry*rte);
@@ -278,7 +278,7 @@ standard_ExecutorStart(QueryDesc *queryDesc, int eflags)
278278
*/
279279
void
280280
ExecutorRun(QueryDesc*queryDesc,
281-
ScanDirectiondirection,longcount)
281+
ScanDirectiondirection,uint64count)
282282
{
283283
if (ExecutorRun_hook)
284284
(*ExecutorRun_hook) (queryDesc,direction,count);
@@ -288,7 +288,7 @@ ExecutorRun(QueryDesc *queryDesc,
288288

289289
void
290290
standard_ExecutorRun(QueryDesc*queryDesc,
291-
ScanDirectiondirection,longcount)
291+
ScanDirectiondirection,uint64count)
292292
{
293293
EState*estate;
294294
CmdTypeoperation;
@@ -1521,12 +1521,12 @@ ExecutePlan(EState *estate,
15211521
booluse_parallel_mode,
15221522
CmdTypeoperation,
15231523
boolsendTuples,
1524-
longnumberTuples,
1524+
uint64numberTuples,
15251525
ScanDirectiondirection,
15261526
DestReceiver*dest)
15271527
{
15281528
TupleTableSlot*slot;
1529-
longcurrent_tuple_count;
1529+
uint64current_tuple_count;
15301530

15311531
/*
15321532
* initialize local variables
@@ -1542,7 +1542,7 @@ ExecutePlan(EState *estate,
15421542
* If a tuple count was supplied, we must force the plan to run without
15431543
* parallelism, because we might exit early.
15441544
*/
1545-
if (numberTuples!=0)
1545+
if (numberTuples)
15461546
use_parallel_mode= false;
15471547

15481548
/*

‎src/backend/executor/functions.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -853,15 +853,15 @@ postquel_getnext(execution_state *es, SQLFunctionCachePtr fcache)
853853
else
854854
{
855855
/* Run regular commands to completion unless lazyEval */
856-
longcount= (es->lazyEval) ?1L :0L;
856+
uint64count= (es->lazyEval) ?1 :0;
857857

858858
ExecutorRun(es->qd,ForwardScanDirection,count);
859859

860860
/*
861861
* If we requested run to completion OR there was no tuple returned,
862862
* command must be complete.
863863
*/
864-
result= (count==0L||es->qd->estate->es_processed==0);
864+
result= (count==0||es->qd->estate->es_processed==0);
865865
}
866866

867867
returnresult;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp