Skip to content

Updates_20261201 - Plans, Trains and Automobiles

Latest

Choose a tag to compare

@erikdarlingdata erikdarlingdata released this 23 Nov 21:10

This release adds @plan_parsing to sp_QuickieStore. With @plan_parsing = 1, the procedure reads the plans in Query Store and reports plan findings. Examples are eager index spools, missing indexes and predicates that cannot use a seek. sp_QuickieStore with @get_all_databases = 1 no longer stops when one database is unreadable. A round of reviews fixed smaller problems in nine procedures and in the helper scripts.

Changes in behavior

  • TestBackupPerformance: the test backups now use COPY_ONLY. Before, each test backup became the new differential base, even a backup to NUL. The next scheduled differential then depended on a backup that no longer existed. Test backups now leave the differential base and the backup chain unchanged. (#951)
  • sp_HealthParser: with @warnings_only = 1, the QUERY_PROCESSING, SYSTEM and cpuIntensiveRequests results now keep rows with the state ERROR, as well as WARNING. Before, a component in ERROR was filtered out, so the output looked like an all-clear. (#945)
  • sp_HealthParser: with @warnings_only = 1, the memory broker rows now keep only the SHRINK notification. Before, the filter compared the notification with RESOURCE_MEMPHYSICAL_LOW, which a broker row never holds. The result was always "no memory pressure events found". With @warnings_only = 0, every row still returns. (#960, #941)
  • sp_HumanEvents: @target_output = 'event_file' now raises the existing "not supported" message on Azure SQL Managed Instance. Before, only Azure SQL Database got the message, and Managed Instance got a raw CREATE EVENT SESSION error. (#945)
  • sp_HumanEvents: an output table must be a table. If a view or a synonym already has the name of an output table, the procedure stops with an error. Before, it logged through the view or synonym, and the hourly retention DELETE ran against whatever the name pointed to. (#945)
  • sp_HumanEvents: when blocking events are logged, the row for each blocking episode now keeps the earliest report and the largest wait_time of the episode. Before, it kept the last report. Rows that tied on the sort now have a fixed order, so a rerun returns the same order. (#935)
  • sp_QuickieStore: with @get_all_databases = 1, the procedure skips a database that the caller cannot enter, and a database where the caller cannot read Query Store. Before, one such database stopped the whole run with Msg 916, 924, 976, 297 or 262, and no database returned rows. The footer lists a skipped database that you name in @include_databases, with the reason No database access or No permission to read Query Store. The Query Store check uses VIEW DATABASE PERFORMANCE STATE on SQL Server 2022 and later, and VIEW DATABASE STATE before that. The old availability group filter is removed, because it never excluded a database. A login without the server permission VIEW SERVER STATE (VIEW SERVER PERFORMANCE STATE on 2022 and later) still fails with Msg 300, because the procedure reads sys.dm_exec_query_stats. (#947, #950)
  • sp_QuickieStore: these parameters are now lowercased before the checks run: @sort_order, @regression_comparator, @regression_direction, @execution_type_desc and @wait_filter. When the database that holds the procedure uses a case-sensitive collation, @sort_order = 'Duration' used to fall back to cpu. @regression_direction = 'Improved' used to fall back to 'regressed', which reverses the ranking. 'Regular' and 'Lock' were rejected. (#949)
  • sp_QuickieStore: a blank @include_ list is now ignored. Before, a blank list together with another id or hash list, such as @ignore_plan_ids, returned no rows and no error. (#949)
  • sp_QuickieStore: @duration_ms now works on plans and not on intervals. A plan qualifies when any one of its intervals in the time period meets @duration_ms. Executions, totals and averages then cover every interval of the plan in the period. Before, the procedure dropped the faster intervals first, so a plan with six runs that averaged 474 ms showed as one run of 2,842 ms. With @execution_count = 6, that plan disappeared. (#949)
  • sp_QuickieStore: in regression mode, @execution_count and @wait_filter no longer hide a plan that ran only in the baseline period. Before, a plan change between the two periods was missing from the output. With @duration_ms, a plan also stays when either period meets the value. (#949)
  • sp_QuickieStore and sp_QueryReproBuilder: an @end_date with no @start_date now covers the seven days before @end_date. Before, the default start was seven days before today. With an old @end_date, the start fell after the end, and the procedures moved the end date and gave no message. The run then covered the last week, not the dates you asked for. Any @end_date that you pass alone now gives a window of exactly seven days. (#948)
  • sp_QuickieStore and sp_QueryReproBuilder: the last_ columns now come from the latest execution. Before, they came from the execution type with the largest value. A plan with an aborted run and a newer regular run showed the aborted run as the last one, when it was larger. The last wait column in sp_QuickieStore follows the same rule. (#948)
  • sp_QuickieCache: with @find_single_use_plans = 1 and @find_duplicate_plans = 1 together, the procedure now returns both lists, in two result sets. Before, it returned only the single-use list and gave no message. (#944)
  • sp_LogHunter: the noise filter no longer removes lines that your own @custom_message search finds. Before, a search for text such as Login failed, SSPI or Starting up database returned nothing. This also applied to the SPN messages and to any line with Severity: 10 to 18. The default run still removes those lines. (#943)
  • sp_LogHunter: the SPN filter now matches Service Principal Name (SPN) and not any line that contains "spn". Before, a line about a database such as ESPN_Sales was hidden in the default run. Expect to see lines that the old pattern removed. (#943)
  • sp_QueryStoreCleanup: a NULL @report_only now means report only. Before, only the value 1 reported, so NULL removed queries and compacted tables. (#946)
  • WhoIsActive Logging: sp_WhoIsActiveLogging_Retention raises an error when @RetentionPeriod is below 1. Before, 0 or a negative value dropped every WhoIsActive_YYYYMMDD table, including the table for today. (#946)
  • Helper Views: WhatsUpLocks shows only locks in the current database. Before, a lock in another database appeared under the name of a local object when the ids matched. Locks with no matching object, such as APPLICATION and METADATA locks, now return with a NULL locked_object. (#955)
  • Helper Views: WhatsUpMemory counts only pages cached for the current database. Before, it counted pages of other databases that had the same allocation unit id. (#955)
  • Helper Views: WhatsUpIndexes now reports in_row_pages_mb from the in-row pages only. Before, it also counted LOB and row-overflow pages, so LOB pages showed twice. A new column, row_overflow_pages_mb, comes after lob_pages_mb. A query that uses SELECT * from the view, or column positions, sees the new column. (#955)
  • Inline Financial Functions: EffectiveAnnualInterestRate_Inline returned 0 for every rate below 100%. It now applies the formula to every rate, including a negative rate, and returns 0 only when the number of periods is below 1. So (0.10, 2) returns 0.1025 and (-0.01, 12) returns about -0.00995. FutureValue_Inline at a rate of 0 multiplied the starting value by the number of periods. It now returns value + payment * periods, so (0, 10, -100, -1000, 0) returns 2000 and not 11000. (#951)
  • Export-SqlResults: a statement with no result set no longer takes a result set number, so resultset01.csv is not skipped. File names and manifest numbers change for a script that has batches such as SET or PRINT. (#953)

sp_QuickieStore: plan parsing

@plan_parsing bit = 0 is new and opt-in. With @plan_parsing = 0, nothing changes. With @plan_parsing = 1, the procedure converts each plan to XML once and reads the XML into temp tables. Then 19 rules run over the temp tables as plain T-SQL.

  • The procedure returns one extra result set after the other results. It has one row for each plan and rule, with the columns database_name, query_id, plan_id, rule_id, rule_name, finding, object_name, node_ids. finding explains the problem in a sentence. node_ids lists the plan operators, for example 4, 7, 12 and 3 more.
  • The rules are numbered. Rule 0 reports a plan that was not checked, because Query Store has no plan text or the plan will not convert to XML.
  • Rules 1 to 4: eager index spool, serial plan, scalar UDF, lookup with predicate.
  • Rules 5 to 7: NOT IN on nullable column, implicit conversion prevents seek, missing index request.
  • Rules 8 to 10: late filter, scan with residual predicate, non-SARGable predicate.
  • Rules 11 to 13: multi-statement table-valued function, TOP over scan, many-to-many merge join.
  • Rules 14 to 16: table variable, remote query, wide DML.
  • Rules 17 to 19: Standard Edition batch mode DOP 2, scan on inner side of nested loops, long compile.
  • Rule 1 writes a CREATE INDEX statement in the finding. For a spool on a table variable, it suggests an inline index in the DECLARE, or a temp table.
  • Some findings need a value to reach a threshold. The thresholds are 1 second of average CPU, duration or compile time, and 1,000 executions a day. A scan must cover 1,000,000 rows, and a wide DML statement must maintain 5 indexes. They are @pp_* variables at the top of the plan parsing section in the procedure. They are starting values.
  • Large numbers in the finding text have thousands separators. (#932)
  • The procedure rejects @plan_parsing = 1 together with @find_high_impact, @find_parameter_sensitive, regression mode or @log_to_table. It raises a severity 11 error.
  • On the author's test server, @plan_parsing = 1 added CPU time to the same call. It added 1.1 to 1.4 seconds at @top = 10, 5.2 to 10.8 seconds at @top = 100, and 30 to 32 seconds at @top = 500. The plans came from three databases of different sizes. The cost grows with the number of plans, so keep @top small. (#931, #934)
  • A set of 24 review patches made the passes read less XML and made the findings more exact. In particular, rule 8 skips bitmap probes and filters on aggregates and windows. Rule 3 blames a scalar UDF for a serial plan only when the plan says the UDF caused it. (#934)

Known limits:

  • Rule 5 runs only when the query text has NOT IN or <> ALL. It misses a NOT IN inside a view or a function.
  • The thresholds are fixed starting values. To change them, edit the @pp_* variables.
  • Rule 2 and rule 17 read the MAXDOP settings when the procedure runs, not when the plan compiled. A finding that depends on MAXDOP can be wrong, and the text says "likely".
  • The inserts into the plan parsing temp tables use TABLOCK and MAXDOP 1, so they run serial. The reason is that parallel startup cost more than these small inserts.
  • With @debug = 1, the dump of #plan_edges is partial. The edge pass opens only the statements whose rules read edges.
  • Not tested: rules 15 and 17, and rule 14 on real plans. Also not tested: Azure SQL Database, Azure SQL Managed Instance, and a Resource Governor group with max_dop 1. Rule 8 on a Hash Match semi join probe has no test fixture.

sp_QueryReproBuilder

  • The repro pasted two kinds of compiled parameter value as bare text. One is a CLR type, such as geography, geometry, hierarchyid or any other schema-qualified type. The other is sql_variant. The script then failed with Msg 102 or Msg 207, or a quoted-looking value came back as an int. The procedure now writes each of these values as N'...' with the quotes doubled, and SQL Server parses the text back into the type. A NULL stays NULL. (#944)
  • Two new repro warnings explain what the plan does not record. spatial parameter SRID says that the repro uses the type default, which is 4326 for geography and 0 for geometry. sql_variant parameter says that the repro binds the value as nvarchar. (#944)

sp_HumanEvents and sp_HumanEventsBlockViewer

  • The procedures read the blocked process attributes in one pass, and they read the event values in one pass with a PIVOT. The BlockViewer reads the reports once into a staging table before it logs them. The test used 3,032 blocked process reports. The CPU of sp_HumanEventsBlockViewer went from 46,545 to 24,893 ms with event_file. It went from 46,798 to 26,624 ms with a ring buffer, and from 45,109 to 23,250 ms with a table. The same run of sp_HumanEvents with blocking went from 44,734 to 25,062 ms. The logging insert and update went from 31,641 to 9,563 ms. These are the author's numbers. The staged logging insert also asks for a much smaller memory grant. (#935)
  • The result sets have the same rows and columns as before. (#935)
  • The name compares in the logging step use the collation of the database that holds the procedure. The last_updated value in #human_events_worker no longer moves on a pass that only inserts. It appears only in the @debug output. (#935)

sp_PressureDetector

  • With @log_to_table = 1, each run no longer logs the newest CPU sample again. The sample time of a ring buffer record changed by up to a second from run to run. The check for new records then passed it again. The cutoff is now the last logged time plus 2 seconds. In the test, three batches of eight runs logged 3 to 4 duplicates before, and 0 after. (#946)

Scripts and repo changes

  • TestBackupPerformance: the @help text and the README say that the test backups are copy-only. (#951)
  • Inline Financial Functions: see Changes in behavior for the two fixes. (#951)
  • Helper Views: the README examples now run. They used in_row_mb and wum.pages, and they called WhatsUpLocks without a second parameter. They now use in_row_pages_mb and buffer_cache_pages_total, and DEFAULT for the second parameter. A new example reads the locks of another session. (#955)
  • Agent job scripts for sp_HumanEvents, WhoIsActive Logging, Clear Token Perm and Ola Stats Only Job no longer name the login sa. They use the login for the sa security id, so they work on a server where sa has another name. (#946, #953)
  • Clear Token Perm: the header and the README say to install the procedure in master, or to change @database_name in the job step. The Inflate Security Cache demo now reports gigabytes, as ClearTokenPerm does. (#953)
  • ProtectSession: the README and one comment now say that an error in the snapshot query reaches the outer CATCH, and the procedure ends. Only the two KILL statements have their own TRY/CATCH. The code is unchanged. (#953)
  • Export-SqlResults: the script now writes manifest.csv even when a batch raises an error, and the error still reaches the caller. The README table lists the PowerShell parameter names, such as -ServerInstance. (#953)
  • String Functions: strip_characters and strip_characters_cte keep trailing spaces. Before, an input such as ab12 with the pattern 0-9 returned ab. An input of only spaces returned NULL. The README now documents Msg 6841 for kept text that has a control character, and gives a workaround. (#957)
  • Dynamic SQL Logging: physical_reads_mb was negative on a warm cache, because the script subtracted logical reads from reads, which is already the physical count. It now uses reads. (#957)
  • SQL Debug Example: the print loop no longer repeats one character at the start of each block. The default run no longer fails with Msg 103. (#957)
  • The sp_HumanEvents and sp_PressureDetector installers: the message and the header now show -v TargetDB="name". go-sqlcmd rejects the old form with spaces around the equals sign. Both READMEs have an "Install with sqlcmd" section. (#956)
  • Docs: the sp_HumanEvents README names the real default session of sp_HumanEventsBlockViewer. The sp_QuickieCache examples say "on or after a date". The sp_IndexCleanup help and READMEs say that @get_all_databases is not supported on Azure SQL Database. The root README lists six more folders. (#956)
  • Docs: CONTRIBUTING and the Install-All README say that CI builds Install-All/DarlingData.sql and that a pull request must not change it. They also describe the dev-latest pre-release. The style list points to the repo style guide. The issue templates list sp_QuickieCache and sp_HumanEventsBlockViewer, and the dead Discussions link is gone. (#952)
  • The README links to the AI training workshop, the video course, the consulting page and the one-on-one day. (#942, #962)
  • The repo no longer tracks .vs/, _config.yml, CNAME, two empty image files and todo.md. .gitignore lists .vs/. (#959)
  • The sp_QuickieStore tests README lists the check count for each SQL Server version. (#958)
  • CI: a pull request now runs only the test harnesses for the procedure folders that it changes. A change to the shared files still runs all of them. (#936)
  • CI: the SQL tests use one sqlcmd, a lighter clone, and they cancel a pull request run that a newer push replaces. A new opt-in pre-push check is in .githooks/pre-push. (#938)
  • CI: workflows have least-privilege tokens, a pinned go-sqlcmd with a checksum, timeouts, and a concurrency group for the dev build. The push run of the SQL tests reports as SQL Tests (push), so it cannot stand in for the pull request check. (#954)
  • CI: the branch check now passes branch names through the environment, runs only for pull requests into main, and no longer uses pull_request_target. (#939, #961)

All ten bundled procedures move to minor version .12, with @version_date 20261201. That includes sp_PerfCheck, which has no change, and sp_IndexCleanup, which has a help text change. sp_QueryStoreCleanup moves to 1.12 and TestBackupPerformance moves to 1.2. ProtectSession is unchanged, because its change is a comment.