3 ms·
If you cache on the level of SQL-statement strings you can skip the transformation into the AST. It's very cheap to quickly hash the string and look it up. If
by Periodic 17y ago
If you cache on the level of SQL-statement strings you can skip the transformation into the AST. It's very cheap to quickly hash the string and look it up. If you have a site that is going to use the same queries over and over (e.g. for front-page data or popular categories) then the query will likely be exactly the same and the string hash is cheaper. If you had to build an AST for every single query you're just adding an extra layer of complexity that won't gain you much.
The only reason I can think of for a query with different literals in the conditionals to have a different plan would be if a histogram of frequencies was actually kept such that different literals created large differences in result sizes which then get fed into a join and affect the join logic. But that's going to be pretty rare and is a level of optimization that is unnecessary. It's also not going to make a huge difference unless the query is very complex, because the plans for simple queries are... simple.
- andrewcooke 17y agoeither i've misunderstood, or you're missing the point. if you cache the statement then you get a miss if the different literals change. remember that (again, unless i have misunderstood) we are not talking about compiled statements, but about linq generate the "complete text". i agree that the same plan would normally be used; the problem is hitting the cache to find that plan if the value of a variable changes.