-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
duckdb.log_pg_subplans
GUC setting
When enabled, dump the query and plan executed by PG during DuckDB execution
- Loading branch information
Showing
7 changed files
with
89 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#pragma once | ||
|
||
#include "pgduckdb/pg/declarations.hpp" | ||
|
||
namespace pgduckdb { | ||
const char *ExplainPGQuery(const char *query_str); | ||
} // namespace pgduckdb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
|
||
extern "C" { | ||
#include "postgres.h" | ||
#include "lib/stringinfo.h" | ||
#include "executor/spi.h" | ||
} | ||
|
||
#include "pgduckdb/pg/explain.hpp" | ||
|
||
namespace pgduckdb { | ||
const char * | ||
ExplainPGQuery(const char *query_str) { | ||
StringInfo explain_query_si = makeStringInfo(); | ||
// Must be created before SPI_connect to be in the right context | ||
StringInfo explain_result_si = makeStringInfo(); | ||
appendStringInfo(explain_query_si, "EXPLAIN (%s)", query_str); | ||
|
||
SPI_connect(); | ||
int ret = SPI_exec(explain_query_si->data, 0); | ||
if (ret != SPI_OK_UTILITY) { | ||
elog(ERROR, "SPI_exec failed: error code %s", SPI_result_code_string(ret)); | ||
} | ||
|
||
for (uint64_t proc = 0; proc < SPI_processed; ++proc) { | ||
HeapTuple tuple = SPI_tuptable->vals[proc]; | ||
char *row = SPI_getvalue(tuple, SPI_tuptable->tupdesc, 1); | ||
appendStringInfo(explain_result_si, "%s\n", row); | ||
} | ||
|
||
SPI_finish(); | ||
return explain_result_si->data; | ||
} | ||
} // namespace pgduckdb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters