« first day (2408 days earlier)      last day (2461 days later) » 

12:50 AM
@JoeObbish boidh
@JoeObbish do you mind if I piggyback your post on row group elimination to test some other stuff?
 
@sp_BlitzErik b?
@sp_BlitzErik Please do, that's part of why I post them
blog?
 
@JoeObbish blog.
Is it similar to this? queryprocessor.com/sudf-ce
 
@sp_BlitzErik No, it's not a CE change
the scalar UDF only gets executed once per query instead of once per row without any tricks
8
Q: How can I force a scalar UDF to be evaluated just once in a query?

Joe ObbishI have a query which needs to filter against the result of a scalar UDF. The query must be sent as a single statement (so I can't assign the UDF result to a local variable) and I cannot use a TVF. I am aware of the performance issues caused by scalar UDFs, which include forcing the entire plan to...

As far as I know, it used to just not be possible
 
1:06 AM
Interesting. Under what circumstances?
 
very limited, most likely
I plan to write up a short post about it this week
SELECT MAX(l.ID)
FROM dbo.MILLIONAIRE_CCI l
WHERE l.ID = dbo.CHEAP_UDF();
it happens in that query
didn't realize what was happening at the time
 
What if you put it in the select list?
 
@sp_BlitzErik It's executed twice per query, instead of twice per row
which is surprising
the query plan is very misleading
even more than usual for scalars
 
1:27 AM
On which version?
 
2:05 AM
> 2016
 
Weird I've run tests with a very similar function and didn't see a reduction in executions. Did you check the stats functions DMV?
 
using sys.dm_exec_function_stats
what's your repro?
 
3:13 AM
@JoeObbish will share tomorrow, going to bed
 
 
3 hours later…
6:28 AM
@JoeObbish Can you share a repro and plan? What you're saying seems to be expected behaviour, but it's hard to be sure without seeing details.
 
6:59 AM
MOrning
 
Good morning all.
0
Q: Hash keys probe and residual

TheGameiswarSay we have below query , select a.*,b.* from a join b on a.col1=b.col1 and len(a.col1)=10 Assuming above query uses Hash Join and has a residual,probe key will col1 and residual will be len(a.col1)=10 But while going through an example,i could see both probe and residual being the same colu...

Not sure what OP really is after but if the question is why there is a probe residual at all it is interesting.
After some digging I found something called unique hash optimization.
There ought to be a blog post about that one somewhere right?
If not perhaps in a near future (@PaulWhite nudge nudge :) )
 
7:52 AM
But basically if the hash function isn't perfect, you need to test the items in the hash bucket for an actual match
Added a brief answer, I might expand it later
 
Forgot about the tags. Thanks, Paul
 
No worries, thanks for saving me a job on the question body!
 
It was the ASK that prompted it.
 
@PaulWhite Thanks!!
 
8:09 AM
@AndriyM Yes that's a strange modern usage. I'm happy with the phrase "a big ask", but labelling a question as an "ask" grates on me.
3
 
8:26 AM
Apparently bit (no surprise there) and smallmoney and smalldatetime can be added to the list of columns that has a perfect hash.
 
@PaulWhite I think it's an Indian thing
 
8:42 AM
26
Q: Can or should "ask" ever be used as a noun?

ukayer"The ask is that you provide me with..." I started hearing "ask" being used as a noun a few years ago. Is this a recent trend? Is it an East Coast thing, unique to North America, or just unique to the in-house vocabulary of telecommunications companies?

 
8:57 AM
Hello
 
Hello
 
I face a weird thing , but I don't know if I can ask this Q in DBA
That weird thing is:
We all know rextester and use it to compile codes
so I do the same
The result is not the same if you run this code in SQL Server
 
In what way is it different? formatting?
 
No , the result
In rextester the result is:
06.08.2017                    12.08.2017
but in SQL Server:
07-08-2017           13-08-2017
 
Can you run SELECT @@DATEFIRST; in Rextester and in your SQL Server instance and tell us the results?
 
9:04 AM
Is @@DATEFIRST have an effect
 
I think it might
 
Ah , ok i got it now
thank you very much :)
 
> When datepart is week (wk, ww) or weekday (dw), the return value depends on the value that is set by using SET DATEFIRST.
 
Yeah , thank you for help
 
9:23 AM
Morning all
 
9:37 AM
Kopisanangan dongkosuabon (Central Dusun)
 
Central Dusun?
No wonder it sounded unfamiliar
6
 
10:04 AM
@MikaelEriksson oh that's interesting I wonder if that changed at some stage. Want to edit something about that into my answer?
 
10:16 AM
@hot2use Is different at North Dusun?
 
10:33 AM
@PaulWhite not really, might encourage some bad design choices :). I tested in 2016. I thought perhaps date would work as well since it did with other "smallish" data types. But it did not.
 
