« first day (1973 days earlier)      last day (2900 days later) » 

3:37 AM
@MichaelGreen I'm not entirely sure which the VP wants, I think that he's interviewing the first and wants the second. I'll know better on Tuesday :D
 
 
3 hours later…
6:25 AM
@EBrown Can you not achieve what you want simply by setting permissions?
 
6:36 AM
@PaulWhite I could, but that scares me. I'm no professional DBA and I have no backups of this DB.
 
6:57 AM
@EBrown As a non-DBA person, do you consider setting up and maintaining a shadow copy of a database to be less of a problem than setting up permissions? I'm not a DBA myself and I would most likely go for the latter, but I don't know if there are any peculiar details to your situation, of course.
 
@AndriyM I mean, I guess it doesn't matter all that much, I just don't know if maintaining permissions for many users is less problematic than maintaining a shadow copy.
 
If you care about the data at all, you must have tested backups.
Making the database read only between updates would be another option.
Create a read-only role (or use the built-in db_datareader role and add users to that. That is one easy way to manage permissions for many users.
 
I think the usual way is to set up roles, assign the necessary permissions to those roles, then assign individual users to the appropriate roles. You might even not need a custom role and use built-in ones instead.
 
Ha.
 
Indeed
 
7:03 AM
Is there anything that db_datareader gives them that could be potentially harmful?
 
3
A: Is there a difference between granting SELECT a user and adding them to the db_datareader role?

RLFRick Byham has a WIKI post showing the fixed server and fixed database roles and how they map. You can look here: http://social.technet.microsoft.com/wiki/contents/articles/database-engine-fixed-server-and-fixed-database-roles.aspx The chart shows that db_datareader role is identical to GRANT S...

@EBrown Well, it doesn't allow you to change anything, which seems to be your primary concern, but being able to read all data in the database might be 'potentially harmful', depending on what the database stores...?
 
I don't mind if they can read the entire database, provided that doesn't give them access to sensitive meta-data on the database.
There are 5 tables and 1 view in this DB, and I don't mind if they can read any of those.
 
db_datareader should be just fine then.
 
I also don't want them to be able to execute any potential SP's I might add.
 
But you still need to have tested backups just in case (of anything).
@EBrown It doesn't grant execute on anything.
It's literally SELECT on database.
 
7:11 AM
That should be fine then.
Is there a way to make a table SELECT/INSERT only?
I don't want to allow any UPDATE or DELETE statements on it.
From anyone, that is.
 
Setting permissions would be the main way. Nothing you can do to prevent an administrator from doing that, if they're determined.
 
I'm not worried about admin malicious intent, I just want to prevent accidents.
 
DENY UPDATE, DELETE ON OBJECT::[TableName] TO PUBLIC;
 
7:35 AM
> …but the recommendation is to move away from those roles to the more granular commands.
^^^ Curious, didn't know about that.
And MSDN certainly recommends nothing of the kind.
 
Good Morning guys!
 
8:00 AM
good morning
 
user image
2
@ConcernedOfTunbridgeWells ^^^ British humour at its most British
 
 
2 hours later…
9:53 AM
3 rows out from the filter, 5 from the Stream Aggregate.
Isn't that odd or is it expected ... sometimes?
 
 
1 hour later…
10:55 AM
If this really is a mystery or unknown to not only me then I can easily turn it into a question on site.i just don't want to come out as daft. Don't care what you heapsters think :)
 
11:18 AM
@MikaelEriksson Is PIVOT involved in that case?
 
@AndriyM No not PIVOT. But perhaps this is a plan that resembles a PIVOT plan. It might be.
I deliberately hid everything in the plan that points to a XML query just to not alienate some people from taking interest in the question.
 
In any event, I don't think the answer would be something obvious to most people.
Meaning there's little chance you'd come out as daft with that question, @Mikael :) IMHO.
 
@AndriyM Ok, time for a question.
 
11:59 AM
0
Q: Odd Stream Aggregate behaviour

Mikael ErikssonQuery: declare @X xml = ' <item ID = "0"/> <item ID = "1"/> <item/> <item/>'; select I.X.value('@ID', 'int') from @X.nodes('/item') as I(X); Result: ----------- 0 1 NULL NULL Execution plan: The top branch shreds the XML to four rows and the bottom branch fetches the value for the a...

 
12:10 PM
@MikaelEriksson A scalar aggregate always produces a single row, even if there is no input. e.g. scalar max of no rows is null; scalar count of no rows is zero. For a vector aggregate, group by (), the result is no row in both cases.
On phone.
 
@PaulWhite Ahhh, scalar aggregate. Thanks.
 
SELECT MAX(SV.number) FROM master.dbo.spt_values AS SV WHERE CONVERT(nvarchar(max), SV.high) = N'#';
Code demo on a phone, go me.
 
@PaulWhite I think I will self-answer that Q then but please feel free to add one of your own if think there is more to say.
Or I just accept your answer instead :)
 
