简体   繁体   English

SQL rtrim选择和分组

[英]SQL rtrim select and group by

If you put an rtrim in the SELECT and also again in the GROUP BY, is this inefficient because its rtriming twice, one in the select and one in the group by? 如果将rtrim放入SELECT中,然后再次放入GROUP BY中,这是否效率低下,因为它会进行两次遍历,一次在select中,一次在group by中? eg... 例如...

SELECT
rtrim(people.FORENAME1)+ ' ' + rtrim(people.SURNAME)AS Full_Name,

FROM 
my table

GROUP BY 
rtrim(people.FORENAME1)+ ' ' + rtrim(people.SURNAME)

It's probably only performing the function once, but it's inefficient since it's non SARGable. 它可能只执行一次功能,但是效率低下,因为它不可SARGable。

Since you are applying a function, the optimizer can't use any existing indexes that refer to those fields. 由于您正在应用函数,因此优化器无法使用任何引用这些字段的现有索引。 It doesn't know the results of the function(s) until they are run, so it needs to process each and every row in the table. 在运行之前,它不知道函数的结果,因此它需要处理表中的每一行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM