MCPcopy Create free account
hub / github.com/apache/cloudberry / expand_table_name_patterns

Function expand_table_name_patterns

src/bin/pg_dump/pg_dump.c:1743–1812  ·  view source on GitHub ↗

* Find the OIDs of all tables matching the given list of patterns, * and append them to the given OID list. See also expand_dbname_patterns() * in pg_dumpall.c */

Source from the content-addressed store, hash-verified

1741 * in pg_dumpall.c
1742 */
1743static void
1744expand_table_name_patterns(Archive *fout,
1745 SimpleStringList *patterns, SimpleOidList *oids,
1746 bool strict_names)
1747{
1748 PQExpBuffer query;
1749 PGresult *res;
1750 SimpleStringListCell *cell;
1751 int i;
1752
1753 if (patterns->head == NULL)
1754 return; /* nothing to do */
1755
1756 query = createPQExpBuffer();
1757
1758 /*
1759 * this might sometimes result in duplicate entries in the OID list, but
1760 * we don't care.
1761 */
1762
1763 for (cell = patterns->head; cell; cell = cell->next)
1764 {
1765 PQExpBufferData dbbuf;
1766 int dotcnt;
1767
1768 /*
1769 * Query must remain ABSOLUTELY devoid of unqualified names. This
1770 * would be unnecessary given a pg_table_is_visible() variant taking a
1771 * search_path argument.
1772 */
1773 appendPQExpBuffer(query,
1774 "SELECT c.oid"
1775 "\nFROM pg_catalog.pg_class c"
1776 "\n LEFT JOIN pg_catalog.pg_namespace n"
1777 "\n ON n.oid OPERATOR(pg_catalog.=) c.relnamespace"
1778 "\nWHERE c.relkind OPERATOR(pg_catalog.=) ANY"
1779 "\n (array['%c', '%c', '%c', '%c', '%c', '%c'])\n",
1780 RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_VIEW,
1781 RELKIND_MATVIEW, RELKIND_FOREIGN_TABLE,
1782 RELKIND_PARTITIONED_TABLE);
1783 initPQExpBuffer(&dbbuf);
1784 processSQLNamePattern(GetConnection(fout), query, cell->val, true,
1785 false, "n.nspname", "c.relname", NULL,
1786 "pg_catalog.pg_table_is_visible(c.oid)", &dbbuf,
1787 &dotcnt);
1788 if (dotcnt > 2)
1789 fatal("improper relation name (too many dotted names): %s",
1790 cell->val);
1791 else if (dotcnt == 2)
1792 prohibit_crossdb_refs(GetConnection(fout), dbbuf.data, cell->val);
1793 termPQExpBuffer(&dbbuf);
1794
1795 ExecuteSqlStatement(fout, "RESET search_path");
1796 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
1797 PQclear(ExecuteSqlQueryForSingleRow(fout,
1798 ALWAYS_SECURE_SEARCH_PATH_SQL));
1799 if (strict_names && PQntuples(res) == 0)
1800 fatal("no matching tables were found for pattern \"%s\"", cell->val);

Callers 1

mainFunction · 0.85

Calls 15

createPQExpBufferFunction · 0.85
appendPQExpBufferFunction · 0.85
initPQExpBufferFunction · 0.85
processSQLNamePatternFunction · 0.85
prohibit_crossdb_refsFunction · 0.85
termPQExpBufferFunction · 0.85
ExecuteSqlStatementFunction · 0.85
ExecuteSqlQueryFunction · 0.85
PQclearFunction · 0.85
PQntuplesFunction · 0.85
simple_oid_list_appendFunction · 0.85

Tested by

no test coverage detected