12:28 PM
@MikaelEriksson Sorry I wandered off to the laptop instead of reading The Heap.
 
@PaulWhite Oh no, that is better. I saw your answer just as I started thinking about what to write.
 
It is more obvious in a regular query than an XML query that you are dealing with a scalar aggregate.
I mean, by looking at the query itself.
 
Not always; see the Connect item.
Oh by looking at the query text? Maybe.
Still not easy though. That Connect item came from a query Adam Machanic passed on to me. He didn't spot the scalar aggregate, and neither did I at first.
Perhaps we are amateurs :)
 
Yes I'm sure you are. Helped him with some XML this weekend. Not sure he got it :)
 
12:32 PM
No one understands XML.
Sorry, couldn't resist.
 
Haha, this question I had come as a result of trying to figure out why his XML query was so slow.
Funny thing is that the standard answer of not using the parent axis was wrong in this case. Using the parent axis was the thing to do only do it with a twist.
 
Everything depends, I guess.
If you can boil that down to a simple example, that might make a great self Q & A.
 
Ooo.
 
The workaround is in the comment. Use [1] even if it is redundant.
 
12:37 PM
@MikaelEriksson Connect item line breaks are still broken.
Since ../@OrderID and ../@OrderID[1] means the same thing... < is that strictly true?
 
@PaulWhite Yes, since you are not allowed to have multiple attributes with the same name in one element.
 
Ah true.
 
It is implemented at all since you can do @*[2]etc to get the second attribute.
Wild card followed by a predicate.
 
Yes I was just reading that.
What the smurf does @*[2] mean?
 
Second attribute
 
12:42 PM
The second attribute in document order?
 
Yes
or attribute order within the current element.
 
Add me to the list of people that had not seen that syntax before.
 
This is what made Adam's query fly.
with xmlnamespaces (default schemas.microsoft.com/sqlserver/2004/07/showplan …')
select C.X.value('../../@LogicalOp[1]', 'varchar(20)'),
       C.X.value('@Column', 'sysname')
from T
  cross apply T.X.nodes('//RelOp/OutputList/ColumnReference') as C(X);
Without the [1] it probably would never finish.
Doing double cross apply took about 10 minutes I believe.
 
Weird. I would like to see that explained on main. Seems like it might be a useful plan shredding thing to be aware of.
 
I will give it a thought.
 
12:45 PM
I'd definitely not think of trying the double parent thing.
Well probably definitely not.
And if I did, I'd miss the [1]
 
Double cross apply is slow because of relop within relop. Still trying to figure out what that plan really is up to.
 
I use XQuery so infrequently I find myself relearning the same things each time. Generally only add [1] when I get an error telling me it is needed :)
Probably close to never on an attribute.
XML plans would only be marginally harder to read if they were encrypted.
5
 
with xmlnamespaces (default 'http://schemas.microsoft.com/sqlserver/2004/07/showplan')
select R.X.value('@LogicalOp', 'varchar(20)'),
       C.X.value('@Column', 'sysname')
from T
  cross apply T.X.nodes('//RelOp') as R(X)
  cross apply R.X.nodes('OutputList/ColumnReference') as C(X);
^^^ That is what I would think is the fastest. But it was not. Far from it.
 
That's how I'd like to think I would write it too.
Was the slow plan slow due to a table spool?
 
I have 639 plans in T and it takes 700 ms for the first and 17 second for the second.
Nope, not spool.
For each RelOp it finds all child RelOps (deep) and uses a filter to check if the RelOp found is a parent to the input RelOp.
Does that make sense? I mean my explanation.
 
12:54 PM
Sense enough.
 
@MikaelEriksson Jumping in late here, can I help? : )
 
So some kind of quadratic performance thing with number items times depth.
 
Yep. I understand.
 
@wBob Hi, I got a good answer to my actual question. Please feel free to ponder the wonders of XML query plans above :).
 
Perf with xml plans can be a bit flaky.
I have a standard pattern I use when working with plans:
SELECT IDENTITY( INT, 1, 1 ) rowId, CAST( target_data AS XML ) AS target_data, GETDATE() dateAdded
INTO #tmp
FROM sys.dm_xe_session_targets st
	INNER JOIN sys.dm_xe_sessions s on s.address = st.event_session_address
WHERE s.name = 'stolen'

ALTER TABLE #tmp ADD PRIMARY KEY ( rowId );
CREATE PRIMARY XML INDEX _pxmlidx_tmp ON #tmp ( target_data );
That one's for Extended Events but you get the idea.
I have also found it's possible to get faster plans by messing with the weightings, don't have a repro to hand an don't encourage this behaviour out in the open : )
 
12:57 PM
Trying perf with above queries using XML index now.....
The first was the about the same 777 ms. the second dropped from 17 second to 4.
 
