SQL - What is the performance impact of having multiple CASE statements in SELECT - Teradata

后端 未结 2 893
心在旅途
心在旅途 2021-02-07 02:23

So I have a query that requires a bunch of CASE statements in the SELECT. This was not the orginal design but part of a compromise.

So the query looks something like thi

2条回答
  •  不要未来只要你来
    2021-02-07 03:00

    The case statements are going to be much less of a factor than the joins in the WHERE clause.

    The main driver of performance in SQL is I/O -- reading the data from disk. I think of it as two orders of magnitude more important than the processing going on in rows. This is just a heuristic, not based on specific tests on a database.

    You are doing self-joins, which will require either lots of work reading the table or a fair amount of work dealing with indexes.

    The case statement, on the other hand, gets turned into very primitive hardware commands -- equals, gotos, and the like. The data resides in memory closest to the processors, so it is going to zip along. You are doing nothing fancy in the case statement (such as a like or a subquery). I would imagine that the query would be just as fast if you removed most of the lines in the statement.

    If you are having issues with performance, put an index on (VERS_NM, RPT_PERD_TYPE_CD, DATA_VLDTN_IND, Perd_END_RPT_DT). This four-part index should allow you to get the max date without invoking I/O requests on the original table.

提交回复
热议问题