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

Function ExecuteSqlString

src/backend/task/pg_cron.c:1838–1976  ·  view source on GitHub ↗

* Execute given SQL string without SPI or a libpq session. */

Source from the content-addressed store, hash-verified

1836 * Execute given SQL string without SPI or a libpq session.
1837 */
1838static void
1839ExecuteSqlString(const char *sql)
1840{
1841 List *raw_parsetree_list;
1842 ListCell *lc1;
1843 bool isTopLevel;
1844 int commands_remaining;
1845 MemoryContext parsecontext;
1846 MemoryContext oldcontext;
1847
1848 /*
1849 * Parse the SQL string into a list of raw parse trees.
1850 *
1851 * Because we allow statements that perform internal transaction control,
1852 * we can't do this in TopTransactionContext; the parse trees might get
1853 * blown away before we're done executing them.
1854 */
1855 parsecontext = AllocSetContextCreate(TopMemoryContext,
1856 "pg_cron parse/plan",
1857 ALLOCSET_DEFAULT_MINSIZE,
1858 ALLOCSET_DEFAULT_INITSIZE,
1859 ALLOCSET_DEFAULT_MAXSIZE);
1860 oldcontext = MemoryContextSwitchTo(parsecontext);
1861 raw_parsetree_list = pg_parse_query(sql);
1862 commands_remaining = list_length(raw_parsetree_list);
1863 isTopLevel = commands_remaining == 1;
1864 MemoryContextSwitchTo(oldcontext);
1865
1866 /*
1867 * Do parse analysis, rule rewrite, planning, and execution for each raw
1868 * parsetree. We must fully execute each query before beginning parse
1869 * analysis on the next one, since there may be interdependencies.
1870 */
1871 foreach(lc1, raw_parsetree_list)
1872 {
1873 RawStmt *parsetree = (RawStmt *) lfirst(lc1);
1874 CommandTag commandTag;
1875 QueryCompletion qc;
1876 List *querytree_list;
1877 List *plantree_list;
1878 bool snapshot_set = false;
1879 Portal portal;
1880 DestReceiver *receiver;
1881 int16 format = 1;
1882
1883 /*
1884 * We don't allow transaction-control commands like COMMIT and ABORT
1885 * here. The entire SQL statement is executed as a single transaction
1886 * which commits if no errors are encountered.
1887 */
1888 if (IsA(parsetree, TransactionStmt))
1889 ereport(ERROR,
1890 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1891 errmsg("transaction control statements are not allowed in pg_cron")));
1892
1893 /*
1894 * Get the command name for use in status display (it also becomes the
1895 * default completion tag, down inside PortalRun). Set ps_status and

Callers 1

CronBackgroundWorkerFunction · 0.85

Calls 15

MemoryContextSwitchToFunction · 0.85
pg_parse_queryFunction · 0.85
list_lengthFunction · 0.85
CreateCommandTagFunction · 0.85
set_ps_displayFunction · 0.85
GetCommandTagNameFunction · 0.85
BeginCommandFunction · 0.85
PushActiveSnapshotFunction · 0.85
GetTransactionSnapshotFunction · 0.85
pg_analyze_and_rewriteFunction · 0.85
pg_plan_queriesFunction · 0.85

Tested by

no test coverage detected