1
0
mirror of synced 2025-02-22 07:03:13 +03:00

[DDC-1985] Fix ordering preservation in SQL limit subquery output walker.

This commit is contained in:
Benjamin Eberlei 2014-02-08 17:01:55 +01:00
parent 1a08b52ab4
commit d31f7ebf57

View File

@ -164,11 +164,8 @@ class LimitSubqueryOutputWalker extends SqlWalker
$sql = sprintf('SELECT DISTINCT %s FROM (%s) dctrn_result', $sql = sprintf('SELECT DISTINCT %s FROM (%s) dctrn_result',
implode(', ', $sqlIdentifier), $innerSql); implode(', ', $sqlIdentifier), $innerSql);
if ($this->platform instanceof PostgreSqlPlatform ||
$this->platform instanceof OraclePlatform) {
// http://www.doctrine-project.org/jira/browse/DDC-1958 // http://www.doctrine-project.org/jira/browse/DDC-1958
$this->preserveSqlOrdering($AST, $sqlIdentifier, $innerSql, $sql); $sql = $this->preserveSqlOrdering($AST, $sqlIdentifier, $innerSql, $sql);
}
// Apply the limit and offset. // Apply the limit and offset.
$sql = $this->platform->modifyLimitQuery( $sql = $this->platform->modifyLimitQuery(
@ -196,7 +193,7 @@ class LimitSubqueryOutputWalker extends SqlWalker
* *
* @return void * @return void
*/ */
public function preserveSqlOrdering(SelectStatement $AST, array $sqlIdentifier, $innerSql, &$sql) public function preserveSqlOrdering(SelectStatement $AST, array $sqlIdentifier, $innerSql, $sql)
{ {
// For every order by, find out the SQL alias by inspecting the ResultSetMapping. // For every order by, find out the SQL alias by inspecting the ResultSetMapping.
$sqlOrderColumns = array(); $sqlOrderColumns = array();
@ -219,11 +216,6 @@ class LimitSubqueryOutputWalker extends SqlWalker
$sqlOrderColumns = array_diff($sqlOrderColumns, $sqlIdentifier); $sqlOrderColumns = array_diff($sqlOrderColumns, $sqlIdentifier);
} }
// We don't need orderBy in inner query.
// However at least on 5.4.6 I'm getting a segmentation fault and thus we don't clear it for now.
/*$AST->orderByClause = null;
$innerSql = parent::walkSelectStatement($AST);*/
if (count($orderBy)) { if (count($orderBy)) {
$sql = sprintf( $sql = sprintf(
'SELECT DISTINCT %s FROM (%s) dctrn_result ORDER BY %s', 'SELECT DISTINCT %s FROM (%s) dctrn_result ORDER BY %s',
@ -232,5 +224,7 @@ class LimitSubqueryOutputWalker extends SqlWalker
implode(', ', $orderBy) implode(', ', $orderBy)
); );
} }
return $sql;
} }
} }