@McNets not sure
 
10:49 AM
@MikaelEriksson Ha, fair enough
 
@PaulWhite or it could be a lesson about right sizing and an unexpected benefit of using smaller data types. But still no.
 
11:15 AM
@MikaelEriksson Also (var)char(1) with binary collation. Added a small footnote.
 
@hot2use Wilujeng siang (Sundanese)
 
@PaulWhite Oh, tested char(1) but never thought about collation.
 
11:39 AM
@MikaelEriksson You can calculate a perfect hash function for just about anything but it's a trial and error process so it can get quite long winded.
In computer science, a perfect hash function for a set S is a hash function that maps distinct elements in S to a set of integers, with no collisions. In mathematical terms, it is an injective function. Perfect hash functions may be used to implement a lookup table with constant worst-case access time. A perfect hash function has many of the same applications as other hash functions, but with the advantage that no collision resolution has to be implemented. == Application == A perfect hash function with values in a limited range can be used for efficient lookup operations, by placing keys from...
 
12:01 PM
The developers are going to hate me this afternoon :) I'm rebuilding a bunch of indexes with compression and I'm starting to see their requests being blocked
 
 
1 hour later…
1:02 PM
@TomV Good job
 
1:35 PM
@TomV no online rebuilds?
 
@sp_BlitzErik Not from dynamics AX no
 
:wat:
 
@sp_BlitzErik is this your sockpuppet account?
0
A: SQL Performance when containing a CASE statement within an ISNULL

EliThere are probably better places to focus your attention. For the fun of it, I tried this particular question which you posed and the query plans were identical. If you're having performance issues, perhaps get yourself your free copy of the Brent Ozar's tools: https://www.brentozar.com/askbr...

 
@sp_BlitzErik To be precise, if you change the compression (or anything else in the index definition) it drops & recreates the index
(y)
Of course your maintenance can do online rebuilds
 
@Lamak @PaulWhite is my sock puppet account
 
1:42 PM
sh!
 
1:55 PM
@sp_BlitzErik The implementation is really neat, I only needed to change one line of code to make it work with SQL 12.something
if (sqlVersion = '11.')
 
 
1 hour later…
3:01 PM
@PaulWhite looks like you're right
no VIEW SERVER STATE but you'll get the idea
did I just never notice this behavior before? maybe the problem is the lack of WITH SCHEMABINDING at work...
 
@JoeObbish I could've told you that, no testing needed
 
3:13 PM
@JoeObbish try this function with your query
	CREATE FUNCTION dbo.ScalarID (@Id INT)
	RETURNS INT
		WITH RETURNS NULL ON NULL INPUT, SCHEMABINDING
	AS
	BEGIN

	RETURN 2147483647

	END;
	GO
it'll execute 2537 times
or however many rows you have in master..spt_values;
SELECT *
FROM   udf_test
WHERE  id > dbo.ScalarID(id);
so perhaps it's not schemabinding, it's passing something in
your function returns a static result with no inputs
 
never seen WITH RETURNS NULL ON NULL INPUT before
inputs are ok if they don't do anything
 
an awe-struck little doe appears
 
I can get it to work with inputs
 
this is what i see when i run it
 
begin
RETURN @Id;
end;
 
3:22 PM
 
can you make the picture longer? thanks
 
stop imitating @Lamak
 
low blow
 
Aug 2 at 17:52, by Lamak
@sp_BlitzErik can you make that smaller?
 
it's weird
if this works how I think it does then there's actually a use case for using these in queries
 
3:25 PM
sys.dm_exec_function_stats agrees
 
I don't believe it
it works with a table
create or alter function stupid_udf (@Id INT) returns bigint
with schemabinding
as
begin
RETURN (SELECT val from dbo.map_table where id = @id);
--RETURN @Id;
end;
 
i think you've had too many shirley temples
 
that doesn't work for you?
I'll post the full thing
 
i'm on 13.0.4422.0
 
I'm on 13.0.4435.0
> still being on 13.0.4422.0
@Lamak Can you try the demo? or would that be too helpful?
 
3:35 PM
@JoeObbish I can
what demo?
 
need to run it somewhere you have VIEW SERVER STATE
thanks!
 
ok
 
Erik, what I just posted really doesn't work for you?
 
the first one does, yes. as soon as i added an input to it, it stopped working though.
 
@JoeObbish you'll have to wait though, I only have that permission in an SQL Server 2008R2 instance, and apparently I can't see sys.dm_exec_function_stats
 
3:40 PM
it's new in 2016
@sp_BlitzErik Works on my machine (TM)
you're using the exact code that I posted here? dbfiddle.uk/…
 
