question

sakuraime avatar image
0 Votes"
sakuraime asked ErlandSommarskog commented

Adaptive Join : Threshold rows

Just interesting how to determine the threshold rows of the adaptive join which switch between hash or nested loop ?


137269-image.png


sql-server-general
image.png (46.0 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AmeliaGu-msft avatar image
0 Votes"
AmeliaGu-msft answered ErlandSommarskog commented

Hi sakuraime,
Please also check this doc:

138072-image.png

Best Regards,
Amelia



image.png (73.9 KiB)
· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

thanks . why more rows with higher host use nested loop join ?

0 Votes 0 ·

They don't. It is the other round. Then the threshold is crossed, the hash join becomes cheaper. Note that it says "Cost" for the y-axis in the diagram.

0 Votes 0 ·

oh. that's much explainable . Thanks

0 Votes 0 ·
Show more comments
AmeliaGu-msft avatar image
0 Votes"
AmeliaGu-msft answered sakuraime commented

Hi sakuraime,

If the Adaptive Threshold Rows is more than an actual number of rows, SQL Server Engine has preferred nested loop join. If the Adaptive Threshold Rows is less than an actual number of rows, SQL Server Engine has preferred Hash Match join.
Please refer to this article.

Best Regards,
Amelia


If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I mean how this number comes out ?

half of the actual rows or what?

0 Votes 0 ·
ErlandSommarskog avatar image
0 Votes"
ErlandSommarskog answered ErlandSommarskog commented

I mean how this number comes out ?

half of the actual rows or what?

I have not checked, but I can't but see that this is a number which is determined at compile time. That is, the optimizer estimates that if the actual number of rows coming into the Adaptive Join operator is lower than the threshold, the nested loops will be the cheapest join method, and but the hash is estimated to be better if the number is above the threshold.



· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks Paul - My head will keep spinning for the next couple of hours. :-)

0 Votes 0 ·