You've already forked mariadb-columnstore-engine
							
							
				mirror of
				https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
				synced 2025-10-30 07:25:34 +03:00 
			
		
		
		
	feat(optimizer): MCOL-5250 rewrite queries with DISTINCT (#3666)
* feat(optimizer): MCOL-5250 rewrite queries with DISTINCT
... as aggregated queries.
So query
```
SELECT DISTINCT <cols list>
FROM <from list>
WHERE <where clause>
HAVING <having clause>
ORDER BY <orderby list>
LIMIT <limit>
```
will become
```
SELECT *
FROM
  (
    SELECT <cols list>
    FROM <from list>
    WHERE <where clause>
    HAVING <having clause>
  ) a
GROUP BY 1,2,3,...,N
ORDER BY <orderby list>
LIMIT limit
```
* move ORDER BY to the outer query
* fix test
* reuse cloneWORecursiveSelects() in clone()
* fix subselect columns processing
			
			
This commit is contained in:
		
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							736ec81e4d
						
					
				
				
					commit
					cfa9a7ff2c
				
			| @@ -15,29 +15,31 @@ | ||||
|    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | ||||
|    MA 02110-1301, USA. */ | ||||
|  | ||||
| #include <algorithm> | ||||
| #include <cstddef> | ||||
| #include <cstdint> | ||||
| #include <limits> | ||||
|  | ||||
| #include "rulebased_optimizer.h" | ||||
|  | ||||
| #include "configcpp.h" | ||||
| #include "constantcolumn.h" | ||||
| #include "execplan/calpontselectexecutionplan.h" | ||||
| #include "execplan/simplecolumn.h" | ||||
| #include "existsfilter.h" | ||||
| #include "logicoperator.h" | ||||
| #include "operator.h" | ||||
| #include "predicateoperator.h" | ||||
| #include "simplefilter.h" | ||||
| #include "rbo_apply_parallel_ces.h" | ||||
| #include "rbo_predicate_pushdown.h" | ||||
| #include "rbo_apply_rewrite_distinct.h" | ||||
| #include "utils/pron/pron.h" | ||||
|  | ||||
| #include "calpontsystemcatalog.h" | ||||
| #include "functioncolumn.h" | ||||
|  | ||||
| namespace optimizer | ||||
| { | ||||
|  | ||||
| std::string getRewrittenSubTableAlias(const execplan::CalpontSystemCatalog::TableAliasName& table, | ||||
|                                       const RBOptimizerContext& ctx) | ||||
| { | ||||
|   static const std::string rewrittenSubTableAliasPrefix{"$added_sub_"}; | ||||
|   return rewrittenSubTableAliasPrefix + table.schema + "_" + table.table + "_" + | ||||
|          std::to_string(ctx.getUniqueId()); | ||||
| } | ||||
|  | ||||
| // Apply a list of rules to a CSEP | ||||
| bool optimizeCSEPWithRules(execplan::CalpontSelectExecutionPlan& root, const std::vector<Rule>& rules, | ||||
|                            optimizer::RBOptimizerContext& ctx) | ||||
| @@ -83,6 +85,10 @@ bool optimizeCSEP(execplan::CalpontSelectExecutionPlan& root, optimizer::RBOptim | ||||
|   { | ||||
|     optimizer::Rule parallelCES{"parallel_ces", optimizer::parallelCESFilter, optimizer::applyParallelCES}; | ||||
|     rules.push_back(parallelCES); | ||||
|  | ||||
|     optimizer::Rule rewriteDistinct{"rewrite_distinct", optimizer::rewriteDistinctFilter, | ||||
|                                     optimizer::applyRewriteDistinct}; | ||||
|     rules.push_back(rewriteDistinct); | ||||
|   } | ||||
|  | ||||
|   optimizer::Rule predicatePushdown{"predicate_pushdown", optimizer::predicatePushdownFilter, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user