Hi everyone - I have a query that selects multiple fields from several different tables using an inner join and two left joins. When I run the exact query in access, the results are instant. When it's run using ucanaccess, it takes nearly four minutes. Can anyone help? Code:
Firstly. you have to pay attention: if the access db is updated in any way after the mirror db has been cteated, the mirror db will be re-created at the next connection. So please, measure just the query executuion time:
@Testpublicvoidread_test()throwsSQLException{Connectionconn=null;Statements=null;ResultSetrs=null;try{conn=DriverManager.getConnection("jdbc:ucanaccess:localpath/to/db.accdb;keepMirror=C:/mirror/path/theMirror1"); s = conn.createStatement(); long time = System.currentTimeMillis(); String qry = "SELECT[AGRMNT-REF],PRIORITY,VENDOR,TYPE,[BASE-COST],UOM,COMPANY,[BASE-PERCENT]FROM((AGRMNTHDRASHINNERJOINAGRMNTLINEASLON" + "L.[AGRMNT-REF]=H.[AGRMNT-REF])LEFTJOINPOAGRMNTPARTPONL.[AGRMNT-REF]=p.[AGRMNT-REF])LEFTJOINPOAGRMNTPERCENTAGEPPon" + "L.[AGRMNT-REF]=PP.[AGRMNT-REF]"; rs = s.executeQuery(qry); long time1 = System.currentTimeMillis(); System.out .println("timeinmillisec:" + (time1 - time) ); while(rs.next()) { System.out.println(rs.getString("UOM"));}}finally{s.close();conn.close();}}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Can you confirm that the AGRMNT-REF column is indexed in all four (4) tables? (If you open the database using "console.bat" or "console.sh" you should see the indexes listed as the database loads.)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi everyone - I have a query that selects multiple fields from several different tables using an inner join and two left joins. When I run the exact query in access, the results are instant. When it's run using ucanaccess, it takes nearly four minutes. Can anyone help? Code:
Firstly. you have to pay attention: if the access db is updated in any way after the mirror db has been cteated, the mirror db will be re-created at the next connection. So please, measure just the query executuion time:
Hey Marco - the db hasn't been updated and the output shows a time of: 268394 milliseconds
Last edit: bran 2017-02-20
Can you confirm that the
AGRMNT-REF
column is indexed in all four (4) tables? (If you open the database using "console.bat" or "console.sh" you should see the indexes listed as the database loads.)Here's the output
Last edit: bran 2017-02-20
Certainly worth a try to add indexes on the [AGRMNT-REF] columns in the [POAGRMNTPART] and [POAGRMNTPERCENTAGE] tables to see if that helps.
wow, that helped a ton! time now is 1790 millsecs, thanks!