duckdb 0.3.2-dev62.0 → 0.3.2-dev68.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "duckdb",
3
3
  "main": "./lib/duckdb.js",
4
- "version": "0.3.2-dev62.0",
4
+ "version": "0.3.2-dev68.0",
5
5
  "description": "DuckDB node.js API",
6
6
  "gypfile": true,
7
7
  "dependencies": {
package/src/duckdb.cpp CHANGED
@@ -11177,6 +11177,8 @@ string PhysicalOperatorToString(PhysicalOperatorType type) {
11177
11177
  return "CREATE_INDEX";
11178
11178
  case PhysicalOperatorType::EXPLAIN:
11179
11179
  return "EXPLAIN";
11180
+ case PhysicalOperatorType::EXPLAIN_ANALYZE:
11181
+ return "EXPLAIN_ANALYZE";
11180
11182
  case PhysicalOperatorType::EXECUTE:
11181
11183
  return "EXECUTE";
11182
11184
  case PhysicalOperatorType::VACUUM:
@@ -31970,6 +31972,7 @@ struct ExpressionInfo {
31970
31972
  vector<unique_ptr<ExpressionInfo>> children;
31971
31973
  // Extract ExpressionInformation from a given expression state
31972
31974
  void ExtractExpressionsRecursive(unique_ptr<ExpressionState> &state);
31975
+
31973
31976
  //! Whether or not expression has function
31974
31977
  bool hasfunction;
31975
31978
  //! The function Name
@@ -31985,6 +31988,7 @@ struct ExpressionInfo {
31985
31988
  //! The ExpressionRootInfo keeps information related to the root of an expression tree
31986
31989
  struct ExpressionRootInfo {
31987
31990
  ExpressionRootInfo(ExpressionExecutorState &executor, string name);
31991
+
31988
31992
  //! Count the number of time the executor called
31989
31993
  uint64_t total_count = 0;
31990
31994
  //! Count the number of time the executor called since last sampling
@@ -32008,6 +32012,7 @@ struct ExpressionRootInfo {
32008
32012
  struct ExpressionExecutorInfo {
32009
32013
  explicit ExpressionExecutorInfo() {};
32010
32014
  explicit ExpressionExecutorInfo(ExpressionExecutor &executor, const string &name, int id);
32015
+
32011
32016
  //! A vector which contain the pointer to all ExpressionRootInfo
32012
32017
  vector<unique_ptr<ExpressionRootInfo>> roots;
32013
32018
  //! Id, it will be used as index for executors_info vector
@@ -32015,11 +32020,12 @@ struct ExpressionExecutorInfo {
32015
32020
  };
32016
32021
 
32017
32022
  struct OperatorInformation {
32023
+ explicit OperatorInformation(double time_ = 0, idx_t elements_ = 0) : time(time_), elements(elements_) {
32024
+ }
32025
+
32018
32026
  double time = 0;
32019
32027
  idx_t elements = 0;
32020
32028
  string name;
32021
- explicit OperatorInformation(double time_ = 0, idx_t elements_ = 0) : time(time_), elements(elements_) {
32022
- }
32023
32029
  //! A vector of Expression Executor Info
32024
32030
  vector<unique_ptr<ExpressionExecutorInfo>> executors_info;
32025
32031
  };
@@ -32057,9 +32063,16 @@ class QueryProfiler {
32057
32063
  public:
32058
32064
  DUCKDB_API QueryProfiler()
32059
32065
  : automatic_print_format(ProfilerPrintFormat::NONE), enabled(false), detailed_enabled(false), running(false),
32060
- query_requires_profiling(false) {
32066
+ query_requires_profiling(false), is_explain_analyze(false), stored_enabled(false),
32067
+ stored_automatic_print_format(ProfilerPrintFormat::NONE) {
32061
32068
  }
32062
32069
 
32070
+ //! The format to automatically print query profiling information in (default: disabled)
32071
+ ProfilerPrintFormat automatic_print_format;
32072
+ //! The file to save query profiling information to, instead of printing it to the console (empty = print to
32073
+ //! console)
32074
+ string save_location;
32075
+
32063
32076
  public:
32064
32077
  struct TreeNode {
32065
32078
  PhysicalOperatorType type;
@@ -32103,9 +32116,11 @@ public:
32103
32116
  return detailed_enabled;
32104
32117
  }
32105
32118
 
32106
- DUCKDB_API void StartQuery(string query);
32119
+ DUCKDB_API void StartQuery(string query, bool is_explain_analyze = false);
32107
32120
  DUCKDB_API void EndQuery();
32108
32121
 
32122
+ DUCKDB_API void StartExplainAnalyze();
32123
+
32109
32124
  //! Adds the timings gathered by an OperatorProfiler to this query profiler
32110
32125
  DUCKDB_API void Flush(OperatorProfiler &profiler);
32111
32126
 
@@ -32121,12 +32136,6 @@ public:
32121
32136
  DUCKDB_API string ToJSON() const;
32122
32137
  DUCKDB_API void WriteToFile(const char *path, string &info) const;
32123
32138
 
32124
- //! The format to automatically print query profiling information in (default: disabled)
32125
- ProfilerPrintFormat automatic_print_format;
32126
- //! The file to save query profiling information to, instead of printing it to the console (empty = print to
32127
- //! console)
32128
- string save_location;
32129
-
32130
32139
  idx_t OperatorSize() {
32131
32140
  return tree_map.size();
32132
32141
  }
@@ -32152,6 +32161,11 @@ private:
32152
32161
  //! A map of a Physical Operator pointer to a tree node
32153
32162
  TreeMap tree_map;
32154
32163
 
32164
+ bool is_explain_analyze;
32165
+ bool stored_enabled;
32166
+ ProfilerPrintFormat stored_automatic_print_format;
32167
+ string stored_save_location;
32168
+
32155
32169
  public:
32156
32170
  const TreeMap &GetTreeMap() const {
32157
32171
  return tree_map;
@@ -54034,7 +54048,6 @@ public:
54034
54048
  }
54035
54049
 
54036
54050
  bool ParallelSink() const override {
54037
- // we can only parallelize if all aggregates are combinable
54038
54051
  return true;
54039
54052
  }
54040
54053
  };
@@ -56018,6 +56031,112 @@ PhysicalExecute::PhysicalExecute(PhysicalOperator *plan)
56018
56031
  : PhysicalOperator(PhysicalOperatorType::EXECUTE, plan->types, -1), plan(plan) {
56019
56032
  }
56020
56033
 
56034
+ } // namespace duckdb
56035
+ //===----------------------------------------------------------------------===//
56036
+ // DuckDB
56037
+ //
56038
+ // duckdb/execution/operator/helper/physical_explain_analyze.hpp
56039
+ //
56040
+ //
56041
+ //===----------------------------------------------------------------------===//
56042
+
56043
+
56044
+
56045
+
56046
+
56047
+
56048
+ namespace duckdb {
56049
+
56050
+ class PhysicalExplainAnalyze : public PhysicalOperator {
56051
+ public:
56052
+ PhysicalExplainAnalyze(vector<LogicalType> types)
56053
+ : PhysicalOperator(PhysicalOperatorType::EXPLAIN_ANALYZE, move(types), 1) {
56054
+ }
56055
+
56056
+ public:
56057
+ // Source interface
56058
+ unique_ptr<GlobalSourceState> GetGlobalSourceState(ClientContext &context) const override;
56059
+ void GetData(ExecutionContext &context, DataChunk &chunk, GlobalSourceState &gstate,
56060
+ LocalSourceState &lstate) const override;
56061
+
56062
+ public:
56063
+ // Sink Interface
56064
+ SinkResultType Sink(ExecutionContext &context, GlobalSinkState &state, LocalSinkState &lstate,
56065
+ DataChunk &input) const override;
56066
+ SinkFinalizeType Finalize(Pipeline &pipeline, Event &event, ClientContext &context,
56067
+ GlobalSinkState &gstate) const override;
56068
+
56069
+ unique_ptr<GlobalSinkState> GetGlobalSinkState(ClientContext &context) const override;
56070
+
56071
+ bool IsSink() const override {
56072
+ return true;
56073
+ }
56074
+
56075
+ bool ParallelSink() const override {
56076
+ return true;
56077
+ }
56078
+ };
56079
+
56080
+ } // namespace duckdb
56081
+
56082
+
56083
+
56084
+
56085
+ namespace duckdb {
56086
+
56087
+ //===--------------------------------------------------------------------===//
56088
+ // Sink
56089
+ //===--------------------------------------------------------------------===//
56090
+ class ExplainAnalyzeStateGlobalState : public GlobalSinkState {
56091
+ public:
56092
+ string analyzed_plan;
56093
+ };
56094
+
56095
+ SinkResultType PhysicalExplainAnalyze::Sink(ExecutionContext &context, GlobalSinkState &state, LocalSinkState &lstate,
56096
+ DataChunk &input) const {
56097
+ return SinkResultType::NEED_MORE_INPUT;
56098
+ }
56099
+
56100
+ SinkFinalizeType PhysicalExplainAnalyze::Finalize(Pipeline &pipeline, Event &event, ClientContext &context,
56101
+ GlobalSinkState &gstate_p) const {
56102
+ auto &gstate = (ExplainAnalyzeStateGlobalState &)gstate_p;
56103
+ gstate.analyzed_plan = context.profiler->ToString();
56104
+ return SinkFinalizeType::READY;
56105
+ }
56106
+
56107
+ unique_ptr<GlobalSinkState> PhysicalExplainAnalyze::GetGlobalSinkState(ClientContext &context) const {
56108
+ return make_unique<ExplainAnalyzeStateGlobalState>();
56109
+ }
56110
+
56111
+ //===--------------------------------------------------------------------===//
56112
+ // Source
56113
+ //===--------------------------------------------------------------------===//
56114
+ class ExplainAnalyzeState : public GlobalSourceState {
56115
+ public:
56116
+ ExplainAnalyzeState() : finished(false) {
56117
+ }
56118
+
56119
+ bool finished;
56120
+ };
56121
+
56122
+ unique_ptr<GlobalSourceState> PhysicalExplainAnalyze::GetGlobalSourceState(ClientContext &context) const {
56123
+ return make_unique<ExplainAnalyzeState>();
56124
+ }
56125
+
56126
+ void PhysicalExplainAnalyze::GetData(ExecutionContext &context, DataChunk &chunk, GlobalSourceState &source_state,
56127
+ LocalSourceState &lstate) const {
56128
+ auto &state = (ExplainAnalyzeState &)source_state;
56129
+ auto &gstate = (ExplainAnalyzeStateGlobalState &)*sink_state;
56130
+ if (state.finished) {
56131
+ return;
56132
+ }
56133
+ chunk.SetValue(0, 0, Value("analyzed_plan"));
56134
+ chunk.SetValue(1, 0, Value(gstate.analyzed_plan));
56135
+ chunk.SetCardinality(1);
56136
+
56137
+ state.finished = true;
56138
+ }
56139
+
56021
56140
  } // namespace duckdb
56022
56141
  //===----------------------------------------------------------------------===//
56023
56142
  // DuckDB
@@ -67794,15 +67913,47 @@ unique_ptr<PhysicalOperator> PhysicalPlanGenerator::CreatePlan(LogicalExecute &o
67794
67913
 
67795
67914
 
67796
67915
 
67916
+ //===----------------------------------------------------------------------===//
67917
+ // DuckDB
67918
+ //
67919
+ // duckdb/parser/statement/explain_statement.hpp
67920
+ //
67921
+ //
67922
+ //===----------------------------------------------------------------------===//
67923
+
67924
+
67925
+
67926
+
67927
+
67928
+
67929
+ namespace duckdb {
67930
+
67931
+ enum class ExplainType : uint8_t { EXPLAIN_STANDARD, EXPLAIN_ANALYZE };
67932
+
67933
+ class ExplainStatement : public SQLStatement {
67934
+ public:
67935
+ ExplainStatement(unique_ptr<SQLStatement> stmt, ExplainType explain_type = ExplainType::EXPLAIN_STANDARD);
67936
+
67937
+ unique_ptr<SQLStatement> stmt;
67938
+ ExplainType explain_type;
67939
+
67940
+ public:
67941
+ unique_ptr<SQLStatement> Copy() const override;
67942
+ };
67943
+
67944
+ } // namespace duckdb
67945
+
67797
67946
 
67798
67947
  namespace duckdb {
67799
67948
 
67800
67949
  class LogicalExplain : public LogicalOperator {
67801
67950
  public:
67802
- explicit LogicalExplain(unique_ptr<LogicalOperator> plan) : LogicalOperator(LogicalOperatorType::LOGICAL_EXPLAIN) {
67951
+ LogicalExplain(unique_ptr<LogicalOperator> plan, ExplainType explain_type)
67952
+ : LogicalOperator(LogicalOperatorType::LOGICAL_EXPLAIN), explain_type(explain_type) {
67803
67953
  children.push_back(move(plan));
67804
67954
  }
67805
67955
 
67956
+ ExplainType explain_type;
67806
67957
  string physical_plan;
67807
67958
  string logical_plan_unopt;
67808
67959
  string logical_plan_opt;
@@ -67821,15 +67972,20 @@ protected:
67821
67972
 
67822
67973
 
67823
67974
 
67975
+
67824
67976
  namespace duckdb {
67825
67977
 
67826
67978
  unique_ptr<PhysicalOperator> PhysicalPlanGenerator::CreatePlan(LogicalExplain &op) {
67827
67979
  D_ASSERT(op.children.size() == 1);
67828
67980
  auto logical_plan_opt = op.children[0]->ToString();
67829
67981
  auto plan = CreatePlan(*op.children[0]);
67982
+ if (op.explain_type == ExplainType::EXPLAIN_ANALYZE) {
67983
+ auto result = make_unique<PhysicalExplainAnalyze>(op.types);
67984
+ result->children.push_back(move(plan));
67985
+ return move(result);
67986
+ }
67830
67987
 
67831
67988
  op.physical_plan = plan->ToString();
67832
-
67833
67989
  // the output of the explain
67834
67990
  vector<string> keys, values;
67835
67991
  switch (context.explain_output_type) {
@@ -100962,32 +101118,6 @@ public:
100962
101118
  };
100963
101119
  } // namespace duckdb
100964
101120
 
100965
- //===----------------------------------------------------------------------===//
100966
- // DuckDB
100967
- //
100968
- // duckdb/parser/statement/explain_statement.hpp
100969
- //
100970
- //
100971
- //===----------------------------------------------------------------------===//
100972
-
100973
-
100974
-
100975
-
100976
-
100977
-
100978
- namespace duckdb {
100979
-
100980
- class ExplainStatement : public SQLStatement {
100981
- public:
100982
- explicit ExplainStatement(unique_ptr<SQLStatement> stmt);
100983
-
100984
- unique_ptr<SQLStatement> stmt;
100985
-
100986
- public:
100987
- unique_ptr<SQLStatement> Copy() const override;
100988
- };
100989
-
100990
- } // namespace duckdb
100991
101121
 
100992
101122
  //===----------------------------------------------------------------------===//
100993
101123
  // DuckDB
@@ -101542,6 +101672,17 @@ unique_ptr<QueryResult> ClientContext::RunStatementInternal(ClientContextLock &l
101542
101672
  return ExecutePreparedStatement(lock, query, move(prepared), move(bound_values), allow_stream_result);
101543
101673
  }
101544
101674
 
101675
+ static bool IsExplainAnalyze(SQLStatement *statement) {
101676
+ if (!statement) {
101677
+ return false;
101678
+ }
101679
+ if (statement->type != StatementType::EXPLAIN_STATEMENT) {
101680
+ return false;
101681
+ }
101682
+ auto &explain = (ExplainStatement &)*statement;
101683
+ return explain.explain_type == ExplainType::EXPLAIN_ANALYZE;
101684
+ }
101685
+
101545
101686
  unique_ptr<QueryResult> ClientContext::RunStatementOrPreparedStatement(ClientContextLock &lock, const string &query,
101546
101687
  unique_ptr<SQLStatement> statement,
101547
101688
  shared_ptr<PreparedStatementData> &prepared,
@@ -101573,7 +101714,7 @@ unique_ptr<QueryResult> ClientContext::RunStatementOrPreparedStatement(ClientCon
101573
101714
  statement = move(copied_statement);
101574
101715
  }
101575
101716
  // start the profiler
101576
- profiler->StartQuery(query);
101717
+ profiler->StartQuery(query, IsExplainAnalyze(statement ? statement.get() : prepared->unbound_statement.get()));
101577
101718
  try {
101578
101719
  if (statement) {
101579
101720
  result = RunStatementInternal(lock, query, move(statement), allow_stream_result);
@@ -103361,7 +103502,10 @@ using std::ofstream;
103361
103502
 
103362
103503
  namespace duckdb {
103363
103504
 
103364
- void QueryProfiler::StartQuery(string query) {
103505
+ void QueryProfiler::StartQuery(string query, bool is_explain_analyze) {
103506
+ if (is_explain_analyze) {
103507
+ StartExplainAnalyze();
103508
+ }
103365
103509
  if (!enabled) {
103366
103510
  return;
103367
103511
  }
@@ -103417,6 +103561,17 @@ void QueryProfiler::Finalize(TreeNode &node) {
103417
103561
  }
103418
103562
  }
103419
103563
 
103564
+ void QueryProfiler::StartExplainAnalyze() {
103565
+ this->is_explain_analyze = true;
103566
+ this->stored_enabled = enabled;
103567
+ this->stored_automatic_print_format = automatic_print_format;
103568
+ this->stored_save_location = save_location;
103569
+
103570
+ this->enabled = true;
103571
+ this->save_location = string();
103572
+ this->automatic_print_format = ProfilerPrintFormat::NONE;
103573
+ }
103574
+
103420
103575
  void QueryProfiler::EndQuery() {
103421
103576
  if (!enabled || !running) {
103422
103577
  return;
@@ -103446,6 +103601,12 @@ void QueryProfiler::EndQuery() {
103446
103601
  WriteToFile(save_location.c_str(), query_info);
103447
103602
  }
103448
103603
  }
103604
+ if (is_explain_analyze) {
103605
+ this->is_explain_analyze = false;
103606
+ this->enabled = stored_enabled;
103607
+ this->automatic_print_format = stored_automatic_print_format;
103608
+ this->save_location = stored_save_location;
103609
+ }
103449
103610
  }
103450
103611
 
103451
103612
  void QueryProfiler::StartPhase(string new_phase) {
@@ -116091,6 +116252,7 @@ void Executor::BuildPipelines(PhysicalOperator *op, Pipeline *current) {
116091
116252
  case PhysicalOperatorType::COPY_TO_FILE:
116092
116253
  case PhysicalOperatorType::LIMIT:
116093
116254
  case PhysicalOperatorType::EXPRESSION_SCAN:
116255
+ case PhysicalOperatorType::EXPLAIN_ANALYZE:
116094
116256
  D_ASSERT(op->children.size() == 1);
116095
116257
  // single operator:
116096
116258
  // the operator becomes the data source of the current pipeline
@@ -130333,12 +130495,12 @@ unique_ptr<SQLStatement> ExecuteStatement::Copy() const {
130333
130495
 
130334
130496
  namespace duckdb {
130335
130497
 
130336
- ExplainStatement::ExplainStatement(unique_ptr<SQLStatement> stmt)
130337
- : SQLStatement(StatementType::EXPLAIN_STATEMENT), stmt(move(stmt)) {
130498
+ ExplainStatement::ExplainStatement(unique_ptr<SQLStatement> stmt, ExplainType explain_type)
130499
+ : SQLStatement(StatementType::EXPLAIN_STATEMENT), stmt(move(stmt)), explain_type(explain_type) {
130338
130500
  }
130339
130501
 
130340
130502
  unique_ptr<SQLStatement> ExplainStatement::Copy() const {
130341
- auto result = make_unique<ExplainStatement>(stmt->Copy());
130503
+ auto result = make_unique<ExplainStatement>(stmt->Copy(), explain_type);
130342
130504
  return move(result);
130343
130505
  }
130344
130506
 
@@ -134597,7 +134759,19 @@ namespace duckdb {
134597
134759
  unique_ptr<ExplainStatement> Transformer::TransformExplain(duckdb_libpgquery::PGNode *node) {
134598
134760
  auto stmt = reinterpret_cast<duckdb_libpgquery::PGExplainStmt *>(node);
134599
134761
  D_ASSERT(stmt);
134600
- return make_unique<ExplainStatement>(TransformStatement(stmt->query));
134762
+ auto explain_type = ExplainType::EXPLAIN_STANDARD;
134763
+ if (stmt->options) {
134764
+ for (auto n = stmt->options->head; n; n = n->next) {
134765
+ auto def_elem = ((duckdb_libpgquery::PGDefElem *)n->data.ptr_value)->defname;
134766
+ string elem(def_elem);
134767
+ if (elem == "analyze") {
134768
+ explain_type = ExplainType::EXPLAIN_ANALYZE;
134769
+ } else {
134770
+ throw NotImplementedException("Unimplemented explain type: %s", elem);
134771
+ }
134772
+ }
134773
+ }
134774
+ return make_unique<ExplainStatement>(TransformStatement(stmt->query), explain_type);
134601
134775
  }
134602
134776
 
134603
134777
  } // namespace duckdb
@@ -140190,7 +140364,7 @@ BoundStatement Binder::Bind(ExplainStatement &stmt) {
140190
140364
  auto plan = Bind(*stmt.stmt);
140191
140365
  // get the unoptimized logical plan, and create the explain statement
140192
140366
  auto logical_plan_unopt = plan.plan->ToString();
140193
- auto explain = make_unique<LogicalExplain>(move(plan.plan));
140367
+ auto explain = make_unique<LogicalExplain>(move(plan.plan), stmt.explain_type);
140194
140368
  explain->logical_plan_unopt = logical_plan_unopt;
140195
140369
 
140196
140370
  result.plan = move(explain);
package/src/duckdb.hpp CHANGED
@@ -10,8 +10,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
10
10
 
11
11
  #pragma once
12
12
  #define DUCKDB_AMALGAMATION 1
13
- #define DUCKDB_SOURCE_ID "c51dafbdb"
14
- #define DUCKDB_VERSION "0.3.2-dev62"
13
+ #define DUCKDB_SOURCE_ID "2bbae7746"
14
+ #define DUCKDB_VERSION "0.3.2-dev68"
15
15
  //===----------------------------------------------------------------------===//
16
16
  // DuckDB
17
17
  //
@@ -12697,6 +12697,7 @@ enum class PhysicalOperatorType : uint8_t {
12697
12697
  // Helpers
12698
12698
  // -----------------------------
12699
12699
  EXPLAIN,
12700
+ EXPLAIN_ANALYZE,
12700
12701
  EMPTY_RESULT,
12701
12702
  EXECUTE,
12702
12703
  PREPARE,