quickstep-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zu...@apache.org
Subject incubator-quickstep git commit: Removed the redundant query id in the optimizer. [Forced Update!]
Date Tue, 02 Aug 2016 07:11:45 GMT
Repository: incubator-quickstep
Updated Branches:
  refs/heads/optimizer-q-id f565f33a4 -> d0d630237 (forced update)


Removed the redundant query id in the optimizer.


Project: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/commit/d0d63023
Tree: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/tree/d0d63023
Diff: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/diff/d0d63023

Branch: refs/heads/optimizer-q-id
Commit: d0d630237f3f1426d2238b4b3759c253cb0b9833
Parents: ccea2ff
Author: Zuyu Zhang <zuyuz@twitter.com>
Authored: Mon Aug 1 23:02:37 2016 -0700
Committer: Zuyu Zhang <zuyuz@twitter.com>
Committed: Tue Aug 2 00:11:14 2016 -0700

----------------------------------------------------------------------
 cli/tests/CommandExecutorTestRunner.cpp         |  5 ++---
 query_optimizer/ExecutionGenerator.cpp          |  4 +++-
 query_optimizer/ExecutionGenerator.hpp          |  2 ++
 query_optimizer/Optimizer.hpp                   |  9 ++-------
 query_optimizer/OptimizerContext.cpp            |  2 --
 query_optimizer/OptimizerContext.hpp            | 20 ++------------------
 query_optimizer/QueryProcessor.cpp              | 10 ++--------
 query_optimizer/QueryProcessor.hpp              |  7 +++++++
 .../tests/ExecutionGeneratorTestRunner.cpp      |  5 ++---
 query_optimizer/tests/OptimizerTest.cpp         |  3 +--
 .../tests/OptimizerTextTestRunner.cpp           |  3 +--
 11 files changed, 24 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/d0d63023/cli/tests/CommandExecutorTestRunner.cpp
