Hello!
Here is my situation:
1) User A must monitor the results of an sql query Q. 2) User B can modify data that may change the results of Q 3) running Q on the entire database is slow
What I would like have is: whenever user B modifies the data: with a create, update or delete, then generate the delta to the results of Q. i.e. return (list of modified, list of created, list of deleted) triple.
So, updates to Q would be much faster.
Implementation details: SQL Server 2005, with NHibernate layer. Currently, user A runs Q in polling mode, every 10 seconds.
One idea I had was to create an in-memory copy of the DB schema, and when user B makes a change, then also make this change in the in-memory copy, and then run Q on this in-memory copy.
Is there a better way of doing this?
Thanks!!!
Post-Script : Thanks for all of the detailed comments. I've decided to implement this feature as follows: 1) use NHibernate PostUpdate event to get notification when a change has been made to the database 2) run LINQ to Object query on in-memory collection of updates 3) for each SQL query registered in the system, store a list of results on a Redis server, in memory (no persistence to disk) 4) if LINQ query indicates that the update is relevant to a given query, i.e. changes the result set, then update the list on Redis 5) use some type of notification, such as Redis Pub/Sub, to notify users of changes to a given query 6) when updating the list on Redis, pass in the sql server update timestamp. Will need a little code on Redis side to resolve conflicts, based on timestamp. If a change is passed in with a lower timestamp, ignore.