diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index 18e9ad7431e836c905a6b3b64655324ad7d79f07..e02939d31f37f2223eb75a14ab974661c299bf8b 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -6969,12 +6969,31 @@ partition_rule_def_worker(PartitionRule *rule, Node *start, if (bLeafTablename) /* MPP-6297: dump by tablename */ { StringInfoData sid1; + PQExpBuffer pqbuf = createPQExpBuffer(); initStringInfo(&sid1); - /* Always quote to make WITH (tablename=...) work correctly */ + /* always quote to make WITH (tablename=...) work correctly */ + /* MPP-12243: but don't use quote_identifier if already quoted! */ + char *relname = get_rel_name(rule->parchildrelid); - appendStringInfo(&sid1, "tablename=%s", quote_literal_internal(relname)); + int len = strlen(relname); + + if(strchr(relname, '\\') != NULL) + appendPQExpBufferChar(pqbuf, ESCAPE_STRING_SYNTAX); + + appendPQExpBufferChar(pqbuf, '\''); + + if(!enlargePQExpBuffer(pqbuf, 2 * len + 2)) + elog(ERROR, "failed to increase buffer size for escaping relname %s", relname); + + pqbuf->len += PQescapeString(pqbuf->data + pqbuf->len, relname, len); + + appendPQExpBufferChar(pqbuf, '\''); + + appendStringInfo(&sid1, "tablename=%s", pqbuf->data); + + destroyPQExpBuffer(pqbuf); /* MPP-7191, MPP-7193: fully-qualify storage type if not * specified (and not a template) @@ -7025,16 +7044,36 @@ partition_rule_def_worker(PartitionRule *rule, Node *start, if (bLeafTablename && part->paristemplate) { - /* - * Make a fake tablename for template entries to invoke special - * dump/restore magic in parse_partition.c:partition_range_every() - * for EVERY. Note that the tablename is ignored during SET - * SUBPARTITION TEMPLATE because the template rules do not have - * corresponding relations (MPP-6297) + /* hackery! */ + /* MPP-6297: Make a fake tablename for template entries to + * invoke special dump/restore magic for EVERY in + * analyze.c:partition_range_every(). Note that the + * tablename is ignored during SET SUBPARTITION TEMPLATE + * because the template rules do not have corresponding + * relations + * + * MPP-10480: use tablename */ + PQExpBuffer pqbuf = createPQExpBuffer(); char *relname = get_rel_name(part->parrelid); - appendStringInfo(&buf, "tablename=%s", quote_literal_internal(relname)); + int len = strlen(relname); + + if(strchr(relname, '\\') != NULL) + appendPQExpBufferChar(pqbuf, ESCAPE_STRING_SYNTAX); + + appendPQExpBufferChar(pqbuf, '\''); + + if(!enlargePQExpBuffer(pqbuf, 2 * len + 2)) + elog(ERROR, "failed to increase buffer size for escaping relname %s", relname); + + pqbuf->len += PQescapeString(pqbuf->data + pqbuf->len, relname, len); + + appendPQExpBufferChar(pqbuf, '\''); + + appendStringInfo(&buf, "tablename=%s", pqbuf->data); + + destroyPQExpBuffer(pqbuf); } opts = rule->parreloptions;