Re: [xwiki-users] MySQL Error "invalid use of group function" in Statistics application
Hi Jeremie, The sql query you suggested is cleaner and at least as efficient as the current one. It was my first option but unfortunately it's not supported by the newer versions of mysql. I've no idea why.. mysql> select xws_name, sum(xws_page_views) as pageviewcount from xwikistatsdoc where xws_action='view' and xws_name like '%.%' group by xws_name order by pageviewscount desc; ERROR 1054 (42S22): Unknown column 'pageviewscount' in 'order clause' Anyway, hibernate should be responsible for the correct translation from hql to a specific sql dialect. A solution would be to use the (idea from the) above sql but configure the dialect to MySQL5Dialect (in my case). I have to test this. I'll give you feedback soon. Best Regards, Marius.
To be complete, this same error occurs for all the Statistics panels ...
-----Original Message----- From: BOUSQUET Jeremie Sent: lundi 18 février 2008 15:50 To: 'XWiki Users' Subject: RE: [xwiki-users] MySQL Error "invalid use of group function" in Statistics application
Hi Marius and thanks,
Your SQL request returns the same error "invalid use of group function" in my mysql version ...
BTW I could have it work by explicitly naming the sum, and using it in the order by :
select xws_name, sum(xws_page_views) as pageviewcount from xwikistatsdoc where xws_action='view' and xws_name like '%.%' group by xws_name order by pageviewscount desc
I believe it's a difference in behaviour between MySQL 1.4 and 1.5 ... Do you want me to create a JIRA issue for this ?
Best Regards,
Jeremie
-----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Marius Dumitru Florea Sent: lundi 18 février 2008 15:19 To: [email protected] Subject: Re: [xwiki-users] MySQL Error "invalid use of group function" in Statistics application
Hi Jeremie,
Sorry for the inconvenience. Your tables' description seems fine. I attached the description of my tables so you can check it for yourself. I think it all resumes to the following SQL query:
select xws_name, sum(xws_page_views) from xwikistatsdoc where xws_action='view' and xws_name like '%.%' group by xws_name order by sum(xws_page_views) desc
This query is very similar to the one used for retrieving the Most Viewed Pages. It works fine under:
mysql Ver 14.12 Distrib 5.0.45, for pc-linux-gnu (x86_64) using readline 5.2
It would be great if you could run this query and tell me if it works in your case.
Best Regards, Marius. _______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
Marius Dumitru Florea wrote:
Hi Jeremie,
The sql query you suggested is cleaner and at least as efficient as the current one. It was my first option but unfortunately it's not supported by the newer versions of mysql. I've no idea why..
mysql> select xws_name, sum(xws_page_views) as pageviewcount from xwikistatsdoc where xws_action='view' and xws_name like '%.%' group by xws_name order by pageviewscount desc; ERROR 1054 (42S22): Unknown column 'pageviewscount' in 'order clause'
Note that there's a typo: pageviewcount <> pageview-S-count
Anyway, hibernate should be responsible for the correct translation from hql to a specific sql dialect. A solution would be to use the (idea from the) above sql but configure the dialect to MySQL5Dialect (in my case). I have to test this. I'll give you feedback soon.
Best Regards, Marius.
-- Sergiu Dumitriu http://purl.org/net/sergiu/
Right.. but the error persists with the correction made. Not at the same level though. WARN util.JDBCExceptionReporter - SQL Error: 1054, SQLState: 42S22 ERROR util.JDBCExceptionReporter - Unknown column 'pageViewsCount' in 'order clause' The problem is with Hibernate. There is a bug ("missing feature", for them) in the translation from HQL to SQL. The aliases from the Select clause are not resolved correctly in other clauses, including Order By. In this case they "recommend" us to duplicate the expressions from the Select clause, hoping that the RDBMS will take care of the optimization. See for yourself: http://opensource.atlassian.com/projects/hibernate/browse/HHH-892 http://opensource.atlassian.com/projects/hibernate/browse/HHH-1902 http://opensource.atlassian.com/projects/hibernate/browse/HHH-2390 http://forum.hibernate.org/viewtopic.php?t=966075&postdays=0&postorder=asc&s... So, using aliases breaks Hibernate and using expressions in the Order By clause is not supported by MySql 4.1.20. I don't see any clean solution for this. Some options are: * drop the Order By clause and sort on the Java side - No way, I don't think this is feasible. * skip Hibernate layer and use JDBC directly - Doable, the SQL query being not too complicated, but with cross DB issues. * tweak the HQL query - How? Any other options Sergiu? Marius
Marius Dumitru Florea wrote:
Hi Jeremie,
The sql query you suggested is cleaner and at least as efficient as the current one. It was my first option but unfortunately it's not supported by the newer versions of mysql. I've no idea why..
mysql> select xws_name, sum(xws_page_views) as pageviewcount from xwikistatsdoc where xws_action='view' and xws_name like '%.%' group by xws_name order by pageviewscount desc; ERROR 1054 (42S22): Unknown column 'pageviewscount' in 'order clause'
Note that there's a typo: pageviewcount <> pageview-S-count
Anyway, hibernate should be responsible for the correct translation from hql to a specific sql dialect. A solution would be to use the (idea from the) above sql but configure the dialect to MySQL5Dialect (in my case). I have to test this. I'll give you feedback soon.
Best Regards, Marius.
-- Sergiu Dumitriu http://purl.org/net/sergiu/
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
A fourth option (someway similar to the second one) is to use the Native SQL Query feature of Hibernate. Instead of calling session.createQuery(hql) you can call session.createSQLQuery(sql). It works, using aliases. However, I tested it only on MySql and HSQLDB. WDYT? Is this a convenient solution. I would have to switch many of the hql queries from the Statistics Application to sql queries. Marius
Right.. but the error persists with the correction made. Not at the same level though.
WARN util.JDBCExceptionReporter - SQL Error: 1054, SQLState: 42S22 ERROR util.JDBCExceptionReporter - Unknown column 'pageViewsCount' in 'order clause'
The problem is with Hibernate. There is a bug ("missing feature", for them) in the translation from HQL to SQL. The aliases from the Select clause are not resolved correctly in other clauses, including Order By. In this case they "recommend" us to duplicate the expressions from the Select clause, hoping that the RDBMS will take care of the optimization.
See for yourself:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-892 http://opensource.atlassian.com/projects/hibernate/browse/HHH-1902 http://opensource.atlassian.com/projects/hibernate/browse/HHH-2390 http://forum.hibernate.org/viewtopic.php?t=966075&postdays=0&postorder=asc&s...
So, using aliases breaks Hibernate and using expressions in the Order By clause is not supported by MySql 4.1.20. I don't see any clean solution for this. Some options are:
* drop the Order By clause and sort on the Java side - No way, I don't think this is feasible. * skip Hibernate layer and use JDBC directly - Doable, the SQL query being not too complicated, but with cross DB issues. * tweak the HQL query - How?
Any other options Sergiu?
Marius
Marius Dumitru Florea wrote:
Hi Jeremie,
The sql query you suggested is cleaner and at least as efficient as the current one. It was my first option but unfortunately it's not supported by the newer versions of mysql. I've no idea why..
mysql> select xws_name, sum(xws_page_views) as pageviewcount from xwikistatsdoc where xws_action='view' and xws_name like '%.%' group by xws_name order by pageviewscount desc; ERROR 1054 (42S22): Unknown column 'pageviewscount' in 'order clause'
Note that there's a typo: pageviewcount <> pageview-S-count
Anyway, hibernate should be responsible for the correct translation from hql to a specific sql dialect. A solution would be to use the (idea from the) above sql but configure the dialect to MySQL5Dialect (in my case). I have to test this. I'll give you feedback soon.
Best Regards, Marius.
-- Sergiu Dumitriu http://purl.org/net/sergiu/
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
Marius Dumitru Florea wrote:
Right.. but the error persists with the correction made. Not at the same level though.
WARN util.JDBCExceptionReporter - SQL Error: 1054, SQLState: 42S22 ERROR util.JDBCExceptionReporter - Unknown column 'pageViewsCount' in 'order clause'
The problem is with Hibernate. There is a bug ("missing feature", for them) in the translation from HQL to SQL. The aliases from the Select clause are not resolved correctly in other clauses, including Order By. In this case they "recommend" us to duplicate the expressions from the Select clause, hoping that the RDBMS will take care of the optimization.
See for yourself:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-892 http://opensource.atlassian.com/projects/hibernate/browse/HHH-1902 http://opensource.atlassian.com/projects/hibernate/browse/HHH-2390 http://forum.hibernate.org/viewtopic.php?t=966075&postdays=0&postorder=asc&s...
So, using aliases breaks Hibernate and using expressions in the Order By clause is not supported by MySql 4.1.20. I don't see any clean solution for this. Some options are:
* drop the Order By clause and sort on the Java side - No way, I don't think this is feasible. * skip Hibernate layer and use JDBC directly - Doable, the SQL query being not too complicated, but with cross DB issues. * tweak the HQL query - How?
Any other options Sergiu?
Yep. Say that mysql <5 is not supported. Frankly, I don't understand why people still use ancient versions. Version 4.1 has been EOL-d for some time, and version 7 is on its way already.
Marius
Marius Dumitru Florea wrote:
Hi Jeremie,
The sql query you suggested is cleaner and at least as efficient as the current one. It was my first option but unfortunately it's not supported by the newer versions of mysql. I've no idea why..
mysql> select xws_name, sum(xws_page_views) as pageviewcount from xwikistatsdoc where xws_action='view' and xws_name like '%.%' group by xws_name order by pageviewscount desc; ERROR 1054 (42S22): Unknown column 'pageviewscount' in 'order clause'
Note that there's a typo: pageviewcount <> pageview-S-count
Anyway, hibernate should be responsible for the correct translation from hql to a specific sql dialect. A solution would be to use the (idea from the) above sql but configure the dialect to MySQL5Dialect (in my case). I have to test this. I'll give you feedback soon.
Best Regards, Marius.
-- Sergiu Dumitriu http://purl.org/net/sergiu/
-- Sergiu Dumitriu http://purl.org/net/sergiu/
Marius Dumitru Florea wrote:
A fourth option (someway similar to the second one) is to use the Native SQL Query feature of Hibernate. Instead of calling session.createQuery(hql) you can call session.createSQLQuery(sql). It works, using aliases. However, I tested it only on MySql and HSQLDB.
WDYT? Is this a convenient solution. I would have to switch many of the hql queries from the Statistics Application to sql queries.
Generally, we should stay away from pure SQL as much as possible. If the existing query works in all DBMSs except mysql 4.1, then leave it as it is.
Marius
Right.. but the error persists with the correction made. Not at the same level though.
WARN util.JDBCExceptionReporter - SQL Error: 1054, SQLState: 42S22 ERROR util.JDBCExceptionReporter - Unknown column 'pageViewsCount' in 'order clause'
The problem is with Hibernate. There is a bug ("missing feature", for them) in the translation from HQL to SQL. The aliases from the Select clause are not resolved correctly in other clauses, including Order By. In this case they "recommend" us to duplicate the expressions from the Select clause, hoping that the RDBMS will take care of the optimization.
See for yourself:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-892 http://opensource.atlassian.com/projects/hibernate/browse/HHH-1902 http://opensource.atlassian.com/projects/hibernate/browse/HHH-2390 http://forum.hibernate.org/viewtopic.php?t=966075&postdays=0&postorder=asc&s...
So, using aliases breaks Hibernate and using expressions in the Order By clause is not supported by MySql 4.1.20. I don't see any clean solution for this. Some options are:
* drop the Order By clause and sort on the Java side - No way, I don't think this is feasible. * skip Hibernate layer and use JDBC directly - Doable, the SQL query being not too complicated, but with cross DB issues. * tweak the HQL query - How?
Any other options Sergiu?
Marius
Marius Dumitru Florea wrote:
Hi Jeremie,
The sql query you suggested is cleaner and at least as efficient as the current one. It was my first option but unfortunately it's not supported by the newer versions of mysql. I've no idea why..
mysql> select xws_name, sum(xws_page_views) as pageviewcount from xwikistatsdoc where xws_action='view' and xws_name like '%.%' group by xws_name order by pageviewscount desc; ERROR 1054 (42S22): Unknown column 'pageviewscount' in 'order clause'
Note that there's a typo: pageviewcount <> pageview-S-count
Anyway, hibernate should be responsible for the correct translation from hql to a specific sql dialect. A solution would be to use the (idea from the) above sql but configure the dialect to MySQL5Dialect (in my case). I have to test this. I'll give you feedback soon.
Best Regards, Marius.
-- Sergiu Dumitriu http://purl.org/net/sergiu/
Sergiu, I must admit that your solution is the more efficient and clean, even if I personally don't like it (you'd be surprised to know how painful it will be to ask my infra team to upgrade mysql version ...). For me it's clearly a MySQL bug not an hibernate one, let's say at least a break of compatibility in MySql not managed by hibernate. Typically what you would like an abstraction layer to take care of ... :/ Thanks for help, Jeremie -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Sergiu Dumitriu Sent: mardi 19 février 2008 11:42 To: XWiki Users Subject: Re: [xwiki-users] MySQL Error "invalid use of group function" in Statistics application Marius Dumitru Florea wrote:
A fourth option (someway similar to the second one) is to use the Native SQL Query feature of Hibernate. Instead of calling session.createQuery(hql) you can call session.createSQLQuery(sql). It works, using aliases. However, I tested it only on MySql and HSQLDB.
WDYT? Is this a convenient solution. I would have to switch many of the hql queries from the Statistics Application to sql queries.
Generally, we should stay away from pure SQL as much as possible. If the existing query works in all DBMSs except mysql 4.1, then leave it as it is.
Marius
Right.. but the error persists with the correction made. Not at the same level though.
WARN util.JDBCExceptionReporter - SQL Error: 1054, SQLState: 42S22 ERROR util.JDBCExceptionReporter - Unknown column 'pageViewsCount' in 'order clause'
The problem is with Hibernate. There is a bug ("missing feature", for them) in the translation from HQL to SQL. The aliases from the Select clause are not resolved correctly in other clauses, including Order By. In this case they "recommend" us to duplicate the expressions from the Select clause, hoping that the RDBMS will take care of the optimization.
See for yourself:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-892 http://opensource.atlassian.com/projects/hibernate/browse/HHH-1902 http://opensource.atlassian.com/projects/hibernate/browse/HHH-2390 http://forum.hibernate.org/viewtopic.php?t=966075&postdays=0&postorder=asc&s...
So, using aliases breaks Hibernate and using expressions in the Order By clause is not supported by MySql 4.1.20. I don't see any clean solution for this. Some options are:
* drop the Order By clause and sort on the Java side - No way, I don't think this is feasible. * skip Hibernate layer and use JDBC directly - Doable, the SQL query being not too complicated, but with cross DB issues. * tweak the HQL query - How?
Any other options Sergiu?
Marius
Marius Dumitru Florea wrote:
Hi Jeremie,
The sql query you suggested is cleaner and at least as efficient as the current one. It was my first option but unfortunately it's not supported by the newer versions of mysql. I've no idea why..
mysql> select xws_name, sum(xws_page_views) as pageviewcount from xwikistatsdoc where xws_action='view' and xws_name like '%.%' group by xws_name order by pageviewscount desc; ERROR 1054 (42S22): Unknown column 'pageviewscount' in 'order clause'
Note that there's a typo: pageviewcount <> pageview-S-count
Anyway, hibernate should be responsible for the correct translation from hql to a specific sql dialect. A solution would be to use the (idea from the) above sql but configure the dialect to MySQL5Dialect (in my case). I have to test this. I'll give you feedback soon.
Best Regards, Marius.
-- Sergiu Dumitriu http://purl.org/net/sergiu/ _______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
BOUSQUET Jeremie wrote:
Sergiu, I must admit that your solution is the more efficient and clean, even if I personally don't like it (you'd be surprised to know how painful it will be to ask my infra team to upgrade mysql version ...). For me it's clearly a MySQL bug not an hibernate one, let's say at least a break of compatibility in MySql not managed by hibernate. Typically what you would like an abstraction layer to take care of ... :/
Thanks for help, Jeremie
I know how hard it is to convince sysadmins to upgrade. I barely convinced one to upgrade from 4.0 in order to have UTF-8 support in the database. It took many days and a signature from the university rector. Finally he decided to install a new mysql on another machine, so that the other apps won't be in danger...
-----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Sergiu Dumitriu Sent: mardi 19 février 2008 11:42 To: XWiki Users Subject: Re: [xwiki-users] MySQL Error "invalid use of group function" in Statistics application
Marius Dumitru Florea wrote:
A fourth option (someway similar to the second one) is to use the Native SQL Query feature of Hibernate. Instead of calling session.createQuery(hql) you can call session.createSQLQuery(sql). It works, using aliases. However, I tested it only on MySql and HSQLDB.
WDYT? Is this a convenient solution. I would have to switch many of the hql queries from the Statistics Application to sql queries.
Generally, we should stay away from pure SQL as much as possible. If the existing query works in all DBMSs except mysql 4.1, then leave it as it is.
Marius
Right.. but the error persists with the correction made. Not at the same level though.
WARN util.JDBCExceptionReporter - SQL Error: 1054, SQLState: 42S22 ERROR util.JDBCExceptionReporter - Unknown column 'pageViewsCount' in 'order clause'
The problem is with Hibernate. There is a bug ("missing feature", for them) in the translation from HQL to SQL. The aliases from the Select clause are not resolved correctly in other clauses, including Order By. In this case they "recommend" us to duplicate the expressions from the Select clause, hoping that the RDBMS will take care of the optimization.
See for yourself:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-892 http://opensource.atlassian.com/projects/hibernate/browse/HHH-1902 http://opensource.atlassian.com/projects/hibernate/browse/HHH-2390 http://forum.hibernate.org/viewtopic.php?t=966075&postdays=0&postorder=asc&s...
So, using aliases breaks Hibernate and using expressions in the Order By clause is not supported by MySql 4.1.20. I don't see any clean solution for this. Some options are:
* drop the Order By clause and sort on the Java side - No way, I don't think this is feasible. * skip Hibernate layer and use JDBC directly - Doable, the SQL query being not too complicated, but with cross DB issues. * tweak the HQL query - How?
Any other options Sergiu?
Marius
Marius Dumitru Florea wrote:
Hi Jeremie,
The sql query you suggested is cleaner and at least as efficient as the current one. It was my first option but unfortunately it's not supported by the newer versions of mysql. I've no idea why..
mysql> select xws_name, sum(xws_page_views) as pageviewcount from xwikistatsdoc where xws_action='view' and xws_name like '%.%' group by xws_name order by pageviewscount desc; ERROR 1054 (42S22): Unknown column 'pageviewscount' in 'order clause'
Note that there's a typo: pageviewcount <> pageview-S-count
Anyway, hibernate should be responsible for the correct translation from hql to a specific sql dialect. A solution would be to use the (idea from the) above sql but configure the dialect to MySQL5Dialect (in my case). I have to test this. I'll give you feedback soon.
Best Regards, Marius.
-- Sergiu Dumitriu http://purl.org/net/sergiu/
participants (3)
-
BOUSQUET Jeremie -
Marius Dumitru Florea -
Sergiu Dumitriu