LCOV - code coverage report
Current view: top level - src/catalog - Catalog.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 51 84 60.7 %
Date: 2025-03-25 01:19:55 Functions: 8 14 57.1 %
Branches: 85 246 34.6 %

           Branch data     Line data    Source code
       1                 :            : #include <mutable/catalog/Catalog.hpp>
       2                 :            : 
       3                 :            : #include "backend/Interpreter.hpp"
       4                 :            : #include "storage/ColumnStore.hpp"
       5                 :            : #include "storage/PaxStore.hpp"
       6                 :            : #include "storage/RowStore.hpp"
       7                 :            : #include <mutable/catalog/CostFunctionCout.hpp>
       8                 :            : 
       9                 :            : 
      10   [ +  -  +  -  :          1 : using namespace m;
          +  -  +  -  +  
             -  +  -  #  
                      # ]
      11   [ +  -  +  -  :          1 : 
          +  -  +  -  +  
             -  +  -  #  
                      # ]
      12   [ +  -  +  -  :          1 : 
          +  -  +  -  +  
             -  +  -  #  
                      # ]
      13   [ +  -  +  -  :          1 : /*======================================================================================================================
          +  -  +  -  +  
             -  +  -  #  
                      # ]
      14   [ +  -  +  -  :          1 :  * Catalog
          +  -  +  -  +  
             -  +  -  #  
                      # ]
      15                 :            :  *====================================================================================================================*/
      16                 :            : 
      17   [ +  -  +  -  :          1 : Catalog * Catalog::the_catalog_(nullptr);
          +  -  +  -  +  
             -  +  -  #  
                      # ]
      18                 :            : 
      19   [ +  -  +  -  :          3 : Catalog::Catalog()
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
                   +  - ]
      20   [ +  -  +  -  :          2 :     : allocator_(new memory::LinearAllocator())
          +  -  +  -  -  
          +  +  -  +  -  
             +  -  #  # ]
      21                 :            : {
      22                 :            :     /*----- Initialize standard functions. ---------------------------------------------------------------------------*/
      23                 :            : #define M_FUNCTION(NAME, KIND) { \
      24                 :            :     auto name = pool(#NAME); \
      25                 :            :     auto res = standard_functions_.emplace(name, new Function(name, Function::FN_ ## NAME, Function::KIND)); \
      26                 :            :     M_insist(res.second, "function already defined"); \
      27                 :            : }
      28                 :            : #include <mutable/tables/Functions.tbl>
      29                 :            : #undef M_FUNCTION
      30                 :          1 : }
      31                 :            : 
      32                 :            : 
      33                 :          1 : Catalog::~Catalog()
      34                 :            : {
      35   [ +  +  +  - ]:          2 :     for (auto db : databases_)
      36         [ -  + ]:          1 :         delete db.second;
      37   [ +  +  +  - ]:          8 :     for (auto fn : standard_functions_)
      38         [ -  + ]:          7 :         delete fn.second;
      39                 :          1 : }
      40                 :            : 
      41                 :            : __attribute__((constructor(200)))
      42                 :      21580 : Catalog & Catalog::Get()
      43                 :            : {
      44         [ +  + ]:      21580 :     if (not the_catalog_)
      45         [ +  - ]:          1 :         the_catalog_ = new Catalog();
      46                 :      21580 :     return *the_catalog_;
      47                 :          0 : }
      48                 :            : 
      49                 :            : __attribute__((destructor(200)))
      50                 :          1 : void Catalog::Destroy()
      51                 :            : {
      52         [ +  - ]:          1 :     delete Catalog::the_catalog_;
      53                 :          1 :     Catalog::the_catalog_ = nullptr;
      54                 :          1 : }
      55                 :            : 
      56                 :            : /*===== Databases ====================================================================================================*/
      57                 :            : 
      58                 :        472 : Database & Catalog::add_database(ThreadSafePooledString name)
      59                 :            : {
      60                 :        472 :     auto it = databases_.find(name);
      61   [ +  -  #  # ]:        472 :     if (it != databases_.end()) throw std::invalid_argument("database with that name already exist");
      62   [ +  -  +  -  :        472 :     it = databases_.emplace_hint(it, std::move(name), new Database(name));
             +  -  #  # ]
      63                 :        472 :     return *it->second;
      64                 :          0 : }
      65                 :            : 
      66                 :          5 : void Catalog::drop_database(const ThreadSafePooledString &name)
      67                 :          0 : {
      68   [ +  +  +  -  :          6 :     if (has_database_in_use() and get_database_in_use().name == name)
          +  +  +  +  #  
                      # ]
      69         [ +  - ]:          1 :         throw std::invalid_argument("Cannot drop database; currently in use.");
      70                 :          4 :     auto it = databases_.find(name);
      71         [ +  + ]:          4 :     if (it == databases_.end())
      72         [ +  - ]:          1 :         throw std::invalid_argument("Database of that name does not exist.");
      73         [ -  + ]:          3 :     delete it->second;
      74                 :          4 :     databases_.erase(it);
      75                 :          3 : }
      76                 :            : 
      77                 :            : __attribute__((constructor(201)))
      78                 :          1 : static void add_catalog_args()
      79                 :            : {
      80                 :          1 :     Catalog &C = Catalog::Get();
      81                 :            : 
      82                 :            :     /*----- Command-line arguments -----------------------------------------------------------------------------------*/
      83                 :          2 :     C.arg_parser().add<const char*>(
      84                 :            :         /* group=       */ "Catalog",
      85                 :            :         /* short=       */ nullptr,
      86                 :            :         /* long=        */ "--data-layout",
      87                 :            :         /* description= */ "data layout to use",
      88                 :          1 :         [&C] (const char *str) {
      89                 :            :             try {
      90   [ #  #  #  # ]:          0 :                 C.default_data_layout(C.pool(str));
      91         [ #  # ]:          0 :             } catch (std::invalid_argument) {
      92   [ #  #  #  #  :          0 :                 std::cerr << "There is no data layout with the name \"" << str << "\".\n";
                   #  # ]
      93                 :          0 :                 std::exit(EXIT_FAILURE);
      94         [ #  # ]:          0 :             }
      95                 :          0 :         }
      96                 :            :     );
      97                 :          2 :     C.arg_parser().add<const char*>(
      98                 :            :         /* group=       */ "Catalog",
      99                 :            :         /* short=       */ nullptr,
     100                 :            :         /* long=        */ "--cardinality-estimator",
     101                 :            :         /* description= */ "cardinality estimator to use",
     102                 :          1 :         [&C] (const char *str) {
     103                 :            :             try {
     104   [ #  #  #  # ]:          0 :                 C.default_cardinality_estimator(C.pool(str));
     105         [ #  # ]:          0 :             } catch (std::invalid_argument) {
     106   [ #  #  #  #  :          0 :                 std::cerr << "There is no cardinality estimator with the name \"" << str << "\".\n";
                   #  # ]
     107                 :          0 :                 std::exit(EXIT_FAILURE);
     108         [ #  # ]:          0 :             }
     109                 :          0 :         }
     110                 :            :     );
     111                 :          2 :     C.arg_parser().add<const char*>(
     112                 :            :         /* group=       */ "Catalog",
     113                 :            :         /* short=       */ nullptr,
     114                 :            :         /* long=        */ "--plan-enumerator",
     115                 :            :         /* description= */ "plan enumerator to use",
     116                 :          1 :         [&C] (const char *str) {
     117                 :            :             try {
     118   [ #  #  #  # ]:          0 :                 C.default_plan_enumerator(C.pool(str));
     119         [ #  # ]:          0 :             } catch (std::invalid_argument) {
     120   [ #  #  #  #  :          0 :                 std::cerr << "There is no plan enumerator with the name \"" << str << "\".\n";
                   #  # ]
     121                 :          0 :                 std::exit(EXIT_FAILURE);
     122         [ #  # ]:          0 :             }
     123                 :          0 :         }
     124                 :            :     );
     125                 :          2 :     C.arg_parser().add<const char*>(
     126                 :            :         /* group=       */ "Catalog",
     127                 :            :         /* short=       */ nullptr,
     128                 :            :         /* long=        */ "--backend",
     129                 :            :         /* description= */ "execution backend to use",
     130                 :          1 :         [&C] (const char *str) {
     131                 :            :             try {
     132   [ #  #  #  # ]:          0 :                 C.default_backend(C.pool(str));
     133         [ #  # ]:          0 :             } catch (std::invalid_argument) {
     134   [ #  #  #  #  :          0 :                 std::cerr << "There is no execution backend with the name \"" << str << "\".\n";
                   #  # ]
     135                 :          0 :                 std::exit(EXIT_FAILURE);
     136         [ #  # ]:          0 :             }
     137                 :          0 :         }
     138                 :            :     );
     139                 :          2 :     C.arg_parser().add<const char*>(
     140                 :            :         /* group=       */ "Catalog",
     141                 :            :         /* short=       */ nullptr,
     142                 :            :         /* long=        */ "--scheduler",
     143                 :            :         /* description= */ "query scheduler to use",
     144                 :          1 :         [&C] (const char *str) {
     145                 :            :             try {
     146   [ #  #  #  # ]:          0 :                 C.default_scheduler(C.pool(str));
     147         [ #  # ]:          0 :             } catch (std::invalid_argument) {
     148   [ #  #  #  #  :          0 :                 std::cerr << "There is no query scheduler with the name \"" << str << "\".\n";
                   #  # ]
     149                 :          0 :                 std::exit(EXIT_FAILURE);
     150         [ #  # ]:          0 :             }
     151                 :          0 :         }
     152                 :            :     );
     153                 :          1 : }

Generated by: LCOV version 1.16