Coldfusion: Using Cached Query in a "drill down interface"

Status
Not open for further replies.

Flipside79

Ars Tribunus Angusticlavius
9,365
Here is my situation. I am running queries on a very large database. Basically the user gets an initial list of results from the search. Many of results are very similar, and may only vary because of something small like "st" instead of "street". So basically the user sees preliminary data about the choice, but then click on a link to see all the data. Basically when they click on the link it reruns the same query, except it also passes URL variables to verify and make sure they are only getting that 1 record. I would love to use cached queries, but since the query is technically different due to the URL variables the cached query does not kick in. It was no big deal to have it just rerun the query when I only had thousands of records, but now that there are around 10million this is NOT PRACTICAL. I am relatively new to Coldfusion, so i need a little help here. Is there a way to requery the cached results with the URL variables? I need some suggestions here. Running a query of 10million records 2 times in a row is not practical......
 

mudboy

Ars Legatus Legionis
17,501
Subscriptor
well, come to think of it, you COULD build a list/array/whatever of the ID's (or whatever you are using as a keyfield) of the records returned on the initial query, save it as a session variable, and then use that to refine your query from there. i.e.:

Query 1:
SELECT ID, data
FROM tbl
WHERE data LIKE "blah"

...Build an array or list from those ID values and store it as a session variable...

The drilldown query:
SELECT ID, data
FROM tbl
WHERE blah blah AND tbl.ID IS "session.blah"

Pardon my SQL laziness, but you get the idea, build your where clause dynamically from the session variables above.

Let me know if that works, I was working on pure theory...

Pete
 

perr2187

Wise, Aged Ars Veteran
137
Based on this and some of your previous posts, here is what you want to do.

First, add an ID column to each of your tables. Make this a primary key for the table, and make it auto increment with each row. that will basically number of record you have uniquely. (1,2,3,... 9 million) Then use something like this for the query that lists all the records:

Code:
select a,b,c,d,ID from myTable where ....

Then when you output the records use tags like this for a link to the drill down page

Code:
<a href="drilldown.cfm?id=#ID#">Details</a>

then on your drill down page use this query:

Code:
select a,b,c,d from myTable where ID=#url.ID#

This will return just the one record on your drill down page, and should run really well.
 
Status
Not open for further replies.