开发者

Oracle runtime of comparing numbers versus comparing strings using a LIKE operator

My company database has 20 different string formats for their primary product label. All 20 of them are stored in a separate look-up table

1 are strings starting with 'W'

2 are strings starting with 'TAIC'

3 are strings starting with 'D'

...

N开发者_JAVA百科ext to the label attribute is the 'type' attribute, which stores the number related to which prefix the label contains.

I'm tasked with updating one of our modules for better runtime. One of the queries I ran across deals with all labels containing 'TAIC' as the prefix. However, instead of comparing whether the type number is equal to 2, it runs a LIKE operation checking for each label that begins with TAIC.

Now, my question is this -- since my goal is for better run time, would it be wise to switch from the like operator to just a regular equality operation against the type attribute? It seems that running a regular expression-ish operation against a string would be a bit more time consuming, but enough to significantly alter the run time of a system?


In Oracle, both these operations:

SELECT  *
FROM    mytable
WHERE   pk LIKE 'TAIC%'

and

SELECT  *
FROM    mytable
WHERE   type = 2

are sargable, that is able to use an index on the appropriate fields.

The numeric index, however, would be more compact and hence require less time to traverse, so using numeric comparison could increase the query performance.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