mirror of https://github.com/citusdata/citus.git
Optimize StringJoin() for when prefix-postfix is needed
Before this commit, we required multiple copies of the
same stringInfo if we needed to append/prepend data to
the stringInfo. Now, we optionally get prefix/postfix.
For large string operations, this can save up to %10
memory.
(cherry picked from commit 26fdcb68f0
)
release-11-onder-27-july
parent
2a684e426c
commit
a21a4e128c
|
@ -180,13 +180,31 @@ GeneratePositiveIntSequenceList(int upTo)
|
||||||
/*
|
/*
|
||||||
* StringJoin gets a list of char * and then simply
|
* StringJoin gets a list of char * and then simply
|
||||||
* returns a newly allocated char * joined with the
|
* returns a newly allocated char * joined with the
|
||||||
* given delimiter.
|
* given delimiter. It uses ';' as the delimiter by
|
||||||
|
* default.
|
||||||
*/
|
*/
|
||||||
char *
|
char *
|
||||||
StringJoin(List *stringList, char delimiter)
|
StringJoin(List *stringList, char delimiter)
|
||||||
|
{
|
||||||
|
return StringJoinParams(stringList, delimiter, NULL, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* StringJoin gets a list of char * and then simply
|
||||||
|
* returns a newly allocated char * joined with the
|
||||||
|
* given delimiter, prefix and postfix.
|
||||||
|
*/
|
||||||
|
char *
|
||||||
|
StringJoinParams(List *stringList, char delimiter, char *prefix, char *postfix)
|
||||||
{
|
{
|
||||||
StringInfo joinedString = makeStringInfo();
|
StringInfo joinedString = makeStringInfo();
|
||||||
|
|
||||||
|
if (prefix != NULL)
|
||||||
|
{
|
||||||
|
appendStringInfoString(joinedString, prefix);
|
||||||
|
}
|
||||||
|
|
||||||
const char *command = NULL;
|
const char *command = NULL;
|
||||||
int curIndex = 0;
|
int curIndex = 0;
|
||||||
foreach_ptr(command, stringList)
|
foreach_ptr(command, stringList)
|
||||||
|
@ -199,6 +217,11 @@ StringJoin(List *stringList, char delimiter)
|
||||||
curIndex++;
|
curIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (postfix != NULL)
|
||||||
|
{
|
||||||
|
appendStringInfoString(joinedString, postfix);
|
||||||
|
}
|
||||||
|
|
||||||
return joinedString->data;
|
return joinedString->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -571,13 +571,11 @@ CreateFixPartitionShardIndexNames(Oid parentRelationId, Oid partitionRelationId,
|
||||||
task->taskId = taskId++;
|
task->taskId = taskId++;
|
||||||
task->taskType = DDL_TASK;
|
task->taskType = DDL_TASK;
|
||||||
|
|
||||||
|
char *prefix = "SELECT pg_catalog.citus_run_local_command($$";
|
||||||
|
char *postfix = "$$)";
|
||||||
|
char *string = StringJoinParams(queryStringList, ';', prefix, postfix);
|
||||||
|
|
||||||
char *string = StringJoin(queryStringList, ';');
|
SetTaskQueryString(task, string);
|
||||||
StringInfo commandToRun = makeStringInfo();
|
|
||||||
|
|
||||||
appendStringInfo(commandToRun,
|
|
||||||
"SELECT pg_catalog.citus_run_local_command($$%s$$)", string);
|
|
||||||
SetTaskQueryString(task, commandToRun->data);
|
|
||||||
|
|
||||||
|
|
||||||
task->dependentTaskList = NULL;
|
task->dependentTaskList = NULL;
|
||||||
|
|
|
@ -174,6 +174,8 @@ extern ArrayType * DatumArrayToArrayType(Datum *datumArray, int datumCount,
|
||||||
Oid datumTypeId);
|
Oid datumTypeId);
|
||||||
extern HTAB * ListToHashSet(List *pointerList, Size keySize, bool isStringList);
|
extern HTAB * ListToHashSet(List *pointerList, Size keySize, bool isStringList);
|
||||||
extern char * StringJoin(List *stringList, char delimiter);
|
extern char * StringJoin(List *stringList, char delimiter);
|
||||||
|
extern char * StringJoinParams(List *stringList, char delimiter,
|
||||||
|
char *prefix, char *postfix);
|
||||||
extern List * ListTake(List *pointerList, int size);
|
extern List * ListTake(List *pointerList, int size);
|
||||||
extern void * safe_list_nth(const List *list, int index);
|
extern void * safe_list_nth(const List *list, int index);
|
||||||
extern List * GeneratePositiveIntSequenceList(int upTo);
|
extern List * GeneratePositiveIntSequenceList(int upTo);
|
||||||
|
|
Loading…
Reference in New Issue