8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-25 00:03:03 +01:00

Fix problem with distributing sort to deeper RSE, query example:

SELECT
  RDB$RELATION_NAME
FROM
  (SELECT FIRST 10 * FROM RDB$RELATIONS ORDER BY RDB$RELATION_NAME DESC)
ORDER BY
  RDB$RELATION_NAME
This commit is contained in:
arnobrinkman 2005-05-04 08:56:14 +00:00
parent 3b4415b0c5
commit d8764cbdb1

View File

@ -1679,6 +1679,16 @@ static void check_sorts(RecordSelExpr* rse)
while (node) { while (node) {
if (node->nod_type == nod_rse) { if (node->nod_type == nod_rse) {
new_rse = (RecordSelExpr*) node; new_rse = (RecordSelExpr*) node;
// AB: Don't distribute the sort when a FIRST/SKIP is supllied,
// because that will effect the behaviour from the deeper RSE.
if (new_rse->rse_first || new_rse->rse_skip) {
node = NULL;
break;
}
// Walk trough the relations of the RSE and see if a
// matching stream can be found.
if (new_rse->rse_jointype == blr_inner) { if (new_rse->rse_jointype == blr_inner) {
if (new_rse->rse_count == 1) { if (new_rse->rse_count == 1) {
node = new_rse->rse_relation[0]; node = new_rse->rse_relation[0];
@ -1691,12 +1701,14 @@ static void check_sorts(RecordSelExpr* rse)
((USHORT)(IPTR)subNode->nod_arg[e_rel_stream]) == sort_stream && ((USHORT)(IPTR)subNode->nod_arg[e_rel_stream]) == sort_stream &&
new_rse != rse) new_rse != rse)
{ {
// We have found the correct stream
sortStreamFound = true; sortStreamFound = true;
break; break;
} }
} }
if (sortStreamFound) { if (sortStreamFound) {
// Set the sort to the found stream and clear the original sort
new_rse->rse_sorted = sort; new_rse->rse_sorted = sort;
sort = rse->rse_sorted = NULL; sort = rse->rse_sorted = NULL;
} }
@ -1715,6 +1727,7 @@ static void check_sorts(RecordSelExpr* rse)
((USHORT)(IPTR)node->nod_arg[e_rel_stream]) == sort_stream && ((USHORT)(IPTR)node->nod_arg[e_rel_stream]) == sort_stream &&
new_rse && new_rse != rse) new_rse && new_rse != rse)
{ {
// We have found the correct stream, thus apply the sort here
new_rse->rse_sorted = sort; new_rse->rse_sorted = sort;
sort = rse->rse_sorted = NULL; sort = rse->rse_sorted = NULL;
} }