Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SQL identifier quoting, generalize using format %I. #464

Merged
merged 1 commit into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/bin/pgcopydb/cli_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -1185,16 +1185,14 @@ cli_list_table_parts(int argc, char **argv)

if (table->partsArray.count <= 1)
{
log_info("Table \"%s\".\"%s\" (%s) will not be split",
table->nspname,
table->relname,
log_info("Table %s (%s) will not be split",
table->qname,
table->bytesPretty);
exit(EXIT_CODE_QUIT);
}

log_info("Table \"%s\".\"%s\" COPY will be split %d-ways",
table->nspname,
table->relname,
log_info("Table %s COPY will be split %d-ways",
table->qname,
table->partsArray.count);

fformat(stdout, "%12s | %12s | %12s | %12s\n",
Expand Down
64 changes: 25 additions & 39 deletions src/bin/pgcopydb/compare.c
Original file line number Diff line number Diff line change
Expand Up @@ -617,10 +617,9 @@ compare_schemas(CopyDataSpec *copySpecs)
if (targetIndexList == NULL)
{
++diffCount;
log_error("Table %s is missing index \"%s\".\"%s\" on target",
log_error("Table %s is missing index %s on target",
qname,
sourceIndex->indexNamespace,
sourceIndex->indexRelname);
sourceIndex->indexQname);

continue;
}
Expand All @@ -631,68 +630,58 @@ compare_schemas(CopyDataSpec *copySpecs)
!streq(sourceIndex->indexRelname, targetIndex->indexRelname))
{
++diffCount;
log_error("Table %s index mismatch: \"%s\".\"%s\" on source, "
"\"%s\".\"%s\" on target",
log_error("Table %s index mismatch: %s on source, %s on target",
qname,
sourceIndex->indexNamespace,
sourceIndex->indexRelname,
targetIndex->indexNamespace,
targetIndex->indexRelname);
sourceIndex->indexQname,
targetIndex->indexQname);
}

if (!streq(sourceIndex->indexDef, targetIndex->indexDef))
{
++diffCount;
log_error("Table %s index \"%s\".\"%s\" mismatch "
"on index definition",
log_error("Table %s index %s mismatch on index definition",
qname,
sourceIndex->indexNamespace,
sourceIndex->indexRelname);
sourceIndex->indexQname);

log_info("Source index \"%s\".\"%s\": %s",
sourceIndex->indexNamespace,
sourceIndex->indexRelname,
log_info("Source index %s: %s",
sourceIndex->indexQname,
sourceIndex->indexDef);

log_info("Target index \"%s\".\"%s\": %s",
targetIndex->indexNamespace,
targetIndex->indexRelname,
log_info("Target index %s: %s",
targetIndex->indexQname,
targetIndex->indexDef);
}

if (sourceIndex->isPrimary != targetIndex->isPrimary)
{
++diffCount;
log_error("Table %s index \"%s\".\"%s\" is %s on source "
log_error("Table %s index %s is %s on source "
"and %s on target",
qname,
sourceIndex->indexNamespace,
sourceIndex->indexRelname,
sourceIndex->indexQname,
sourceIndex->isPrimary ? "primary" : "not primary",
targetIndex->isPrimary ? "primary" : "not primary");
}

if (sourceIndex->isUnique != targetIndex->isUnique)
{
++diffCount;
log_error("Table %s index \"%s\".\"%s\" is %s on source "
log_error("Table %s index %s is %s on source "
"and %s on target",
qname,
sourceIndex->indexNamespace,
sourceIndex->indexRelname,
sourceIndex->indexQname,
sourceIndex->isUnique ? "unique" : "not unique",
targetIndex->isUnique ? "unique" : "not unique");
}

if (!streq(sourceIndex->constraintName, targetIndex->constraintName))
{
++diffCount;
log_error("Table %s index \"%s\".\"%s\" is supporting "
" constraint named \"%s\" on source "
"and \"%s\" on target",
log_error("Table %s index %s is supporting "
" constraint named %s on source "
"and %s on target",
qname,
sourceIndex->indexNamespace,
sourceIndex->indexRelname,
sourceIndex->indexQname,
sourceIndex->constraintName,
targetIndex->constraintName);
}
Expand All @@ -702,22 +691,19 @@ compare_schemas(CopyDataSpec *copySpecs)
!streq(sourceIndex->constraintDef, targetIndex->constraintDef)))
{
++diffCount;
log_error("Table %s index \"%s\".\"%s\" constraint \"%s\" "
log_error("Table %s index %s constraint %s "
"definition mismatch.",
qname,
sourceIndex->indexNamespace,
sourceIndex->indexRelname,
sourceIndex->indexQname,
sourceIndex->constraintName);

log_info("Source index \"%s\".\"%s\" constraint \"%s\": %s",
sourceIndex->indexNamespace,
sourceIndex->indexRelname,
log_info("Source index %s constraint %s: %s",
sourceIndex->indexQname,
sourceIndex->constraintName,
sourceIndex->constraintDef);

log_info("Target index \"%s\".\"%s\" constraint \"%s\": %s",
targetIndex->indexNamespace,
targetIndex->indexRelname,
log_info("Target index %s constraint %s: %s",
targetIndex->indexQname,
targetIndex->constraintName,
targetIndex->constraintDef);
}
Expand Down
12 changes: 5 additions & 7 deletions src/bin/pgcopydb/copydb_schema.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,9 @@ copydb_prepare_table_specs(CopyDataSpec *specs, PGSQL *pgsql)

if (source->partsArray.count > 1)
{
log_info("Table \"%s\".\"%s\" is %s large, "
"%d COPY processes will be used, partitining on \"%s\".",
source->nspname,
source->relname,
log_info("Table %s is %s large, "
"%d COPY processes will be used, partitioning on %s.",
source->qname,
source->bytesPretty,
source->partsArray.count,
source->partKey);
Expand Down Expand Up @@ -481,11 +480,10 @@ copydb_prepare_index_specs(CopyDataSpec *specs, PGSQL *pgsql)

if (table == NULL)
{
log_error("Failed to find table %u (\"%s\".\"%s\") "
log_error("Failed to find table %u (%s) "
" in sourceTableHashByOid",
oid,
indexArray->array[i].tableNamespace,
indexArray->array[i].tableRelname);
indexArray->array[i].tableQname);
return false;
}

Expand Down
61 changes: 25 additions & 36 deletions src/bin/pgcopydb/indexes.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,10 @@ copydb_create_index_by_oid(CopyDataSpec *specs, uint32_t indexOid)

if (table == NULL)
{
log_error("Failed to find table %u (\"%s\".\"%s\") "
log_error("Failed to find table %u (%s) "
" in sourceTableHashByOid",
oid,
index->tableNamespace,
index->tableRelname);
index->tableQname);
return false;
}

Expand All @@ -208,12 +207,10 @@ copydb_create_index_by_oid(CopyDataSpec *specs, uint32_t indexOid)
return false;
}

log_trace("copydb_create_index_by_oid: %u \"%s.%s\" on \"%s\".\"%s\"",
log_trace("copydb_create_index_by_oid: %u %s on %s",
indexOid,
index->indexNamespace,
index->indexRelname,
table->nspname,
table->relname);
index->indexQname,
table->qname);

/*
* Add IF NOT EXISTS clause when the --resume option has been used, or when
Expand Down Expand Up @@ -264,19 +261,17 @@ copydb_create_index_by_oid(CopyDataSpec *specs, uint32_t indexOid)

if (!copydb_create_constraints(specs, table))
{
log_error("Failed to create constraints for table \"%s\".\"%s\"",
table->nspname,
table->relname);
log_error("Failed to create constraints for table %s",
table->qname);
return false;
}

if (!specs->skipVacuum)
{
if (!vacuum_add_table(specs, table->oid))
{
log_error("Failed to queue VACUUM ANALYZE \"%s\".\"%s\" [%u]",
table->nspname,
table->relname,
log_error("Failed to queue VACUUM ANALYZE %s [%u]",
table->qname,
table->oid);
return false;
}
Expand Down Expand Up @@ -346,9 +341,8 @@ copydb_table_indexes_are_done(CopyDataSpec *specs,
if (!create_table_index_file(table, tablePaths->idxListFile))
{
/* this only means summary is missing some indexing information */
log_warn("Failed to create table \"%s\".\"%s\" index list file \"%s\"",
table->nspname,
table->relname,
log_warn("Failed to create table %s index list file \"%s\"",
table->qname,
tablePaths->idxListFile);
}
}
Expand Down Expand Up @@ -381,9 +375,8 @@ copydb_add_table_indexes(CopyDataSpec *specs, CopyTableDataSpec *tableSpecs)
.data.oid = index->indexOid
};

log_trace("Queueing index \"%s\".\"%s\" [%u] for table %s [%u]",
index->indexNamespace,
index->indexRelname,
log_trace("Queueing index %s [%u] for table %s [%u]",
index->indexQname,
mesg.data.oid,
tableSpecs->sourceTable->qname,
tableSpecs->sourceTable->oid);
Expand Down Expand Up @@ -721,12 +714,11 @@ copydb_create_index(const char *pguri,
{
skipCreateIndex = true;
log_notice("Skipping concurrent build of index "
"\"%s\" for constraint %s on \"%s\".\"%s\", "
"%s for constraint %s on %s, "
"it is not a UNIQUE or a PRIMARY constraint",
index->indexRelname,
index->indexQname,
index->constraintDef,
index->tableNamespace,
index->tableRelname);
index->tableQname);
}

if (!copydb_index_is_being_processed(index,
Expand Down Expand Up @@ -1062,22 +1054,20 @@ copydb_prepare_create_constraint_command(SourceIndex *index, char **command)
char *constraintType = index->isPrimary ? "PRIMARY KEY" : "UNIQUE";

appendPQExpBuffer(cmd,
"ALTER TABLE \"%s\".\"%s\" "
"ADD CONSTRAINT \"%s\" %s "
"USING INDEX \"%s\"",
index->tableNamespace,
index->tableRelname,
"ALTER TABLE %s "
"ADD CONSTRAINT %s %s "
"USING INDEX %s",
index->tableQname,
index->constraintName,
constraintType,
index->indexRelname);
}
else
{
appendPQExpBuffer(cmd,
"ALTER TABLE \"%s\".\"%s\" "
"ADD CONSTRAINT \"%s\" %s ",
index->tableNamespace,
index->tableRelname,
"ALTER TABLE %s "
"ADD CONSTRAINT %s %s ",
index->tableQname,
index->constraintName,
index->constraintDef);
}
Expand Down Expand Up @@ -1167,10 +1157,9 @@ copydb_create_constraints(CopyDataSpec *specs, SourceTable *table)
specs->section == DATA_SECTION_ALL ? LOG_NOTICE : LOG_INFO;

log_level(logLevel,
"Found %d indexes on target database for table \"%s\".\"%s\"",
"Found %d indexes on target database for table %s",
dstIndexArray.count,
table->nspname,
table->relname);
table->qname);
}

SourceIndexList *indexListEntry = table->firstIndex;
Expand Down
7 changes: 7 additions & 0 deletions src/bin/pgcopydb/progress.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ copydb_index_array_as_json(SourceIndexArray *indexArray,
json_object_set_number(jsIndexObj, "oid", (double) index->indexOid);
json_object_set_string(jsIndexObj, "schema", index->indexNamespace);
json_object_set_string(jsIndexObj, "name", index->indexRelname);
json_object_set_string(jsIndexObj, "qname", index->indexQname);

json_object_set_boolean(jsIndexObj, "isPrimary", index->isPrimary);
json_object_set_boolean(jsIndexObj, "isUnique", index->isUnique);
Expand All @@ -447,6 +448,7 @@ copydb_index_array_as_json(SourceIndexArray *indexArray,
json_object_set_number(jsTableObj, "oid", (double) index->tableOid);
json_object_set_string(jsTableObj, "schema", index->tableNamespace);
json_object_set_string(jsTableObj, "name", index->tableRelname);
json_object_set_string(jsTableObj, "qname", index->tableQname);

json_object_set_value(jsIndexObj, "table", jsTable);

Expand Down Expand Up @@ -508,6 +510,7 @@ copydb_seq_array_as_json(SourceSequenceArray *sequenceArray,
json_object_set_number(jsSeqObj, "oid", (double) seq->oid);
json_object_set_string(jsSeqObj, "schema", seq->nspname);
json_object_set_string(jsSeqObj, "name", seq->relname);
json_object_set_string(jsSeqObj, "qname", seq->qname);

json_object_set_number(jsSeqObj, "last-value", (double) seq->lastValue);
json_object_set_boolean(jsSeqObj, "is-called", (double) seq->isCalled);
Expand Down Expand Up @@ -723,13 +726,15 @@ copydb_parse_schema_json_file(CopyDataSpec *copySpecs)

char *schema = (char *) json_object_get_string(jsIndex, "schema");
char *name = (char *) json_object_get_string(jsIndex, "name");
char *qname = (char *) json_object_get_string(jsIndex, "qname");
char *cols = (char *) json_object_get_string(jsIndex, "columns");
char *def = (char *) json_object_get_string(jsIndex, "sql");
char *listName =
(char *) json_object_get_string(jsIndex, "restore-list-name");

strlcpy(index->indexNamespace, schema, sizeof(index->indexNamespace));
strlcpy(index->indexRelname, name, sizeof(index->indexRelname));
strlcpy(index->indexQname, qname, sizeof(index->indexQname));

int lenCols = strlen(cols) + 1;

Expand Down Expand Up @@ -766,9 +771,11 @@ copydb_parse_schema_json_file(CopyDataSpec *copySpecs)

schema = (char *) json_object_dotget_string(jsIndex, "table.schema");
name = (char *) json_object_dotget_string(jsIndex, "table.name");
qname = (char *) json_object_dotget_string(jsIndex, "table.qname");

strlcpy(index->tableNamespace, schema, sizeof(index->tableNamespace));
strlcpy(index->tableRelname, name, sizeof(index->tableRelname));
strlcpy(index->tableQname, name, sizeof(index->tableQname));

if (json_object_has_value(jsIndex, "constraint"))
{
Expand Down
Loading
Loading