Subject | Strange GROUP BY behavior |
---|---|
Author | Walter Ogston |
Post date | 2005-05-18T20:33:38Z |
Dear friends,
In a query using constant fields (used to control a union) I find that
including constant fields in the GROUP BY is optional. Using IB_SQL,
FBServer 1.5.2.4731 on Windows XP Pro this SQL works:
select
A.department,
0 D1,
sum(B.projected_budget),
1 D2
from department A join proj_dept_budget B
on B.dept_no = A.dept_no
group by 1
as does this one:
select
A.department,
0 D1,
sum(B.projected_budget),
1 D2
from department A join proj_dept_budget B
on B.dept_no = A.dept_no
group by 1, 2
But this one sends the server into a loop, returning row after row with
department blank and SUM <NULL>
select
A.department,
0 D1,
sum(B.projected_budget),
1 D2
from department A join proj_dept_budget B
on B.dept_no = A.dept_no
group by 1, 2, 4
So my question is, does this accord with the SQL specification, or have I
discovered a tricky feature? When I came across this phenomenon in my
application, it had the effect of freezing it up with the SQL hourglass
cursor showing and the server using about 25% of cpu time. I had to kill
the client with the Task Manager. Incidentally, I don't think this problem
happens with FBServer 1.5.2.4231 - It first showed up on my cleint's
server, and I could not reproduce it on my development machine until I
copied his version of FBServer.exe.
/*
C. Walter Ogston
ogstoncw@...
*/
In a query using constant fields (used to control a union) I find that
including constant fields in the GROUP BY is optional. Using IB_SQL,
FBServer 1.5.2.4731 on Windows XP Pro this SQL works:
select
A.department,
0 D1,
sum(B.projected_budget),
1 D2
from department A join proj_dept_budget B
on B.dept_no = A.dept_no
group by 1
as does this one:
select
A.department,
0 D1,
sum(B.projected_budget),
1 D2
from department A join proj_dept_budget B
on B.dept_no = A.dept_no
group by 1, 2
But this one sends the server into a loop, returning row after row with
department blank and SUM <NULL>
select
A.department,
0 D1,
sum(B.projected_budget),
1 D2
from department A join proj_dept_budget B
on B.dept_no = A.dept_no
group by 1, 2, 4
So my question is, does this accord with the SQL specification, or have I
discovered a tricky feature? When I came across this phenomenon in my
application, it had the effect of freezing it up with the SQL hourglass
cursor showing and the server using about 25% of cpu time. I had to kill
the client with the Task Manager. Incidentally, I don't think this problem
happens with FBServer 1.5.2.4231 - It first showed up on my cleint's
server, and I could not reproduce it on my development machine until I
copied his version of FBServer.exe.
/*
C. Walter Ogston
ogstoncw@...
*/