Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 245657 - GROUP BY filters out NULL
Summary: GROUP BY filters out NULL
Status: RESOLVED DUPLICATE of bug 246211
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 major with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-08-29 04:54 EDT by Markus KARG CLA
Modified: 2022-06-09 10:29 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Markus KARG CLA 2008-08-29 04:54:22 EDT
Build ID: N/A

Steps To Reproduce:
I found out that when doing "GROUP BY state_field_path_expression" I am getting
a result that has a NULL group (i. e. all NULLs build one group), while I am
getting NO NULL group (i. e. all NULLs are filtered out) when I am doing "GROUP
BY single_valued_association_path_expression). The reason seams to be simple:
single_valued_association_path_expression necessarily contains a dot operator,
which is treated like an INNER JOIN. Unfortunately, this leads to the fact, that
it is impossible get a NULL group as long as the 'X' of "GROUP BY X" is not a
state field. In fact, that it not acceptable, since there is no workaround. You
just lose all NULLs. Neither does the specification clearly tell that in the
GROUP BY description, nor can you do anything to actually get the NULL group.
But getting the NULL group is essential in lots of business use cases.

Example:

If you store the cause for a problem, it might be the case that you just do not
know the cause, so the reason can be NULL. So you would add a relationship from
problem to reason that accepts NULL. Now the boss wants to know the percentage
of reasons, so you do GROUP BY problem.reason. Since reason is a relation, and
due to this reported bug, your boss will never know that for 95% of all problems
you do not know the reasons. As you can see, getting the NULL group is essential.

For us, this is a big problem.

More information:
Bug originall reported to TopLink, see: https://glassfish.dev.java.net/issues/show_bug.cgi?id=5678
Comment 1 Markus KARG CLA 2008-08-29 04:59:14 EDT
Changed severity to major since our application needs the NULL groups essentially, we cannot change the app since it is not EclipseLink specific but vendor transparent, and since executing a second JPA QL command for SOLELY retrieving the NULLs is an unacceptable performance penalty.
Comment 2 Markus KARG CLA 2008-09-04 10:25:26 EDT
see also bug report #246211
Comment 3 Chris Delahunt CLA 2008-09-04 15:06:27 EDT
This is a result of path expressions (A.B) using inner joins.  You can specify that an outer join be used in the form of:
  "Select ...  FROM A a LEFT OUTER JOIN a.b b ... GROUP BY B"
The above statment will use a left outer join from A->B.

Closing as a duplicate of 246211

*** This bug has been marked as a duplicate of bug 246211 ***
Comment 4 Markus KARG CLA 2008-09-05 05:53:22 EDT
(In reply to comment #3)
> This is a result of path expressions (A.B) using inner joins.  You can specify
> that an outer join be used in the form of:
>   "Select ...  FROM A a LEFT OUTER JOIN a.b b ... GROUP BY B"
> The above statment will use a left outer join from A->B.
> 
> Closing as a duplicate of 246211
> 
> *** This bug has been marked as a duplicate of bug 246211 ***
> 

Just wanted to confirm that this idea solved our problem pretty well. The NULL groups are contained in the result as soon as adding a trailing "LEFT JOIN a.b b" that overrides the implicit inner join.

Thanks for this tip, it is a pretty cool workaround! :-)

Unfortunately it implies more complexity for the reader of the code and less performance of the DBMS server, compared to the solution implied in #246211 (not joining the grouped, referenced table at all but GROUP directly over the foreign key which is already joined).

Thanks!
Markus
Comment 5 Eclipse Webmaster CLA 2022-06-09 10:29:57 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink