2

Actually it's a simple question but I'm lacking of experience and know how about the internal optimization of a database system (in general, but T-SQL in my specific case).

Assumed I have a database with integer data fields (for simplification 1-3):

table Data (D1, D2, D3)

I have a collection of match criteria:

D1 > 3       D2 < 100    D3 all
D1 >= 50     D2 all      D3 > 50
and so on...

The naive way to perform a query would be to AND every expression of a criteria an OR every criteria expression. But obviously an optimized query would be D1 >= 50 and D2 < 100 and D3 > 50 (see edit)

So here's the question: Is a database (T-SQL in my case) able to optimize my naive query?

If not: Can someone point me to the right direction (i'm sure there must be some algorithm for that case I can't figure it out).

Edit:

Obviously the optimization assumption was wrong :-D

D1 >= 50     D2 < 100    D3 all
D1 >= 50     D2 all      D3 > 50
and so on...

This one could be optimized from
D1 >= 50 and D2 < 100 or D1 >= 50 and D3 > 50
to
D1 >= 50 and (D2 < 100 or D3 = 50)

And somehow I assume, that a database should be that smart (if I think about how complex queries become this must be child's play for the database).

The question should be: How much criteria can it handle (X data fields and Y criterias). But that's something I have to figure out. I'll report when we collect some date here (could take a while).

4

1 回答 1

0

由于不会有真正的答案,我会回答我自己的问题以提供反馈。
(如果有人愿意为此做出贡献,我仍然很高兴!)

最初的问题暗示了一个表格,其中包含数据和适用于该数据的标准集合。在进一步的分析中,我面临这样一个事实,即这个想法背后的整个概念是如此复杂,以至于我们不能依赖于将这个标准保存在一个单独的表中(原因:动态 API 和当你试图在没有清晰的编程库的情况下处理它时纯粹的混乱)。

所以它以动态 SQL 结束(而不是连接、存储过程等)。幸运的是,我可以通过以前的限制来减少查询的数据,这将减少大量的数据,这些数据仍然需要使用标准进行查询。我什至不再认为应用(例如)100 条标准和 10 条规则有问题。我仍然担心数据库可以在短时间内处理多少这样的查询(除了常见的工作负载)而不会爆发。

尽管如此,对于我作为开发人员来说,这是一个非常巧妙的要求来“挣扎”。如果还有更多要说的,我会回来报告...

于 2013-09-07T00:11:54.963 回答