GROUP BY PERIOD and PERIOD DISTINCT: Which columns are needed from the CTE subquery on selfnormalization?
List of issues:
- Currently we cannot mix GROUP BY with PERIOD DISTINCT
- GROUP BY PERIOD does not support empty expr_lists after WITH(ts, te)
- PERIOD DISTINCT with * introduces regressions for GROUP BY PERIOD
transformNormalizeSelfRef and transformPeriodWithListClause
Determine which columns are needed from the CTE subquery, and which from the outer query?
/*
* transformPeriodWithListClause -
* transform a GROUP BY PERIOD clause into a GROUP BY clause or transform
* a PERIOD DISTINCT clause into a regular DISTINCT clause.
*/
static List *
transformPeriodWithListClause(SelectStmt *stmt,
List *grouplist,
ColumnRef **range1,
ColumnRef **range2,
List **nonTempAttrib,
bool *hasRangeTypes)
...and...
/*
* transformNormalizeSelfRef -
* transform a SELECT statement into a CTE used by a temporal normalized
* SELECT, that refers to it self.
*
* INPUT: (query with already transformed GROUP BY PERIOD clause) =
* SELECT a1,...,an FROM e1,...,en WHERE f GROUP BY t, a;
* where t can be a range typed temporal bound [ts,te) or two single values
* that form the upper and lower bounds.
*
* OUTPUT:
* WITH unnamed_normalize AS
* (
* SELECT a1,...,an
* FROM e1,...,en
* WHERE f
* )
* SELECT *
* FROM
* (
* unnamed_normalize
* NORMALIZE
* unnamed_normalize unnamed_normalize_2
* USING (a)
* WITH (t, t)
* ) unnamed_normalize
* GROUP BY t, a;
*/
static void
transformNormalizeSelfRef(SelectStmt *stmt,
bool hasRangeTypes,
ColumnRef *range1,
ColumnRef *range2,
List *nonTempAttrib,
bool needAllAttributes)