« first day (1520 days earlier)      last day (3646 days later) » 

03:37
@JamesLupolt The DISTINCT guarantees that joining to the second table will not result in repeated rows from the first table.
 
3 hours later…
06:57
@PaulWhite Yes, thanks. I get it now. It took a while, admittedly.
@JamesLupolt Good. Just out of interest, where did I put that code? It looks very familiar, but I can't remember where I might have posted it online.
@PaulWhite It's actually not online as far as I know. I was watching one of the SQL PASS 2012 videos: Query Optimizer Deep Dive
@JamesLupolt Ah! Yes I remember now. Thanks - that would have bugged me!
 
3 hours later…
09:48
@swasheck If session 2 has a sufficiently strong hook on the ##table it can survive session 1's disconnection:
session 1: create table ##
session 2: SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;
begin transaction;
select * from ##;

close session 1
session 2: select * from ##
- all OK
..and tempdb.sys.objects still shows the ## as existing.
 
1 hour later…
10:52
-9
Q: What select =* does?

Annem SrinivasI do know that select * from table gives all columns in the result. but what happens if we use select =* from table Could any one give detailed explanation for this.

Somedays I just don't understand the logic that goes through another person's brain...
11:09
@MarkSinkinson His other answers are equally awesome
 
2 hours later…
JNK
JNK
13:18
@ypercube I had to comment on one
Yeah. And it's not only that it's wrong.
he is basically combining 3 selects on that answer. For something that could be as simple as select top 1 .. order by
The other answer by Doc needs a slap, too:
0
A: How to get last record from the latest inserted record

DocSELECT * FROM tbl WHERE Col1 ='A' AND Col2='B' AND Mindate = MAX(Mindate)

13:55
This question (and accepted answer) hurt my eyes. I don't know where to start. stackoverflow.com/questions/8602395/…
@MichaelJSwart I suppose you are right. They confuse deadlocks with blocking
JNK
JNK
Q for the room - has anyone ever heard of using the size of a tlog relative to the data files as some sort of health metric?
i.e. "Make sure the tlog is < 3/4 the size of the mdf"
We can compare with Remus answer here, on a similar issue:
2
Q: Occasionally Getting SqlException: Timeout expired

user960567I have application running on my server. The problem with this application is that daily I am getting nearly 10-20, System.Data.SqlClient.SqlException Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding only one of my SP. Here is my SP,...

JNK
JNK
I'd like to meet that guy some day
This is not an answer. Please support why you "prefer" one over the other. — Kermit 8 secs ago
14:13
I don't tell you the details, but you are wrong in any case:
0
Q: How can I tell which process owns a particular connection?

d33tahI recently tried to call ALTER TABLE, which got blocked because one of the transactions holds a lock on the related table. With the help of #postgresql IRC channel, I managed to track down the problem to this particular process:d33tah 47329 0.9 0.0 275836 95384 ? Ss Mar03 23:59 po...

JNK
JNK
repeating this:
Q for the room - has anyone ever heard of using the size of a tlog relative to the data files as some sort of health metric?
i.e. "Make sure the tlog is < 3/4 the size of the mdf"
Not an admin but I listen them speak. Never heard that metric
@JNK Probably a lack of people around today with SQLBits on. Also not an admin and also never heard of that
Seems spurious though. What if I have very large bulk activities that cause my tlog to grow larger than my mdf
JNK
JNK
oh yeah I forgot about SQL Bits
@billinkc yeah my thought as well
also this is part of a WEEKLY check
so what the hell would it matter if it's like that monday morning
14:28
Does The DBA(tm) have any reasoning on why this makes sense?
Not to besmirch their good name, I'm sure someone else could have said it
JNK
JNK
it looks like it's some metric we got third hand from a rackspace person before I worked here
And it makes no sense whatsoever
@Kermit I want to downvote all answers ...
I have a magic rock that keeps tigers away. I could sell it to you. It also keeps tlogs in check
3
JNK
JNK
@billinkc This is more of a polar bear area now so I'll pass
it actually rained today and I was amazed
i had not seen liquid water outside in like 2 months
@JNK It's wonderful isnt it?
14:37
@JNK I've heard something along those lines....but from the same people that like to just go and truncate the log when it reaches some arbitrary size, so
JNK
JNK
@Lamak all our DBs have tlog backups every 15 mins anyways
so this is like not a big concern of mine
@JNK I meant that as in "I wouldn't believe anything those guys say about DBA things"
Is the only way to never query the table, by using a separate query or dynamic sql to create the query?
0
Q: How do I have SQL JOIN done depending on some condition?

sharptoothI have two tables: CREATE TABLE Users( UserId UNIQUEIDENTIFIER NOT NULL PRIMARY KEY, UserName NVARCHAR(200) NOT NULL, -- some other columns CurrentSubscriptionId UNIQUEIDENTIFIER NULL, ) CREATE TABLE Subscriptions( SubscriptionId UNIQUEIDENTIFIER NOT NULL PRIMARY KEY, Us...

@JNK Nope. I start with my t-logs ~1/3 the size of my data files then let them grow as the workload dictates. I will monitor them for growth, but not for size (to make sure they aren't growing out of control).
14:53
@bluefeet This looks like searching for an answer to a non-existent problem...
@MarkSinkinson I agree, but now I'm curious if there is a way to prevent it. My only thought would be dynamic sql
I was under the impression there are situations where SQL Server will simplify a query not look at certain underlying tables if they are not useful for the query. i.e. If I LEFT OUTER JOIN to a table but then don't include any columns in the results, or where clause, or any further joins, SQL Server can choose to exclude that table from the query.
However, if you've got CASE around each column, I'm guessing it's not able to simplify in this way.
I believe the term is 'Lazy Join'
http://stackoverflow.com/questions/20434556/does-sql-server-2012-lazy-join
Or 'carpet bomb join'
@MarkSinkinson I shall rename it "@billinkc's join"
15:17
I hope a volcano erupts on your head
@swasheck What's your opinion on removing duplicate statistics?
@billinkc you should've been honored
There's no honor when peasants sing your praise
I....have no comeback to that
billinkc scores again. (and I know, tornado on my head ...)
JNK
JNK
15:28
@MarkSinkinson It won't exclude that left joined table AFAIK because it can still affect the number of records returned even if you don't reference the table in the select or filters
@ypercube im not stopping you
JNK
JNK
@MikeFal thanks!
@Kermit No one can stop me with a tornado on my head ;)
@JamesLupolt Wat? How? Deliberate sabotage ?
@JNK It shouldn't if the database structure was correct though. You can only have one Current Subscription per user, meaning that the join to a Primary Key should return one row from the Subscriptions table for each record in the Users table.
15:38
Ypercubenado
You should get the same number of records with or without the JOIN
JNK
JNK
@MarkSinkinson Not sure the engine can know that
unless your fk is a pk in both tables
@JNK According to Mikael Eriksson it can stackoverflow.com/a/20502510/775200
@MarkSinkinson join simplification. Rob farley Blog post. It's that what you're thinking if?
JNK
JNK
@MarkSinkinson ah I was thinking parent left join child
if you child LJ parent then yes, the join is the PK in the parent so it can know there's no dupes
15:42
a wee bit broad
0
Q: The highest impact of operation on transaction log?

terrykonWhat operation: SELECT, INSERT, UPDATE or DELETE has the highest impact on transaction log?

@swasheck Ah, that's what I knew I'd looked at
@bluefeet That's like saying 'it's in that place i put that thing that time'
Mobile chat will be the dearth of this vein in my forehead
Death too
@swasheck DROP STATISTICS?
15:54
@JamesLupolt i'm still trying to figure out why you'd have dupes? one manual and one autocreated from an earlier time?
but i'm all for dropping dupes
as long as they're strict dupes (same sample rate, same exact column order, etc).
@swasheck Yes, say you've manually created multi-column stats. Or you created a nonclustered index, and stats were automatically created for the index. Now you might have some duplicate stats alongside the single-column stats that were auto-created on the base table.
i'd drop the auto-generated ones
personally
but i'd also seek permission to run this
(hold please)
well wait ... which version of sql server are you running?
@JamesLupolt ... is this 2008r2 or is it 2012 <=
16:22
@swasheck I'm working on a way to detect duplicate stats (and figure out which to remove) on 2008, 2008 R2, 2012, 2014
ok
well i'd get the list of candidates
I think the whole table (clustered index or heap) has to be rebuild. With 90M rows, that takes some time. — ypercube 1 min ago
Out of my own curiosity, what's the gain for removing duplicate stats?
is this correct?
and then use TF 9204 + XE (trace_print) event
for < 2014 CE
16:23
@KrisGruttemeyer I'm not convinced there's a huge gain. You'd get a smaller set of statistics objects to update.
and TF 2363 + XE (trace_print) event for 2014
@KrisGruttemeyer @JamesLupolt not much ... fewer statistics to update at update time ... fewer stats to consider during planning ... fewer _WA_123809_WTF objects to decipher
i just like having that cleanness
@JamesLupolt Makes sense, i assume it just depends on how many 'true' duplicates there are?
@swasheck I can appreciate that, for sure.
@KrisGruttemeyer Yeah, the 'true' duplicates part is something I'm not sure about yet. I need to read more about how multi-column stats are structured
@KrisGruttemeyer if you want to see some good impact ... clear the proc cache and compile a query with option (querytraceon 9224, querytraceon 3604) all of the stats considered interesting are loaded.
> However, small inefficiencies can add up quickly when your tables get large, so I recommend that you delete unnecessary auto-created statistics when you create a real index on a column. SQL Server won't do it for you.
9224? I assume ondoc/unsupported?
16:29
@KrisGruttemeyer natch
> Hi Marios-

There *could* be a situation where the duplicate single-column statistics is chosen instead of the index statistic for a query plan, or vice versa…and the concern is if one is out of date (and therefore not representative of the data in the column) and therefore it generates a less-than-optimal query plan.

To calculate the size footprint of duplicate stats you’d need to dig into some of the internal tables. I haven’t done that, might be worth investigating!

Erin
Makes sense, could be interesting information to pull out.
@swasheck Where did you find that quote from Erin?
I know she wrote something about this topic, but I can't find it in Google
@JamesLupolt comment thread from here: sqlskills.com/blogs/erin/…
Ah yes
"I recently attended a webcast by you on the topic of identifying duplicate statistics"
That webcast seems to have disappeared
@JamesLupolt i'd surmise that's an interesting edge case, but @PaulWhite can really speak to that more than i
16:34
i'll bbl
thanks for help
send me your email address i will send you pictures of my table in which i enter my data — qismatullah 14 secs ago
Yeah, right.
Please send photos.
POIDH
Vote to close please
I get the impression he'll take screenshots of his computer with his phone and then email them to you...
@MarkSinkinson We had at least one of those in a past question!
(bu tI think it was form a very old OS, probably without print screen option)
I imagine the OP as a she
17:00
Comment I just found.
-- First 5 CTEs use this data set
[Seriously considering using this on the developers: sqlstudies.com/2015/02/16/…
Wanna put NOLOCK on everything? You shall not pass....
unnesting 15 CTE's is no fun.
@Zane Ew, just ew
Like trying to find a needle in a stack of needles
Yeah this guy can't figure out why his query is running slow...
He has enlisted my assistance.
Certainly the 15 CTEs have nothing to do with it.
17:17
He doesn't seem to be utilizing the value of a CTE in the first place.
recruiter email ...
> Any Tips?
@Zane which is ... ???
cte1 is doing select blah from table1 join on table 2 where date between example1 and example2 and thing =1
then CTE is doing select blah from table1 join on table 2 where date between example1 and example2 and thing =2
i'm just asking what the value of a CTE is
Why the eff would you do that?
@swasheck I like them, I find them easier to read
17:21
oh i didnt say i didnt like them --- just wondering what the perceived benefit was to @Zane
legibility and recursion are the only two i can think of off te top of my head
I personally do not like writing them.
@swasheck that's about it for me too
anyone care to guess?
0
Q: SQL Server- Long Running simple query

Doc Holidayselect * from [table_name]. This table has about 500,000 rows and took nearly 16 mins to bring back 500 rows. What would cause this?

from an admin perspective i hate them because every dev here believes them to be some sort of pre-materialization feature
I find them to look confusing to beginners which is something I am doing more often.
I wish I could show you guys this GD thing.
17:25
y'all so helpful
slow storage? wide data? slow network between client and server? subtle variations in the gravitational constant as highlighted by the pioneer probes? — swasheck 43 secs ago
I like my comment better
@DocHoliday Get a dartboard, place all possible reasons, throw dart. At this point, we'd basically be doing that - we'd be guessing. — bluefeet ♦ 24 secs ago
@bluefeet flagged as not educational
Classic:
yes C and E has more than one row on a_id what i should do please write me query — qismatullah 19 mins ago
Where's a mod
That question is offensive and shouldn't be on dba.SE
@JNK WHERE THE FUNK ARE YOU???!!!!!!
17:28
It's closed now
help me @JNK - Wan, you're our only hope
@Zane We are so inadequate. In SO, they would have simply advised her to use distinct. Problem solved.
lol
@swasheck you do realize that's not a valid reason for a moderator to be flagged
JNK
JNK
17:30
@swasheck was on a 90 minute conf. call with customers
I have to lead this thing once a week
Feb 27 at 16:39, by Paul White
You're mistaking me for someone who cares enough.
@JNK whatever
;)
@bluefeet I don't think he's flagging a moderator ;)
i rarely flag things.
@AndriyM you never know with @swasheck
but when i do, i tend to do it because something is so offensively bad or just generally offensive
@bluefeet WHY SO SERIOUS?
17:32
he's a rebel
The amount of CTE's that pull from this CTE is ridiculous.
@swasheck serious SO mod over here
wanna hear the story about how i got this scar?
@swasheck Not really
17:33
@Zane How many times is the CTE re-used in the query?
@ypercube @Zane i'm thinking about the number of times the cte is evaluated over and over and over and over ... the optimizer loves that
@MikeFal okfine
@ypercube 6
@Zane It's good then.
If the performance is horrible due to the re-evaluation, make it a temp table ;)
I was trying to get this query to no longer use any CTE's
@swasheck Is it a good story? Like you got headbutted by Andre The Giant?
17:35
@ypercube what do you mean that it's good
@JamesLupolt did you just call me a butthead?
@swasheck It's good for Zane because converting a cte to a temp table is easy. Imagine if it was duplicated (6 times) in a huge query.
ok. i see now
18:01
@Zane i just got one with 13
@swasheck guh.
with a as (select * from a),
b as (select * from b),
c as (select * from c).
....
@ypercube I gave up on this effing thing and just told the dev to do the quick fix of the #table.
lol He sent it back and it's called #CTE
Patching is so boring
/IAcceptSQLServerLicenseTerms
JNK
JNK
18:39
@bluefeet you get any further with TSQLT unit tests?
I'm working on some new ones now and it made me think of you asking about it
@JNK sort of. It looks like we will be using the DB projects (SSDT tools) inside Visual Studio. The main issue with the tsqlt is our environments are basically "reimaged" from production periodically, so installing code inside our DBs doesn't really work very well.
@Zane Nice.
WITH temp AS
( SELECT *
  FROM #cte
) ...
JNK
JNK
@bluefeet ah ok makes sense
you do need the CLR assembly
It was going to be too much maintenance to use tsqlt for us
18:56
@JNK, another option with your design:
SELECT COUNT(*)
FROM dbo.Lines
WHERE BallVal IN (@ball1, @ball2, @ball3, @ball4, @ball5, @ball6)
GROUP BY LineID
HAVING COUNT(*) >= @matchCount ;
No idea what which index would be good for this.
 
1 hour later…
19:57
Ha, nice. I love Canadians!
20:38
I think @Zane will like this: youtube.com/watch?v=UE8VpRie1Ik
20:55
The whip sound effect was amazing.
 
2 hours later…
22:42
i'm actually coming up against a situation where the plan for a query with a bunch of CTEs is different and the query execution time is consistently faster over against the query without CTEs
23:06
i wish i wasnt so bad at this

« first day (1520 days earlier)      last day (3646 days later) »