Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type conversion in expression may affect cardinality estimate in query plan

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

like image 304
Jens Borrisholt Avatar asked Feb 10 '26 23:02

Jens Borrisholt


2 Answers

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.

like image 116
Stu Avatar answered Feb 13 '26 14:02

Stu


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

like image 42
Daniel Jonsson Avatar answered Feb 13 '26 15:02

Daniel Jonsson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!