1

Have recently migrated from SQL 2016 where the DB's compatibility level was all set to 2008 to SQL 2019 where the compatibility level for all DB's are now 150.

Upon running workload for a while, I found some queries that weren't performing too well. I added the hint OPTION (USE HINT ('FORCE_LEGACY_CARDINALITY_ESTIMATION')) to these queries and it seems to have helped in some cases and in other cases, doesn't help at all.

What I have noticed is that some of the queries, even though they're being forced to use the legacy CE, the query plan shows BatchModeOnRowStoreUsed = true

How is this possible?

Batch mode on rowstore is a SQL 2019 engine feature so how can a query running CE 70 have this feature?

Unless I am misunderstanding and a query that is using legacy CE can still leverage SQL 2019 IQP features?

Also, has anyone experienced poor performance when a query plan features Batch Mode on Rowstore?

The wait associated with this particular query is HTDELETE

Thank you

1 Answer 1

4

Batch mode on rowstore is a SQL 2019 engine feature so how can a query running CE 70 have this feature?

Cardinality estimation model is separate from compatibility level, and features available by way of using newer compatibility levels.

The "new" cardinality estimation model was introduced in SQL Server 2014, and like the original cardinality estimation model, has undergone various changes over the years.

This only controls the formulas SQL Server uses during query optimization to determine how many rows will potentially qualify for or be projected from various predicates, joins, groupings, etc.

It wouldn't be sensible to tie the two settings together so tightly, where users would either use the legacy model and get no new features, or the new model and get all of the new features.

The "new" model is only "new", and in many cases not better, than the legacy model.

Unless I am misunderstanding and a query that is using legacy CE can still leverage SQL 2019 IQP features?

Correct. You can change cardinality estimation in other ways, too. A mostly-correct list of valid use hints is available here:

SELECT 
    d.* 
FROM sys.dm_exec_valid_use_hints AS d;

Which includes FORCE_LEGACY_CARDINALITY_ESTIMATION and FORCE_DEFAULT_CARDINALITY_ESTIMATION.

It also includes several ways to control which compatibility level features can be made available to your query.

  • QUERY_OPTIMIZER_COMPATIBILITY_LEVEL_100
  • QUERY_OPTIMIZER_COMPATIBILITY_LEVEL_110
  • QUERY_OPTIMIZER_COMPATIBILITY_LEVEL_120
  • QUERY_OPTIMIZER_COMPATIBILITY_LEVEL_130
  • QUERY_OPTIMIZER_COMPATIBILITY_LEVEL_140
  • QUERY_OPTIMIZER_COMPATIBILITY_LEVEL_150
  • QUERY_OPTIMIZER_COMPATIBILITY_LEVEL_160 (SQL Server 2022)

There is even a specific use hint that you may find specifically helpful, specifically for your specific query, having HTDELETE problems: DISALLOW_BATCH_MODE.

Also, has anyone experienced poor performance when a query plan features Batch Mode on Rowstore? The wait associated with this particular query is HTDELETE

You should post a new question with relevant details.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.