表达中的类型转换可能会影响查询计划中的基数估计值

发布于 2025-01-20 21:23:05 字数 430 浏览 2 评论 0 原文

我的执行计划有警告,我无法摆脱。我在这里做了一个最小,可重复的示例:

declare @TestData Table
(
  FloatValue float null
)

insert into @TestData values
 (null), (0.1)

select 
    CONVERT(varchar, FloatValue * 100.00) + ' pct.' PctValue
from 
    @TestData

我包括了警告。

I have a warning in my Execution plan that I can not get rid of. I've made an Minimal, Reproducible Example here:

declare @TestData Table
(
  FloatValue float null
)

insert into @TestData values
 (null), (0.1)

select 
    CONVERT(varchar, FloatValue * 100.00) + ' pct.' PctValue
from 
    @TestData

I've included the warning.

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风渺 2025-01-27 21:23:05

SQL Server 有时对其警告有点过于谨慎。

您可能会在执行计划中遇到各种警告,经过审查后发现这些警告无关紧要;例如,您有时可能会看到有关内存授予过多的警告,即使该授予实际上是每个查询可能配置的最小量。

由于这不是涉及过滤或加入决策的列,因此您可以放心地忽略它。

SQL Server is sometimes a little over cautious with its warnings.

You can encounter various warnings in the execution plan that, after review, prove to be irrelevant; for example you may sometimes see a warning about an excessive memory grant, even though the grant is literally the minimum configured amount possible per query.

As this is not a column involved with filtering or joining decision making you can safely disregard it.

海螺姑娘 2025-01-27 21:23:05

You can change CONVERT(varchar, FloatValue * 100.00) to FORMAT(FloatValue * 100.00, 'N0') in the query:

declare @TestData Table
(
  FloatValue float null
)

insert into @TestData values
 (null), (0.1)

select 
    FORMAT(FloatValue * 100.00, 'N0') + ' pct.' PctValue
from 
    @TestData

And it will get rid of the warning:

< a href =“ https://i.sstatic.net/v5nq0.png” rel =“ nofollow noreferrer”>

You can change CONVERT(varchar, FloatValue * 100.00) to FORMAT(FloatValue * 100.00, 'N0') in the query:

declare @TestData Table
(
  FloatValue float null
)

insert into @TestData values
 (null), (0.1)

select 
    FORMAT(FloatValue * 100.00, 'N0') + ' pct.' PctValue
from 
    @TestData

And it will get rid of the warning:

The warning 'Type conversion in expression may affect cardinality estimate in query plan' is now gone from the message box

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文