Skip to main content
5 votes
Accepted

Is my query having Parameter Sniffing performance issue

nope You don't have a parameter sniffing problem because you don't have any parameters. You are using local variables, which means you'll always get the same density vector estimate no matter which ...
Erik Reasonable Rates Darling's user avatar
4 votes
Accepted

Will the query time increase?

Think of a telephone book. Does it take longer to search for a name if a telephone book for a larger city, with thousands or millions of people? Yes, of course it does. But doubling the number of ...
Bill Karwin's user avatar
3 votes
Accepted

How do I tell Postgres to only scan the newest values in this query?

It's the classic "Top-N by category" problem, with a bit of a plot twist. Fastest solution will probably be a lateral join. This allows executing a join with a dependent subquery. If you ...
bobflux's user avatar
  • 1,706
1 vote

Why do I get a statement timeout when dropping a column from a large table?

It's slow because something has the table desciption locked. If there is an autovacuum, dump, or other slow process locking the table description you should wait for that to complete first. You are ...
Jasen's user avatar
  • 3,622
1 vote

Will the query time increase?

Will it increase? Almost certainly. By how much? As with all things, it depends. If you are finding rows by a single values on a uniquely-indexed field, the query can use an index (possibly the ne ...
Phill  W.'s user avatar
  • 9,486
1 vote

transactions without a corresponding session in sql server

My guess is that they belong to internal sessions used by SQL Server engine. I have an instance on my desktop, which I just started in order to check that, and after executing that same query the ...
Ronaldo's user avatar
  • 5,926
1 vote

Is my query having Parameter Sniffing performance issue

ymmv A further option/improvement to @ErikDarling's answer is to use window functions instead of those CROSS APPLYs. DECLARE @orgId integer = 22, @salesperson integer = 0, @sql nvarchar(...
Charlieface's user avatar
  • 14.6k
1 vote
Accepted

Sql Server: Query to parse and validate codes

One relational way you can do this is by splitting your #SourceData first (fortunately you have access to the STRING_SPLIT() function despite being on an outdated version of SQL Server), then getting ...
J.D.'s user avatar
  • 39.5k
1 vote

Sql Server: Query to parse and validate codes

-- first thing that comes to mind: SELECT sd.ID , sd.Codes , CASE WHEN NOT EXISTS ( SELECT x.[value] FROM string_split(sd.Codes, ';') as x ...
Doug Hills's user avatar

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