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

Commite15aae8

Browse files
committed
Avoid statically allocating statement cache in ecpglib/prepare.c.
This removes a megabyte of storage that isn't used at all in ecpglib'sdefault operating mode --- you have to enable auto-prepare to get anyuse out of it. Seems well worth the trouble to allocate on demand.Discussion:https://postgr.es/m/20181015200754.7y7zfuzsoux2c4ya@alap3.anarazel.de
1 parent92dff34 commite15aae8

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

‎src/interfaces/ecpg/ecpglib/prepare.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
#defineSTMTID_SIZE 32
1515

16+
#defineN_STMTCACHE_ENTRIES 16384
17+
1618
typedefstruct
1719
{
1820
intlineno;
@@ -25,7 +27,7 @@ typedef struct
2527
staticintnextStmtID=1;
2628
staticconstintstmtCacheNBuckets=2039;/* # buckets - a prime # */
2729
staticconstintstmtCacheEntPerBucket=8;/* # entries/bucket */
28-
staticstmtCacheEntrystmtCacheEntries[16384]={{0, {0},0,0,0}};
30+
staticstmtCacheEntry*stmtCacheEntries=NULL;
2931

3032
staticbooldeallocate_one(intlineno,enumCOMPAT_MODEc,structconnection*con,
3133
structprepared_statement*prev,structprepared_statement*this);
@@ -362,6 +364,10 @@ SearchStmtCache(const char *ecpgQuery)
362364
intentNo,
363365
entIx;
364366

367+
/* quick failure if cache not set up */
368+
if (stmtCacheEntries==NULL)
369+
return0;
370+
365371
/* hash the statement */
366372
entNo=HashStmt(ecpgQuery);
367373

@@ -397,6 +403,10 @@ ecpg_freeStmtCacheEntry(int lineno, int compat,
397403
structprepared_statement*this,
398404
*prev;
399405

406+
/* fail if cache isn't set up */
407+
if (stmtCacheEntries==NULL)
408+
return-1;
409+
400410
entry=&stmtCacheEntries[entNo];
401411
if (!entry->stmtID[0])/* return if the entry isn't in use */
402412
return0;
@@ -437,6 +447,15 @@ AddStmtToCache(int lineno,/* line # of statement */
437447
entNo;
438448
stmtCacheEntry*entry;
439449

450+
/* allocate and zero cache array if we haven't already */
451+
if (stmtCacheEntries==NULL)
452+
{
453+
stmtCacheEntries= (stmtCacheEntry*)
454+
ecpg_alloc(sizeof(stmtCacheEntry)*N_STMTCACHE_ENTRIES,lineno);
455+
if (stmtCacheEntries==NULL)
456+
return-1;
457+
}
458+
440459
/* hash the statement */
441460
initEntNo=HashStmt(ecpgQuery);
442461

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp