Alexey Antipovsky cfa9a7ff2c 
	
	
	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 
		
	 
		2025-09-22 16:16:37 +04:00 
	 
	
	
	
		 
	
	
		
			
			
			
			
			
			2025-09-10 19:50:26 +01:00 
		 
	
		
			
			
			
			
			
			2025-09-10 19:50:26 +01:00 
		 
	
		
			
			
			
			
			
			2025-09-10 19:50:26 +01:00 
		 
	
		
			
			
			
			
			
			2025-09-10 19:50:26 +01:00 
		 
	
		
			
			
			
			
			
			2022-02-14 14:12:27 -05:00 
		 
	
		
			
			
			
			
			
			2025-02-21 20:01:34 +04:00 
		 
	
		
			
			
			
			
			
			2025-02-21 20:01:34 +04:00 
		 
	
		
			
			
			
			
			
			2022-01-21 16:43:49 +00:00 
		 
	
		
			
			
			
			
			
			2016-01-06 14:08:59 -06:00 
		 
	
		
			
			
			
			
			
			2022-01-21 16:43:49 +00:00 
		 
	
		
			
			
			
			
			
			2022-01-21 16:43:49 +00:00 
		 
	
		
			
			
			
			
			
			2022-01-21 16:43:49 +00:00 
		 
	
		
			
			
			
			
			
			2022-01-21 16:43:49 +00:00 
		 
	
		
			
			
			
			
			
			2025-09-22 16:16:37 +04:00 
		 
	
		
			
			
			
			
			
			2025-09-22 16:16:37 +04:00 
		 
	
		
			
			
			
			
			
			2025-07-04 19:57:49 +04:00 
		 
	
		
			
			
			
			
			
			2025-08-13 13:20:55 +00:00 
		 
	
		
			
			
			
			
			
			2025-08-01 02:56:31 +04:00 
		 
	
		
			
			
			
			
			
			2025-02-21 20:01:34 +04:00 
		 
	
		
			
			
			
			
			
			2025-08-01 02:56:31 +04:00 
		 
	
		
			
			
			
			
			
			2023-03-30 21:18:29 +03:00 
		 
	
		
			
			
			
			
			
			2025-05-15 19:05:38 +04:00 
		 
	
		
			
			
			
			
			
			2025-05-15 19:05:38 +04:00 
		 
	
		
			
			
			
			
			
			2025-09-10 19:50:26 +01:00 
		 
	
		
			
			
			
			
			
			2025-09-10 19:50:26 +01:00 
		 
	
		
			
			
			
			
			
			2023-03-22 23:25:06 +03:00 
		 
	
		
			
			
			
			
			
			2025-02-21 20:01:34 +04:00 
		 
	
		
			
			
			
			
			
			2023-03-02 15:59:42 +00:00 
		 
	
		
			
			
			
			
			
			2022-01-21 16:43:49 +00:00 
		 
	
		
			
			
			
			
			
			2025-02-21 20:01:34 +04:00 
		 
	
		
			
			
			
			
			
			2023-03-22 23:25:06 +03:00 
		 
	
		
			
			
			
			
			
			2025-02-21 20:01:34 +04:00 
		 
	
		
			
			
			
			
			
			2025-09-14 17:16:17 +04:00 
		 
	
		
			
			
			
			
			
			2025-09-10 19:50:26 +01:00 
		 
	
		
			
			
			
			
			
			2025-05-15 19:05:38 +04:00 
		 
	
		
			
			
			
			
			
			2025-07-31 00:32:32 +04:00 
		 
	
		
			
			
			
			
			
			2023-03-22 23:25:06 +03:00 
		 
	
		
			
			
			
			
			
			2025-05-15 19:05:38 +04:00 
		 
	
		
			
			
			
			
			
			2022-01-21 16:43:49 +00:00 
		 
	
		
			
			
			
			
			
			2025-02-21 20:01:34 +04:00 
		 
	
		
			
			
			
			
			
			2022-02-14 14:12:27 -05:00 
		 
	
		
			
			
			
			
			
			2025-05-15 19:05:38 +04:00 
		 
	
		
			
			
			
			
			
			2022-01-21 16:43:49 +00:00 
		 
	
		
			
			
			
			
			
			2022-01-21 16:43:49 +00:00 
		 
	
		
			
			
			
			
			
			2022-01-21 16:43:49 +00:00 
		 
	
		
			
			
			
			
			
			2025-05-15 19:05:38 +04:00 
		 
	
		
			
			
			
			
			
			2022-01-21 16:43:49 +00:00 
		 
	
		
			
			
			
			
			
			2023-09-26 17:01:53 +03:00 
		 
	
		
			
			
			
			
			
			2025-02-21 20:01:34 +04:00 
		 
	
		
			
			
			
			
			
			2023-07-04 12:58:18 -04:00 
		 
	
		
			
			
			
			
			
			2025-05-15 19:05:38 +04:00 
		 
	
		
			
			
			
			
			
			2022-01-21 16:43:49 +00:00 
		 
	
		
			
			
			
			
			
			2022-01-21 16:43:49 +00:00 
		 
	
		
			
			
			
			
			
			2023-03-22 23:25:06 +03:00 
		 
	
		
			
			
			
			
			
			2025-02-21 20:01:34 +04:00 
		 
	
		
			
			
			
			
			
			2025-08-14 19:38:00 +04:00 
		 
	
		
			
			
			
			
			
			2024-12-20 19:11:47 +00:00 
		 
	
		
			
			
			
			
			
			2025-08-01 02:56:31 +04:00 
		 
	
		
			
			
			
			
			
			2025-08-01 02:56:31 +04:00 
		 
	
		
			
			
			
			
			
			2025-02-21 20:01:34 +04:00 
		 
	
		
			
			
			
			
			
			2022-01-21 16:43:49 +00:00 
		 
	
		
			
			
			
			
			
			2022-01-21 16:43:49 +00:00 
		 
	
		
			
			
			
			
			
			2025-09-22 16:16:37 +04:00 
		 
	
		
			
			
			
			
			
			2025-09-10 19:50:26 +01:00 
		 
	
		
			
			
			
			
			
			2025-05-15 19:05:38 +04:00 
		 
	
		
			
			
			
			
			
			2023-08-21 10:38:46 +03:00 
		 
	
		
			
			
			
			
			
			2023-03-22 23:25:06 +03:00 
		 
	
		
			
			
			
			
			
			2025-02-21 20:01:34 +04:00 
		 
	
		
			
			
			
			
			
			2025-09-15 20:22:10 +01:00 
		 
	
		
			
			
			
			
			
			2025-09-15 20:22:10 +01:00 
		 
	
		
			
			
			
			
			
			2025-05-15 19:05:38 +04:00 
		 
	
		
			
			
			
			
			
			2025-02-21 20:01:34 +04:00 
		 
	
		
			
			
			
			
			
			2022-01-21 16:43:49 +00:00 
		 
	
		
			
			
			
			
			
			2025-02-21 20:01:34 +04:00 
		 
	
		
			
			
			
			
			
			2025-02-21 20:01:34 +04:00 
		 
	
		
			
			
			
			
			
			2025-02-21 20:01:34 +04:00 
		 
	
		
			
			
			
			
			
			2025-02-21 20:01:34 +04:00 
		 
	
		
			
			
			
			
			
			2025-09-22 16:16:37 +04:00 
		 
	
		
			
			
			
			
			
			2025-09-22 16:16:37 +04:00 
		 
	
		
			
			
			
			
			
			2025-09-10 19:50:26 +01:00 
		 
	
		
			
			
			
			
			
			2025-09-10 19:50:26 +01:00 
		 
	
		
			
			
			
			
			
			2023-03-22 23:25:06 +03:00 
		 
	
		
			
			
			
			
			
			2025-07-31 00:32:32 +04:00 
		 
	
		
			
			
			
			
			
			2016-01-06 14:08:59 -06:00 
		 
	
		
			
			
			
			
			
			2022-01-21 16:43:49 +00:00 
		 
	
		
			
			
			
			
			
			2022-01-21 16:43:49 +00:00 
		 
	
		
			
			
			
			
			
			2022-01-21 16:43:49 +00:00 
		 
	
		
			
			
			
			
			
			2022-01-21 16:43:49 +00:00 
		 
	
		
			
			
			
			
			
			2022-01-21 16:43:49 +00:00 
		 
	
		
			
			
			
			
			
			2022-01-21 16:43:49 +00:00 
		 
	
		
			
			
			
			
			
			2022-01-21 16:43:49 +00:00 
		 
	
		
			
			
			
			
			
			2022-01-21 16:43:49 +00:00 
		 
	
		
			
			
			
			
			
			2022-01-21 16:43:49 +00:00 
		 
	
		
			
			
			
			
			
			2022-01-21 16:43:49 +00:00 
		 
	
		
			
			
			
			
			
			2022-01-21 16:43:49 +00:00 
		 
	
		
			
			
			
			
			
			2022-01-21 16:43:49 +00:00 
		 
	
		
			
			
			
			
			
			2022-01-21 16:43:49 +00:00 
		 
	
		
			
			
			
			
			
			2022-01-21 16:43:49 +00:00 
		 
	
		
			
			
			
			
			
			2022-01-21 16:43:49 +00:00 
		 
	
		
			
			
			
			
			
			2022-01-21 16:43:49 +00:00 
		 
	
		
			
			
			
			
			
			2022-01-21 16:43:49 +00:00 
		 
	
		
			
			
			
			
			
			2022-01-21 16:43:49 +00:00 
		 
	
		
			
			
			
			
			
			2022-01-21 16:43:49 +00:00 
		 
	
		
			
			
			
			
			
			2022-01-21 16:43:49 +00:00 
		 
	
		
			
			
			
			
			
			2022-01-21 16:43:49 +00:00 
		 
	
		
			
			
			
			
			
			2022-01-21 16:43:49 +00:00 
		 
	
		
			
			
			
			
			
			2022-01-21 16:43:49 +00:00 
		 
	
		
			
			
			
			
			
			2022-01-21 16:43:49 +00:00 
		 
	
		
			
			
			
			
			
			2022-01-21 16:43:49 +00:00 
		 
	
		
			
			
			
			
			
			2022-01-21 16:43:49 +00:00 
		 
	
		
			
			
			
			
			
			2022-01-21 16:43:49 +00:00 
		 
	
		
			
			
			
			
			
			2025-07-31 00:32:32 +04:00 
		 
	
		
			
			
			
			
			
			2023-03-22 23:25:06 +03:00 
		 
	
		
			
			
			
			
			
			2025-02-21 20:01:34 +04:00 
		 
	
		
			
			
			
			
			
			2023-03-22 23:25:06 +03:00 
		 
	
		
			
			
			
			
			
			2025-02-21 20:01:34 +04:00 
		 
	
		
			
			
			
			
			
			2022-01-21 16:43:49 +00:00 
		 
	
		
			
			
			
			
			
			2022-01-21 16:43:49 +00:00 
		 
	
		
			
			
			
			
			
			2025-02-21 20:01:34 +04:00 
		 
	
		
			
			
			
			
			
			2025-05-30 14:05:21 +04:00 
		 
	
		
			
			
			
			
			
			2025-05-15 19:05:38 +04:00