Skip to content

Commit 38cb1c7

Browse files
committed
Fixed ctas.
1 parent 1405a2d commit 38cb1c7

File tree

2 files changed

+442
-1
lines changed

2 files changed

+442
-1
lines changed

cpp/deeplake_pg/extension_init.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ extern "C" {
3333
#include <commands/defrem.h>
3434
#include <nodes/nodeFuncs.h>
3535
#include <optimizer/planner.h>
36+
#include <parser/parser.h>
3637
#include <postmaster/bgworker.h>
3738
#include <storage/ipc.h>
3839
#include <tcop/utility.h>
@@ -1135,6 +1136,22 @@ static void process_utility(PlannedStmt* pstmt,
11351136
}
11361137
}
11371138

1139+
// Check if the query string represents a pure SELECT statement (not CTAS, INSERT, etc.)
1140+
static bool is_pure_select_statement(const char* query_string)
1141+
{
1142+
if (query_string == nullptr) {
1143+
return false;
1144+
}
1145+
1146+
List* raw_parsetree_list = raw_parser(query_string, RAW_PARSE_DEFAULT);
1147+
if (raw_parsetree_list == NIL) {
1148+
return false;
1149+
}
1150+
1151+
RawStmt* raw_stmt = linitial_node(RawStmt, raw_parsetree_list);
1152+
return nodeTag(raw_stmt->stmt) == T_SelectStmt;
1153+
}
1154+
11381155
static PlannedStmt*
11391156
deeplake_planner(Query* parse, const char* query_string, int32_t cursorOptions, ParamListInfo boundParams)
11401157
{
@@ -1146,7 +1163,7 @@ deeplake_planner(Query* parse, const char* query_string, int32_t cursorOptions,
11461163
}
11471164

11481165
PlannedStmt* planned_stmt = nullptr;
1149-
if (pg::use_deeplake_executor) {
1166+
if (pg::use_deeplake_executor && is_pure_select_statement(query_string)) {
11501167
planned_stmt = deeplake_create_direct_execution_plan(parse, query_string, cursorOptions, boundParams);
11511168
}
11521169

0 commit comments

Comments
 (0)