java - Using a Local Temp Table and such using SimpleJdbcTemplate (or Spring) -
first off, admittedly, no dba...so sql-fu weak.
i working on project had pretty hefty report did 10 inner joins. when ran against prod data (sql server 2005) using sql studio management client, query wasn't barn-burner, returned in under 20sec. however, when ran through spring, 31min.
so, got our dba ninja on it, , pointed out query plan different because jdbc method use prepared statement, passing in variables parameters, whereas in client hard-coded. so, re-worked query.
the resulting query sets declare variables top, uses create local temp table, uses local temp table part of ultimate report query. said should able send part of same query string (compound query????). looks (obfuscated protect innocent):
declare @startdate datetime declare @enddate datetime set @startdate = dateadd (dd, 0, datediff (dd, 0, '2013-03-01 00:00:00.000')) set @enddate = dateadd (dd, 1, datediff (dd, 0, '2013-08-08 00:00:00.000')) create table #latest_blah_action ( fk_blah_timestamp datetime, fk_blah_id varchar(10), blah_other_thing varchar(10), [latest updated date/time] datetime ) insert #latest_blah_action select fk_blah_timestamp, fk_blah_id, blah_other_thing, max(blah_other_timestamp) [latest updated date/time] blahtable blah_another_thing = 'some value' , blah_other_timestamp between @startdate , @enddate group fk_blah_timestamp, fk_blah_id, blah_other_thing select -- bunch of fields latest_blah_action -- bunch of crazy inner joins , such
however it's not working. if run out of sql management studio, results. if run out of java code using spring's simplejdbctemplate, no error no results.
is possible run (compound???) query using spring, , if so, how? have them individually, part of transaction? maybe use other simplejdbctemplate?
Comments
Post a Comment