@MikaelEriksson You could experiment with secondary indexes and/or selective xml indexes...
@MikaelEriksson but you might be in to diminishing returns. What do you think?
 
@wBob Added all secondary path index. First is the same, second is 1.5 seconds.
 
@MikaelEriksson Interesting. Is there a repro? Might be worth trying the property and value secondaries, just for fun : )
0
Q: How to disable IO timeouts

boot4lifeOn my dev box I sometimes need to run very IO intensive queries such as index builds and CHECKDB. This can put so much load on the disk that it hardly can process anything else. This causes enormous lagging in other programs. For that reason I sometimes need to suspend sqlservr.exe using Process ...

On a separate note:
if I caught you suspending my sqlservr.exe processing using Process Explorer I would go absolutely mental.
 
Well all is fair on a personal dev box.
 
@wBob Just a table like this.
create table T(ID int identity primary key, X xml not null);
Filled with a bunch of plans from the cache.
 
1:12 PM
@PaulWhite Well we all do crazy things on our personal dev boxes : )
 
and these two queries.
with xmlnamespaces (default 'http://schemas.microsoft.com/sqlserver/2004/07/showplan')
select C.X.value('../../@LogicalOp[1]', 'varchar(20)'),
       C.X.value('@Column', 'sysname')
from T
  cross apply T.X.nodes('//RelOp/OutputList/ColumnReference') as C(X);


with xmlnamespaces (default 'http://schemas.microsoft.com/sqlserver/2004/07/showplan')
select R.X.value('@LogicalOp', 'varchar(20)'),
       C.X.value('@Column', 'sysname')
from T
  cross apply T.X.nodes('//RelOp') as R(X)
  cross apply R.X.nodes('OutputList/ColumnReference') as C(X);
 
Where's my "run this query turning on and off all trace flags" template?
 
Got to go for now. Will probably test with selective indexes later. for fun.
 
@wBob I suspend (well, freeze) threads all the time to catch SQL Server doing stuff. I accept dumps and other complaints from SQL Server as acceptable collateral damage.
 
@PaulWhite lol that's fair. With this person though, I'm just thinking why not schedule them for the nighttime / weekend? And "you're gonna need a bigger boat".
 
1:15 PM
@wBob Level complete. Next level: combinations of trace flags (some only work with others).
2
 
It is possible to disable stack dumps, I'm not gonna tell them how though.
 
@wBob Yes, that's one of the reasons I haven't answered.
 
@MikaelEriksson For your fun only, only for you.
 
And for anyone interested who might immediately add a 500 point bounty.
 
@PaulWhite I drafted a snarky comment along those lines, along with "invest in an NVMe SSD", but deleted it, in the interests of being less snarky these days,
 
1:16 PM
@wBob With a trace flag? Or system config?
@wBob "not constructive" :)
 
@PaulWhite Indeed.
 
I'm sure I've read the no stack dump thing somewhere before, but never used it, hence no memory of it.
 
@PaulWhite No, this is a tip from one of the Bob's, (Dorr or Ward) can't remember. You just >! rename stackdumper.exe.
sqldumper even
 
Ah.
No that doesn't seem familiar at all.
 
Not for open consumption I think.
 
1:19 PM
Probably not :) Oh...
Ha! I even commented on that.
 
@PaulWhite Ha! Knew I'd read it somewhere. Think it came up a year or two ago when someone was running out of diskspace due to excessive dumps.
@PaulWhite Small SQL world.
 
Not the first time, won't be the last.
 
I failed to use the spoiler syntax in chat there.
 
I wondered what that >! was about.
>! Doesn't work in chat
 
1:35 PM
Ah, fair nuff.
 
Not that it matters since it's all public anyway.
 
@PaulWhite Yes, good job people asking questions here don't know how to use google.
lol
 
snurk
 
@PaulWhite lol perhaps a bit harsh on my part, that one is tucked away.
 
 
1 hour later…
2:56 PM
Thanks for bumping the SSIS question @PaulWhite
 
3:42 PM
@PaulWhite could be a Postgres operator ;)
 
One of the simpler ones :)
 
4:07 PM
@MikaelEriksson I get best result with property index and ordinals, eg
;WITH XMLNAMESPACES (default 'http://schemas.microsoft.com/sqlserver/2004/07/showplan')
SELECT R.X.value('(@LogicalOp)[1]', 'varchar(20)') a,
       C.X.value('(@Column)[1]', 'sysname') b
FROM T
	CROSS APPLY T.X.nodes('//RelOp') as R(X)
	CROSS APPLY R.X.nodes('OutputList/ColumnReference') as C(X)
YMMV
I don't normally use ordinals with attributes, but there you go.
 
 
2 hours later…
5:49 PM
So our main national TV station is attempting a World Record Rickroll. They invited Rick Astley as the main guest
2
A couple 100K people being rickrolled at exactly the same time :)
They aren't doing it intentionally, the WR though
 

« first day (1973 days earlier)      last day (2900 days later) »