Hibernate version:
3.1
Name and version of the database you are using:
Postgresql 8.1.3
Hello,
I have a big query that I must implement as native SQL (it uses UNION).
If I implement this query cleanly, ie with binded parameters, it is awfully slow (> 15 seconds).
The query outputed with show_sql is fast (<1 second).
I can get the native sql query to be as fast as a direct SQL query (through psql) if I directly put the value of the parameters inside the sql String instead of using binded parameters.
For instance :
Code:
getSession().createSQLQuery("select {feat.* } \n" +
"from FEATURE feat where feat.uniquename like \'B0510_contig_1887_fgenesh_Magnaporthe_transcript%\' \n" +
"UNION\n" +
" select {feat.* } \n" +
"from FEATURE feat join FEATURE_SYNONYM fs using (feature_id) join SYNONYM s using (synonym_id) where s.name like \'B0510_contig_1887_fgenesh_Magnaporthe_transcript%\' \n").addEntity("feat",FeatureImpl.class).list();
executes in less than a second, while :
Code:
getSession().createSQLQuery("select {feat.* } \n" +
"from FEATURE feat where feat.uniquename like ? \n" +
"UNION\n" +
" select {feat.* } \n" +
"from FEATURE feat join FEATURE_SYNONYM fs using (feature_id) join SYNONYM s using (synonym_id) where s.name like ? \n").addEntity("feat",FeatureImpl.class)
.setString(0,"B0510_contig_1887_fgenesh_Magnaporthe_transcript%")
.setString(1,"B0510_contig_1887_fgenesh_Magnaporthe_transcript%")
.list();
executes in 15 seconds
Am I missing something here?
Is there a way to get better performances with native SQL and binded parameters?
Thanks in advance for any help.