21 hours ago, by sp_BlitzErik
@JoeObbish socks to be you
so a function that takes no input and returns a static result may run once per query rather than once per row
that sounds useful
 
I have a demo that takes an input and queries a table
you know what
fine
 
show me that one
 
you asked for it
the pain is coming
I was going to make a gif
but now it doesn't work
 
the virgin daiquiris must be kicking in
 
3:50 PM
I blame dm_exec_function_stats
bet there's a bug
there are some use cases
are they stupid use cases? yes
 
it can't possibly be the known behavior of scalar functions
gotta be a bug
 
but that's all it was going to be anyway
known according to who? Pablo Blanco?
 
well, it's known to me, so it can't be too deep in the debugger
 
I can get it to work with an input and an output that changes based on the input
What are the criteria for a function to be executed once per query?
 
returning one row?
:D
 
3:53 PM
ahem
I think that you meant "processing one row"
 
yes
yes indeed
mon petite pedant
 
NEWID() returns one value. Is it executed once per query?
 
@ypercubeᵀᴹ it can be
depends on the query
 
i was just trying with RETURN @@SPID and RETURN @@ROWCOUNT
 
probably won't work, not sure though
@ypercubeᵀᴹ for example:
SELECT *
FROM udf_test
WHERE RIGHT(BINARY_CHECKSUM(NEWID()), 2) = 10
it's a startup expression
but if I do this:
SELECT RIGHT(BINARY_CHECKSUM(NEWID()), 2)
FROM udf_test
get lots of different values
 
4:46 PM
so how's the demo?
 
5:00 PM
@sp_BlitzErik which demo?
 
1 hour ago, by Joe Obbish
the pain is coming
 
@sp_BlitzErik it turned out the pain was coming for me
I was going to make a gif of the demo but the demo stopped working
 
@JoeObbish did you brace yourself?
 
I did not
 
that's where it went wrong
 
5:07 PM
 
5:18 PM
> Engage with the SQL Server engineering team
Stack Overflow (tag sql-server) - ask technical questions
first time I notice that
 
5:35 PM
approving DDL created by data architects and developers is depressing.
 
@MaxVernon I'm a developer!
 
@JoeObbish ok, not you :-)
I should have stated "present company excluded, of course"
because at heart I'm a developer too.
but really, why do you need an indicator column to be a char(1) with "Y" or "N"
and it to be NULLABLE.
 
What's your preferred data type for that?
 
and, never heard of RI of course.
a bit
preferably not nullable.
 
I don't like bits personally
 
5:40 PM
I mean, you either are or you aren't.
 
can't take aggregates of them
it's weird
seems like there are unnecessary restrictions in how you can query them
 
@JoeObbish this is my main issue with them too
 
ok, then an INT if you really want to do that.
or even a tiny int
a char is just total overkill.
storing a "percent complete" in a char(15) seems a bit strange to me too
 
sure, I get what you mean
at this point I don't even notice minor (?) mistakes like that
don't know if that's good or bad
the percent complete one is definitely odd
 
and apparently since the data comes from a source system that has RI, he doesn't need RI in this database.
^^^ And Now for Something Complete Different
 
5:59 PM
@MaxVernon with data like this?: 'A', 'AA', 'AAA', 'AAAA', 'AAAAA', ..., 'AAAAAAAAAAAAAAA'
 
lol exactly
 
makes sense.
AAAAAAAAAAAAAAA sense
 
each 'A' indicates 6.666% complete.
because that totally makes sense. And it's flexible. You could use 'B' to mean something else. ;-)
 
6:57 PM
@MaxVernon like what?
 
3.333% complete?
 
ah. yeah. i guess i can see that
 
@MaxVernon I refuse to believe this
 
YOU CAN'T HANDLE THE TRUTH
 
ok, so the source data is like "Under 25" or "25-49" or "50-74" or "75-99" or "100".
kill.me.now.
seems to me like that would be perfect example of a lookup table, with RI
 
7:11 PM
are you doing market research?
 
@sp_BlitzErik you can't make me answer that.
:-)
 
@swasheck I can't
 
7:37 PM
ugh. tapped for a "cloud strategy" meeting at the office.
my strategy is, "don't"
at least not for mission-critical things
 
which cloud?
some clouds are bigger than others~
 
amazon
 
as far as clouds go, that's the least crappy
 
that's like saying that the best STD is syphilis
 
does varchar2 handle unicode data in Oracle?
 
7:39 PM
it's not, it's chlamydia
trust me
 
@sp_BlitzErik that's definitely star-worthy
 
gbn
I quite like AWS
Avoid RDS though
 
@gbn well that's the problem (good to see you). it's not so much that i dislike AWS ... it's that i dislike the direction we're taking it. saying on 1 AZ (good call!) and they're pushing RDS even though i've highlighted many of the drawbacks
 
