11

There are often several ways to derive a cardinality estimate, with each method giving a different (but equally valid) answer. That is simply the nature of statistics and estimations. You ask essentially why one method produces an estimate of 296.839 rows, while another gives 181.8 rows. Let's look at a simpler example of the same AdventureWorksDW2017 join ...


5

You should directly extract the values from the json array using the WITH clause, like this: SELECT src.* , tt.* FROM json_test src CROSS APPLY OPENJSON(src.the_json , 'lax $') WITH ( [name] sysname '$.name' , [object_id] int '$.object_id' , [principal_id]...


5

You can't, as far as I'm aware. One might try things like: OPTION (TABLE HINT (sp, READUNCOMMITTED)) ...but this will fail for things that aren't real tables. Table-valued or OPENROWSET function 'sp' cannot be specified in the TABLE HINT clause. It would also fail because the desired hint is semantic-affecting. If the thing you need to access doesn't ...


5

You need better indexing, and a bit of a rewrite. Because you’re only using one table, you can use ROW_NUMBER() in a sub-query and then grab the top row from each partition. SELECT grp_fk_obj_id, grp_name, grp_id FROM ( SELECT grp_fk_obj_id, grp_name, grp_id, ROW_NUMBER() OVER (PARTITION BY grp_fk_obj_id ORDER BY date_from DESC, ISNULL(date_to, '4000-01-...


5

This is a bug in the way SQL Server decides whether a rebind is required with certain plan shapes. It has been in the product since SQL Server 2005. Minimal repro This uses a trace flag to force a spool: CREATE TABLE #T (v integer NOT NULL); INSERT #T VALUES (1), (2), (3), (4); SELECT #T.v, A.* FROM #T CROSS APPLY ( SELECT #T.v UNION ALL ...


1

Scalar udf's may cause your query to run single threaded. See Ozar's post on the matter.


Only top voted, non community-wiki answers of a minimum length are eligible