w517424787 commented on issue #22528: URL: https://github.com/apache/doris/issues/22528#issuecomment-1666829359
> 这里存在语义差异,doris中字符串和数字比较时,会将字符串转为数字: > > ```sql > stat_date = '20200601' --是字符串比较 > stat_date = 20200601 --是数字比较 > ``` > > state_date值 stat_date = '20200601' stat_date = 20200601 > '20200601' true true > '020200601' false true > 'abc' false null > 可以看到,两者的返回值并不一致。基于此,不能将`cast(stat_date as int) = 20200601`改写为`stat_date = '20200601'`以提升性能 -------------------- 目前doris在字符串和数字比较时,都统一将字符串转数字进行比较,这样会导致查询出的结果不准确,而且也不会报错。 另外,针对字符串和数字比较时,可以根据字段的类型,将传入的值类型转换为字段类型,提高查询效率,如: 如果stat_date是string类型,where stat_date = 20200601 可以转换为 where stat_date = cast(20200601 as string),而不是 where cast(stat_date as int) = 20200601 , 这在数据量很大的时候,性能损耗很严重。 如果stat_date是int类型,where stat_date = '20200601' 可以转换为 where stat_date = cast(20200601 as int) --> 目前这个是已经有了。 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org