----------------------------------------------------------------------
diff --git a/cli/tests/CommandExecutorTestRunner.cpp b/cli/tests/CommandExecutorTestRunner.cpp
index bd7082f..dc7e43f 100644
--- a/cli/tests/CommandExecutorTestRunner.cpp
+++ b/cli/tests/CommandExecutorTestRunner.cpp
@@ -76,8 +76,7 @@ void CommandExecutorTestRunner::runTestCase(
   while (true) {
     ParseResult result = sql_parser_.getNextStatement();
 
-    O::OptimizerContext optimizer_context(0 /* query_id */,
-                                          test_database_loader_.catalog_database(),
+    O::OptimizerContext optimizer_context(test_database_loader_.catalog_database(),
                                           test_database_loader_.storage_manager());
 
     if (result.condition != ParseResult::kSuccess) {
@@ -99,7 +98,7 @@ void CommandExecutorTestRunner::runTestCase(
               nullptr,
               output_stream.file());
         } else  {
-          QueryHandle query_handle(optimizer_context.query_id());
+          QueryHandle query_handle(0 /* query_id */);
           O::LogicalGenerator logical_generator(&optimizer_context);
           O::PhysicalGenerator physical_generator;
           O::ExecutionGenerator execution_generator(&optimizer_context, &query_handle);

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/d0d63023/query_optimizer/ExecutionGenerator.cpp
----------------------------------------------------------------------
diff --git a/query_optimizer/ExecutionGenerator.cpp b/query_optimizer/ExecutionGenerator.cpp
index 88103df..b3d3941 100644
--- a/query_optimizer/ExecutionGenerator.cpp
+++ b/query_optimizer/ExecutionGenerator.cpp
@@ -26,6 +26,8 @@
 #include <type_traits>
 #include <unordered_map>
 
+#include "query_optimizer/QueryOptimizerConfig.h"  // For QUICKSTEP_DISTRIBUTED.
+
 #ifdef QUICKSTEP_DISTRIBUTED
 #include <unordered_set>
 #endif
@@ -299,7 +301,7 @@ void ExecutionGenerator::generatePlanInternal(
 std::string ExecutionGenerator::getNewRelationName() {
   std::ostringstream out;
   out << OptimizerContext::kInternalTemporaryRelationNamePrefix
-      << optimizer_context_->query_id() << "_" << rel_id_;
+      << query_handle_->query_id() << "_" << rel_id_;
   ++rel_id_;
   return out.str();
 }

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/d0d63023/query_optimizer/ExecutionGenerator.hpp
----------------------------------------------------------------------
diff --git a/query_optimizer/ExecutionGenerator.hpp b/query_optimizer/ExecutionGenerator.hpp
index 9186707..adfed4a 100644
--- a/query_optimizer/ExecutionGenerator.hpp
+++ b/query_optimizer/ExecutionGenerator.hpp
@@ -24,6 +24,8 @@
 #include <string>
 #include <unordered_map>
 
+#include "query_optimizer/QueryOptimizerConfig.h"  // For QUICKSTEP_DISTRIBUTED.
+
 #ifdef QUICKSTEP_DISTRIBUTED
 #include <unordered_set>
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/d0d63023/query_optimizer/Optimizer.hpp
----------------------------------------------------------------------
diff --git a/query_optimizer/Optimizer.hpp b/query_optimizer/Optimizer.hpp
index 9177414..18c927d 100644
--- a/query_optimizer/Optimizer.hpp
+++ b/query_optimizer/Optimizer.hpp
@@ -18,8 +18,6 @@
 #ifndef QUICKSTEP_QUERY_OPTIMIZER_OPTIMIZER_HPP_
 #define QUICKSTEP_QUERY_OPTIMIZER_OPTIMIZER_HPP_
 
-#include <cstddef>
-
 #include "query_optimizer/OptimizerContext.hpp"
 #include "utility/Macros.hpp"
 
@@ -45,15 +43,12 @@ class Optimizer {
   /**
    * @brief Constructor.
    *
-   * @param query_id The query id. Used to identify a query and create distinct
-   *        names for temporary relations.
    * @param database The database that the query is executed on.
    * @param storage_manager The storage manager for the database.
    */
-  Optimizer(const std::size_t query_id,
-            CatalogDatabase *database,
+  Optimizer(CatalogDatabase *database,
             StorageManager *storage_manager)
-      : optimizer_context_(query_id, database, storage_manager) {}
+      : optimizer_context_(database, storage_manager) {}
 
   /**
    * @brief Destructor.

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/d0d63023/query_optimizer/OptimizerContext.cpp
----------------------------------------------------------------------
diff --git a/query_optimizer/OptimizerContext.cpp b/query_optimizer/OptimizerContext.cpp
index 4bdd24e..82cfcae 100644
--- a/query_optimizer/OptimizerContext.cpp
+++ b/query_optimizer/OptimizerContext.cpp
@@ -17,8 +17,6 @@
 
 #include "query_optimizer/OptimizerContext.hpp"
 
-#include <string>
-
 namespace quickstep {
 namespace optimizer {
 

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/d0d63023/query_optimizer/OptimizerContext.hpp
----------------------------------------------------------------------
diff --git a/query_optimizer/OptimizerContext.hpp b/query_optimizer/OptimizerContext.hpp
index abdc7f4..bcab9d0 100644
--- a/query_optimizer/OptimizerContext.hpp
+++ b/query_optimizer/OptimizerContext.hpp
@@ -18,18 +18,12 @@
 #ifndef QUICKSTEP_QUERY_OPTIMIZER_OPTIMIZER_CONTEXT_HPP_
 #define QUICKSTEP_QUERY_OPTIMIZER_OPTIMIZER_CONTEXT_HPP_
 
-#include <cstddef>
-#include <cstdlib>
-#include <string>
-
-#include "catalog/CatalogTypedefs.hpp"
 #include "query_optimizer/expressions/ExprId.hpp"
 #include "utility/Macros.hpp"
 
 namespace quickstep {
 
 class CatalogDatabase;
-class CatalogRelation;
 class StorageManager;
 
 namespace optimizer {
@@ -49,16 +43,13 @@ class OptimizerContext {
   /**
    * @brief Constructor.
    *
-   * @param query_id The query ID.
    * @param catalog_database The catalog database where this query is executed.
    * @param storage_manager The storage manager to use for allocating storage
    *        blocks.
    */
-  OptimizerContext(const std::size_t query_id,
-                   CatalogDatabase *catalog_database,
+  OptimizerContext(CatalogDatabase *catalog_database,
                    StorageManager *storage_manager)
-      : query_id_(query_id),
-        current_expr_id_(-1),
+      : current_expr_id_(-1),
         catalog_database_(catalog_database),
         storage_manager_(storage_manager),
         has_nested_queries_(false),
@@ -94,11 +85,6 @@ class OptimizerContext {
   StorageManager* storage_manager() { return storage_manager_; }
 
   /**
-   * @return Query ID.
-   */
-  std::size_t query_id() const { return query_id_; }
-
-  /**
    * @brief Gets the next ExprId.
    *
    * @return A new ExprId.
@@ -133,8 +119,6 @@ class OptimizerContext {
   bool is_catalog_changed() const { return is_catalog_changed_; }
 
  private:
-  const std::size_t query_id_;
-
   expressions::ExprId current_expr_id_;
 
   CatalogDatabase *catalog_database_;

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/d0d63023/query_optimizer/QueryProcessor.cpp
----------------------------------------------------------------------
diff --git a/query_optimizer/QueryProcessor.cpp b/query_optimizer/QueryProcessor.cpp
index 6381d3a..8af4408 100644
--- a/query_optimizer/QueryProcessor.cpp
+++ b/query_optimizer/QueryProcessor.cpp
@@ -17,20 +17,15 @@
 
 #include "query_optimizer/QueryProcessor.hpp"
 
-#include <cstdint>
-#include <cstdlib>
 #include <fstream>
 #include <memory>
 #include <string>
 
 #include "catalog/Catalog.hpp"
 #include "catalog/Catalog.pb.h"
-#include "catalog/CatalogDatabase.hpp"
-#include "catalog/CatalogRelation.hpp"
 #include "parser/ParseStatement.hpp"
 #include "query_optimizer/Optimizer.hpp"
 #include "query_optimizer/QueryHandle.hpp"
-#include "storage/StorageManager.hpp"
 
 using std::ifstream;
 using std::ofstream;
@@ -41,10 +36,9 @@ QueryHandle* QueryProcessor::generateQueryHandle(const ParseStatement &statement
   std::unique_ptr<QueryHandle> query_handle(
       new QueryHandle(query_id_, statement.getPriority()));
 
-  optimizer::Optimizer optimizer(query_id_, getDefaultDatabase(), storage_manager_.get());
-  optimizer.generateQueryHandle(statement, query_handle.get());
+  optimizer_->generateQueryHandle(statement, query_handle.get());
 
-  if (optimizer.isCatalogChanged() && !catalog_altered_) {
+  if (optimizer_->isCatalogChanged() && !catalog_altered_) {
     catalog_altered_ = true;
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/d0d63023/query_optimizer/QueryProcessor.hpp
----------------------------------------------------------------------
diff --git a/query_optimizer/QueryProcessor.hpp b/query_optimizer/QueryProcessor.hpp
index 32739dc..f3844a0 100644
--- a/query_optimizer/QueryProcessor.hpp
+++ b/query_optimizer/QueryProcessor.hpp
@@ -26,6 +26,7 @@
 #include <string>
 
 #include "catalog/Catalog.hpp"
+#include "query_optimizer/Optimizer.hpp"
 #include "storage/StorageManager.hpp"
 #include "utility/Macros.hpp"
 
@@ -139,6 +140,9 @@ class QueryProcessor {
         query_id_(0) {
     loadCatalog();
     storage_manager_.reset(new StorageManager(storage_path));
+
+    // Construct after Catalog loads and StorageManager initializes.
+    optimizer_.reset(new optimizer::Optimizer(getDefaultDatabase(), storage_manager_.get()));
   }
 
   /**
@@ -190,6 +194,9 @@ class QueryProcessor {
 
   std::unique_ptr<Catalog> catalog_;
   std::unique_ptr<StorageManager> storage_manager_;
+
+  std::unique_ptr<optimizer::Optimizer> optimizer_;
+
   bool catalog_altered_;
 
   std::size_t query_id_;

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/d0d63023/query_optimizer/tests/ExecutionGeneratorTestRunner.cpp
----------------------------------------------------------------------
diff --git a/query_optimizer/tests/ExecutionGeneratorTestRunner.cpp b/query_optimizer/tests/ExecutionGeneratorTestRunner.cpp
index 563a777..fd1bb86 100644
--- a/query_optimizer/tests/ExecutionGeneratorTestRunner.cpp
+++ b/query_optimizer/tests/ExecutionGeneratorTestRunner.cpp
@@ -73,8 +73,7 @@ void ExecutionGeneratorTestRunner::runTestCase(
   while (true) {
     ParseResult result = sql_parser_.getNextStatement();
 
-    OptimizerContext optimizer_context(0 /* query_id */,
-                                       test_database_loader_.catalog_database(),
+    OptimizerContext optimizer_context(test_database_loader_.catalog_database(),
                                        test_database_loader_.storage_manager());
 
     if (result.condition != ParseResult::kSuccess) {
@@ -85,7 +84,7 @@ void ExecutionGeneratorTestRunner::runTestCase(
     } else {
       std::printf("%s\n", result.parsed_statement->toString().c_str());
       try {
-        QueryHandle query_handle(optimizer_context.query_id());
+        QueryHandle query_handle(0 /* query_id */);
         LogicalGenerator logical_generator(&optimizer_context);
         PhysicalGenerator physical_generator;
         ExecutionGenerator execution_generator(&optimizer_context,

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/d0d63023/query_optimizer/tests/OptimizerTest.cpp
----------------------------------------------------------------------
diff --git a/query_optimizer/tests/OptimizerTest.cpp b/query_optimizer/tests/OptimizerTest.cpp
index 3734719..57e2d67 100644
--- a/query_optimizer/tests/OptimizerTest.cpp
+++ b/query_optimizer/tests/OptimizerTest.cpp
@@ -59,8 +59,7 @@ OptimizerTest::OptimizerTest()
     : catalog_(new Catalog),
       catalog_database_(
           new CatalogDatabase(catalog_.get(), "TestDatabase" /* name */, 0)),
-      optimizer_context_(new OptimizerContext(0 /* query_id */,
-                                              catalog_database_.get(),
+      optimizer_context_(new OptimizerContext(catalog_database_.get(),
                                               nullptr /* storage_manager */)),
       physical_generator_(new PhysicalGenerator()) {}
 

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/d0d63023/query_optimizer/tests/OptimizerTextTestRunner.cpp
----------------------------------------------------------------------
diff --git a/query_optimizer/tests/OptimizerTextTestRunner.cpp b/query_optimizer/tests/OptimizerTextTestRunner.cpp
index 251b64b..d790c33 100644
--- a/query_optimizer/tests/OptimizerTextTestRunner.cpp
+++ b/query_optimizer/tests/OptimizerTextTestRunner.cpp
@@ -47,8 +47,7 @@ void OptimizerTextTestRunner::runTestCase(const std::string &input,
   sql_parser_.feedNextBuffer(new std::string(input));
   ParseResult result = sql_parser_.getNextStatement();
 
-  OptimizerContext optimizer_context(0 /* query_id */,
-                                     test_database_loader_.catalog_database(),
+  OptimizerContext optimizer_context(test_database_loader_.catalog_database(),
                                      nullptr /* storage_manager */);
   if (result.condition != ParseResult::kSuccess) {
     *output = result.error_message;


Mime
View raw message