|
| 1 | +/* |
| 2 | + Copyright (c) 2023 Intel Corporation |
| 3 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | + you may not use this file except in compliance with the License. |
| 5 | + You may obtain a copy of the License at |
| 6 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | + Unless required by applicable law or agreed to in writing, software |
| 8 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 | + See the License for the specific language governing permissions and |
| 11 | + limitations under the License. |
| 12 | +*/ |
| 13 | + |
1 | 14 | #include "AnalyticalTemplatesExtractor.h" |
2 | 15 | #include <limits> |
3 | 16 | #include <stdexcept> |
4 | 17 | #include <vector> |
5 | 18 | #include "QueryEngine/CostModel/Measurements.h" |
6 | 19 | #include "QueryEngine/RelAlgExecutionUnit.h" |
7 | 20 |
|
| 21 | +std::vector<costmodel::AnalyticalTemplate> AnalyticalTemplatesExtractor::extractTemplates( |
| 22 | + const RelAlgExecutionUnit& ra_exe_unit) const { |
| 23 | + Priority current_priority = std::numeric_limits<Priority>::max(); |
| 24 | + std::vector<costmodel::AnalyticalTemplate> templates; |
8 | 25 |
|
9 | | -std::vector<costmodel::AnalyticalTemplate> AnalyticalTemplatesExtractor::extractTemplates(const RelAlgExecutionUnit &ra_exe_unit) const { |
10 | | - Priority current_priority = std::numeric_limits<Priority>::max(); |
11 | | - std::vector<costmodel::AnalyticalTemplate> templates; |
12 | | - |
13 | | - for (auto [priority, templ]: priotities_) { |
14 | | - if (priority > current_priority) { |
15 | | - return templates; |
16 | | - } |
17 | | - |
18 | | - if (templSuits(ra_exe_unit, templ)) { |
19 | | - current_priority = priority; |
20 | | - templates.push_back(templ); |
21 | | - } |
| 26 | + for (auto [priority, templ] : priotities_) { |
| 27 | + if (priority > current_priority) { |
| 28 | + return templates; |
22 | 29 | } |
23 | 30 |
|
24 | | - return templates; |
25 | | -} |
26 | | - |
27 | | -template <> |
28 | | -bool AnalyticalTemplatesExtractor::templSuits<costmodel::AnalyticalTemplate::GroupBy>(const RelAlgExecutionUnit &ra_exe_unit) const { |
29 | | - return !ra_exe_unit.groupby_exprs.empty(); |
30 | | -} |
31 | | - |
32 | | -template <> |
33 | | -bool AnalyticalTemplatesExtractor::templSuits<costmodel::AnalyticalTemplate::Join>(const RelAlgExecutionUnit &ra_exe_unit) const { |
34 | | - return !ra_exe_unit.join_quals.empty(); |
35 | | -} |
36 | | - |
37 | | -template <> |
38 | | -bool AnalyticalTemplatesExtractor::templSuits<costmodel::AnalyticalTemplate::Scan>(const RelAlgExecutionUnit &ra_exe_unit) const { |
39 | | - return !ra_exe_unit.quals.empty() || !ra_exe_unit.simple_quals.empty(); |
40 | | -} |
41 | | - |
42 | | -template <> |
43 | | -bool AnalyticalTemplatesExtractor::templSuits<costmodel::AnalyticalTemplate::Sort>(const RelAlgExecutionUnit &ra_exe_unit) const { |
44 | | - return !ra_exe_unit.sort_info.order_entries.empty(); |
45 | | -} |
| 31 | + if (templSuits(ra_exe_unit, templ)) { |
| 32 | + current_priority = priority; |
| 33 | + templates.push_back(templ); |
| 34 | + } |
| 35 | + } |
46 | 36 |
|
47 | | -template <> |
48 | | -bool AnalyticalTemplatesExtractor::templSuits<costmodel::AnalyticalTemplate::Reduce>(const RelAlgExecutionUnit &ra_exe_unit) const { |
49 | | - // TODO(bagrorg): currently we don't even |
50 | | - // use Reduce for cost model |
51 | | - return false; |
| 37 | + return templates; |
52 | 38 | } |
53 | 39 |
|
54 | | -bool AnalyticalTemplatesExtractor::templSuits(const RelAlgExecutionUnit &ra_exe_unit, costmodel::AnalyticalTemplate templ) const { |
55 | | - using costmodel::AnalyticalTemplate; |
| 40 | +bool AnalyticalTemplatesExtractor::templSuits(const RelAlgExecutionUnit& ra_exe_unit, |
| 41 | + costmodel::AnalyticalTemplate templ) const { |
| 42 | + using costmodel::AnalyticalTemplate; |
56 | 43 |
|
57 | | - switch (templ) { |
| 44 | + switch (templ) { |
58 | 45 | case AnalyticalTemplate::GroupBy: |
59 | | - return templSuits<AnalyticalTemplate::GroupBy>(ra_exe_unit); |
| 46 | + return !ra_exe_unit.groupby_exprs.empty(); |
60 | 47 | case AnalyticalTemplate::Join: |
61 | | - return templSuits<AnalyticalTemplate::Join>(ra_exe_unit); |
| 48 | + return !ra_exe_unit.join_quals.empty(); |
62 | 49 | case AnalyticalTemplate::Sort: |
63 | | - return templSuits<AnalyticalTemplate::Sort>(ra_exe_unit); |
| 50 | + return !ra_exe_unit.sort_info.order_entries.empty(); |
64 | 51 | case AnalyticalTemplate::Reduce: |
65 | | - return templSuits<AnalyticalTemplate::Reduce>(ra_exe_unit); |
| 52 | + // TODO(bagrorg): currently we don't even |
| 53 | + // use Reduce for cost model |
| 54 | + return false; |
66 | 55 | case AnalyticalTemplate::Scan: |
67 | | - return templSuits<AnalyticalTemplate::Scan>(ra_exe_unit); |
| 56 | + return !ra_exe_unit.quals.empty() || !ra_exe_unit.simple_quals.empty(); |
68 | 57 | default: |
69 | | - throw std::runtime_error("Unknown template for check was given"); |
70 | | - } |
| 58 | + throw std::runtime_error("Unknown template for check was given"); |
| 59 | + } |
71 | 60 | } |
0 commit comments