I am running the following SQL query, to query my database.
Query = "SELECT TimeValue, strValue FROM tabDataRaw WHERE ID_PAR = 5 AND TimeValue >= #01/10/2012 00:21:00# AND TimeValue <= #01/10/2012 18:12:00#"
However when I run this query I get no results, the code freezes at the execute command and doesn’t return any results. Generally I see a dip in the memory being used on my PC after a couple of minutes, which I assume is the query giving up, but it never returns anything.
I decided to leave the code running overnight and I came back in the morning to a System Resource Exceeded error. I don’t understand this as I have ~1.5GB of RAM spare where this Query should return only about one thousand results. The table does hold over 13 million records but surely this shouldn’t affect the RAM needed for the query that badly, the .mdb file is less than 1GB on the drive.
Any help or advise on debugging this would be greatly appreciated.
EDIT: I have found a mistake in the Query from the Data syntax I generally use that caused me another error because I was querying for the wrong date, this Query is looking for Jan 10th rather than Oct 1st. I generally use this form to make it clearer:
Query = "SELECT TimeValue, strValue FROM tabDataRaw WHERE ID_PAR = 13 AND TimeValue >= #01 October 2012 00:21:00# AND TimeValue <= #01 October 2012 18:12:00#"
The query is probably doing a full scan of the table. To avoid this, add a compound index on
(ID_PAR, TimeValue):A (covering) index on
(ID_PAR, TimeValue, strValue)would be even better in most DBMS but I’m not sure if this applies to MS-Access.