Searching for matching queries Suppose you have a large set of queries (could be in SQL form, but conceivably the same problem exists for search engine query strings or Lucene expressions, etc...) stored and you want to know which of these queries matches a specific object X: is there a general approach to this problem? 

Naive implementation would of course be to iterate over all queries, execute them and see if object X is an element of the results found. I expect that a solution would consist of using the indexes that are useful for the operation "query -> results" to perform the "result -> queries" search to find a small superset of the correct set of queries.
Create a new table with only one object i.e. object X
Execute all the queries on it.
Discard those which return nothing.
Remaining queries are the queries that match your object X.


This will be faster than searching in a big table.