1

in DB2 query, what is the fastest between:

1) SELECT A, B, C from MY_TABLE where Z = 'VAL1' OR Z = 'VAL2' OR Z = 'VAL3';

2) SELECT A, B, C from MY_TABLE where Z IN ('VAL1', 'VAL2', 'VAL3');

4

1 回答 1

0

我从未使用过 db2,但如果您看到 db2 的性能更好IN,它可能正在优化您的查询以在后台执行类似的操作:

SELECT
    A, B, C
FROM
    MY_TABLE m
JOIN
    (VALUES 'VAL1','VAL2','VAL3') AS v(Value)
    ON
    m.Z = v.Value

我认为这比三个 OR 查找更有效。你有任何索引Z吗?

于 2013-06-14T15:14:13.287 回答