I have a question on a FilterExpression I plan to use on my SqlDataSource. I just want to know whether this would work, and what would happen in certain scenarios:
(itemID like '%{0}%' OR parentID like '%{0}%') AND (source like '%{1}%' OR action like '%{1}%' OR itemID like '%{1}%' OR parentID like '%{1}%' OR item like '%{1}%' OR userid like '%{1}%' OR timestamp like '%{1}%')
The {0} parameter can be given in a query string (although it can also not be given), and {1} is what is typed into a textbox. Basically, the user can access a page which lists all records that have an 'itemID' or 'parentID' like the query string. They can then narrow it down even more by typing into a textbox any text they'开发者_如何学JAVAd like to filter all columns by.
Basically, would it work as desired above? If not, can I change it easily somehow?
Thanks
Would it work? It appears so.
However, this is going to be hell on your database server. In a nutshell, you will not be able to leverage any indexing, cached query plans, or any other optimization hints. It will result in full table scans.
The database server (doesn't matter which one) is incapable of optimizing LIKE '%{some value}%'
The problem is the first %, which means match anywhere in the column. Of course, all of the OR statements would throw out the query plans anyway, so maybe that isn't as big a deal as the whole design.
You might consider using Full Text Indexing on those fields. Another idea would be to go back and take a hard look at the requirements to see if it wouldn't be better to implement a regular field based search that allowed multiple where clauses with distinct values entered for the criteria.
精彩评论