Hi, we migrated a database from a SQL Server 2008 server (production) to a SQL Server 2008 R2 server (test - version 10.50.4000). The test server has the trace flag 4199 enabled. The original production server does not use the trace flag. One of the queries (with a complicated ON clause) became very slow. As soon as I removed the trace flag and restarted, the query is fast again.
With T4199: (takes 30 seconds)
Table 'complaint_data'. Scan count 12296800, logical reads 39196050, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'enhancement'. Scan count 4, logical reads 101956, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'charging_language_segment'. Scan count 9, logical reads 38, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'charge_filed'. Scan count 1, logical reads 3, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'defendant'. Scan count 1, logical reads 2, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Without T4199: (takes less than second)
Table 'Worktable'. Scan count 0, logical reads 0, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'complaint_data'. Scan count 80, logical reads 320, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'charging_language_segment'. Scan count 9, logical reads 38, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'enhancement'. Scan count 3, logical reads 33, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'charge_filed'. Scan count 1, logical reads 3, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'defendant'. Scan count 1, logical reads 2, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
I did update the usage and statistics, but it made no difference. I removed the T4199 flag from startup. I was able to use DBCC TRACEON one at a time, usinghttp://support.microsoft.com/kb/974006, and isolate the issue to trace flag 4126 (http://support.microsoft.com/kb/959013). I had to use "OPTION(RECOMPILE)" to insure I was getting a new plan each test. This flag does not seem to have anything to do with this query. I don't see any local publications or subscriptions.
Here's the query. (Yes, that's an ugly ON clause. This is ancient code. I did create a version that optimizes with or without the trace flag, but we have a lot of other code to worry about. A developer just happened to notice this issue on this query.)
DECLARE @case_sid int SET @case_sid = 132970 SELECT COUNT(DISTINCT CAST(e.enhancement_number AS VARCHAR(10)) + CAST(c.segment_number AS VARCHAR(10))) FROM charging_language_segment c INNER JOIN enhancement e ON c.offense_sid = e.offense_sid AND c.segment_type IN ('CITY', 'CNTY', 'CRTN', 'CRTP', 'FARM', 'JNDR', 'NAME', 'NAR', 'SEL', 'ST', 'VHCL', 'WPN') AND e.charge_sid IN ( SELECT charge_sid FROM charge_filed WHERE defendant_sid IN ( SELECT defendant_sid FROM defendant WHERE case_sid = @case_sid ) ) AND 'E' + CAST(e.enhancement_number as varchar(9)) + '_' + CAST(c.segment_number AS VARCHAR(9)) NOT IN (SELECT DISTINCT cd.count_number + '_' + CAST(cd.segment_number AS VARCHAR(9)) FROM complaint_data cd INNER JOIN enhancement e2 ON cd.count_number = 'E' + CAST(e2.enhancement_number AS VARCHAR(9)) AND cd.case_sid = @case_sid AND cd.complaint_data_value IS NOT NULL AND cd.complaint_data_value <> '') OPTION(RECOMPILE)
Does anybody have any advice? Perhaps T4199 is no longer an option once we have production code not using the flag?
Thanks, Randy
Randy in Marin