what about it do you consider a drawback?
i'm not arguing, just curious
 
7:48 PM
performance is worse than a similarly-configured EC2 instance
restoring requires creating a new instance (yes. we restore a lot - especially to preprod)
minimal control over file layout and other knobs (yes, i'm a control-freak DBA)
 
ooh. what's up with performance?
disks?
 
didnt take the time to isolate the issue, but IIRC, in my testing (in the us-east-1a region only, because BIDNESS) RDS was ~10%-15% slower than EC2.
 
ah, gotcha
i'm with you on restores though
the 30 database per instance limit can be a hassle for people, too
 
@sp_BlitzErik we dont have that problem (yet)
 
devs are silly like that
(removed)
 
8:06 PM
@MaxVernon unless your database character set doesn't — in which case you could use nvarchar2
 
I'm going to write an answer that recommends a scalar UDF to be used in queries
come at me, haters
 
can you be sent to jail for answers on this site?
find out in 10 minutes!
 
Anyone have any intuition as to why a SELECT * FROM .... query would perform worse than a SELECT * FROM .... WHERE x = '' query, when the queries return the same data minus two rows for the second? (SQL Server 2012)
(I don't have actual access to the database this happened on, but if what the person reported is true, that goes against everything I thought I knew.)
 
i wish i could downvote chat messages
 
@sp_BlitzErik you can move them to the trash
 
8:12 PM
@sp_BlitzErik Why's that? Each one returned ~240k rows, the second returned two rows less than the first, but that's the only difference. I assumed that SQL Server used available indexes for the second to avoid a raw table scan, but I honestly have no idea.
 
@EBrown there are dozens of reasons. you should post a question on the main site
 
which indexes did they use?
 
@JoeObbish Eh, I wasn't the one who found it, was helping a colleague in a different chat room find out what was going on, I don't have access to any of the database used here.
 
when you say table scan, do you mean the table is a heap?
 
@sp_BlitzErik That I'm not certain, colleague couldn't post execution plans.
@sp_BlitzErik Unclear, I assume not, but it could have been. What I do know is performance was several orders of magnitude different, like several seconds for SELECT * FROM... and less than half a second for WHERE x = ''.
 
8:14 PM
tea leaves and chicken bones
 
The WHERE clause only filtered out 2 rows apparently, so I'm wondering what could have made it perform superior to the raw SELECT.
 
@EBrown Why persist in helping him when he won't help you?
 
@Forrest Eh, not really helping him at this point, I just wondered for my own education/knowledge.
 
@EBrown ok, that person should post the question then
there are lots of smart people on the main site who don't come into here
 
Yeah, and I also require a somewhat concrete example to post on the main site.
I don't have any of the specifics, going to try to recreate it as best I can, but no guarantees.
 
8:18 PM
how can you hope to repro it without any specifics?
 
@sp_BlitzErik I do that all the time on here
but only for those sweet, sweet unicorn points
 
@JackDouglas thanks!
 
@JoeObbish but you know what you're doing, kind of
 
@sp_BlitzErik I can't, but I can at least give it a minimal effort attempt.
 
@JoeObbish i'm having a joyful time with the piggyback post
 
8:21 PM
@sp_BlitzErik you mean the blog?
 
yeah
 
good
I have high expectations
 
don't forget the ®
 
is it "great" or "good"?
 
usually great
 
gbn
8:27 PM
@swasheck this. Lack of ad integration unless you use their Open LDAP
Fine control of backups
 
1 message moved to Trash
you might even earn a "Great Post Brent! ®"
 
that is my goal in life
well, that and a 500lb squat
 
@JoeObbish I have an actual data-set to test with now, and I'm seeing ~0.2-0.3s faster times for WHERE StrValue3 = '' which only filters two rows (the first two) out of this table. Possibly going to make it a main-site question if you care to comment on it.
 
9:13 PM
@gbn si
 
9:39 PM
@EBrown if you post a question with one of my tracked tags I will look at it
can't promise an answer or anything like that
 
 
2 hours later…
11:38 PM
@sp_BlitzErik - I love the OPs answer to your question about 27 indexes on individual columns. I don't think he gets it at all, and I don't think he knows about INCLUDE.
 
@MaxVernon yeah, this is a nuclear potato
 
Well, he pasted the plan.
I love that he has an index named [<name of missing index>]
3
 
<sigh>
>Consider that you execute a query that retrieves data from a clustered columnstore index in Microsoft SQL Server 2014 or 2016. If the data pages are too far apart, you may receive an access violation error.
This CU is wild
 
lol:
the plan you pasted is different. It has no Key Lookup. — Max Vernon 17 secs ago
 
11:59 PM
Smh
 

« first day (2408 days earlier)      last day (2461 days later) »