Kids, get off my lawn!

Change can be hard. But sometimes it’s necessary. And a lot has happened this week.  First, I want to congratulate my fellow #SQLFamily member Cathrine Wihlemsen on one more orbit of the Sun. Apparently, in her honor Microsoft decided to release SQL Server 2019 on her birthday! I’ve been using SQL Server since the 4.21a days. Every version has had new features and required learning something new. As I said recently, it’s easy to fall into the trap of being an old dog and not learning new tricks. This is something we have to avoid. Being trapped in the past can be limiting.

Besides SQL Server 2019 dropping this week, I recently upgraded my phone. I had been using a Windows Phone for about 5 years now. I loved it. Especially when it first came out, it was top of the line and had a bright future. I eagerly downloaded apps and it became part of my life. But alas, we know how well Microsoft did in the Windows Phone market. But I doggedly held on, even as features were deprecated. I couldn’t use the Weather App. The Amtrak App went away. Eventually several features of Cortana stopped work as Microsoft stopped supporting them. Slowly my phone was becoming a brick. I kept debating do I upgrade to one more Windows Phone knowing it’s the end of the line, or what? I kept putting off the decision. After the mapping function failed me on my recent trip to the Hampton Roads User Group Meeting I decided it was time to finally time to replace it with an Android phone. Choosing from the plethora out there was not fun. It was very tempting to go with one of the top of the line models, but spending $1000 or so wasn’t really a fun idea.  I eventually ended up choosing a Samsung A50.

I’m mostly happy with it. Right now I’m struggling with what parts of it are “get off my lawn” because I don’t like change, and what parts are “what the hell is the UI doing now?”  Fortunately, my son has mentioned some of his dislike of certain UI functionalities, so I think not all of it is me simply being an old curmudgeon (are there young ones?) I will say what I’m most happy with is that Microsoft has a number of tools including the Windows Launcher and the Phone Companion, as well as the obvious apps like Outlook and other parts office.

A word about the Phone Companion. This alone has made the upgrade a win. One of the features is that when I’m working at home (I have not yet enabled it on my Surface Pro) is that things like text messages pop-up on my desktop screen. This actually makes life a LOT easier, since I can simply type a reply from a full-size keyboard or copy the numerous soft-tokens I get to log into various client sites without having to pick up my phone. It’s a small detail, but a wonderful one!

The Launcher helps me retain some of the features that I liked about my Windows Phone. Overall, it’s a win.

But the changes in my life aren’t complete. As I mentioned last week I’m at PASS Summit again this week in Seattle. But alas, this is the last year that PASS Summit will be in Seattle. Next year it will be held in Houston. Just as I’ve figured out where the cheapest and most convenient parking for me is, where some decent food places are, and I’m feeling, if not at home in Seattle, at least comfortable, next year is a big change. I won’t be able to stay with my college friends or do our annual Thai pot luck with a bunch of ROC Alumns.

But, I’ll get to explore another city. I’ve been to Houston only once, literally decades ago, to do SQL Server install at Exxon. The server was literally the only Intel computer in a room full of mainframe equipment. I suspect that has changed since then.  That was one of my early experiences installing SQL Server (4.21a for the record).

So, this old dog is still learning and looking forward to new experiences: plus ça change, plus c’est la même chose.

 

Small Victories

Ask most DBAs and they’ll probably tell you they’re not a huge fan of triggers.  They can be useful, but hard to debug.  Events last week reminded me of that. Fortunately a little debugging made a huge difference.

Let me set the scene, but unfortunately since this was work for a client, I can’t really use many screenshots. (or rather to do so would take far too long to sanitize them in the time I allocate to write my weekly blog posts.)

The gist is, my client is working on a process to take data from one system and insert it into their Salesforce system.  To do so, we’re using a 3rd party tool called Pentaho. It’s similar to SSIS in some ways, but based on Java.

Anyway, the process I was debugging was fairly simple. Take account information from the source and upsert it into Salesforce. If the account already existed in Salesforce, great, simply perform an update. If it’s new data, perform an insert.  At the end of the process Pentaho returns a record that contains the original account information and the Salesforce ID.

So far so good. Now, the original author of the system had setup a trigger so when these records are returned it can update the original source account record with the Salesforce ID if it didn’t exist previously. I should note that updating the accounts is just one of many possible transformations the entire process runs.

After working on the Pentaho ETL (extract, transform, load) for a bit and getting it stable, I decided to focus on performance. There appeared to be two main areas of slowness, the upsert to Salesforce and the handling of the returned records. Now, I had no insight into the Salesforce side of things, so I decided to focus on handling the returned records.

The problem of course was that Pentaho was sort of hiding what it was doing. I had to get some insight there. I knew it was doing an Insert into a master table of successful records and then a trigger to update the original account.

Now,  being a 21st Century DBA and taking into account Grant Fritchey’s blog post on Extended Events I had previously setup a Extended Events Session on this database. I had to tweak it a bit, but I got what I wanted in short order.

CREATE EVENT SESSION [Pentaho Trace SalesForceData] ON SERVER
ADD EVENT sqlserver.existing_connection(
    ACTION(sqlserver.session_id)
    WHERE ([sqlserver].[username]=N'TempPentaho')),
ADD EVENT sqlserver.login(SET collect_options_text=(1)
    ACTION(sqlserver.session_id)
    WHERE ([sqlserver].[username]=N'TempPentaho')),
ADD EVENT sqlserver.logout(
    ACTION(sqlserver.session_id)
    WHERE ([sqlserver].[username]=N'TempPentaho')),
ADD EVENT sqlserver.rpc_starting(
    ACTION(sqlserver.session_id)
    WHERE ([package0].[greater_than_uint64]([sqlserver].[database_id],(4)) AND [package0].[equal_boolean]([sqlserver].[is_system],(0)) AND [sqlserver].[username]=N'TempPentaho')),
ADD EVENT sqlserver.sql_batch_completed(
    ACTION(sqlserver.session_id)
    WHERE ([package0].[greater_than_uint64]([sqlserver].[database_id],(4)) AND [package0].[equal_boolean]([sqlserver].[is_system],(0)) AND [sqlserver].[username]=N'TempPentaho')),
ADD EVENT sqlserver.sql_batch_starting(
    ACTION(sqlserver.session_id)
    WHERE ([package0].[greater_than_uint64]([sqlserver].[database_id],(4)) AND [package0].[equal_boolean]([sqlserver].[is_system],(0)) AND [sqlserver].[username]=N'TempPentaho'))
ADD TARGET package0.ring_buffer(SET max_memory=(1024000))
WITH (MAX_MEMORY=4096 KB,EVENT_RETENTION_MODE=ALLOW_SINGLE_EVENT_LOSS,MAX_DISPATCH_LATENCY=30 SECONDS,MAX_EVENT_SIZE=0 KB,MEMORY_PARTITION_MODE=NONE,TRACK_CAUSALITY=ON,STARTUP_STATE=OFF)
GO

It’s not much, but it lets me watch incoming transactions.

I could then fire off the ETL in question and capture some live data. A typical returned result looked like

exec sp_execute 1,N'SourceData',N'GQF',N'Account',N'1962062',N'a6W4O00000064zbUAA','2019-10-11 13:07:22.8270000',N'neALaRggAlD/Y/T4ign0vOA==L',N'Upsert Success'

Now that’s not much, but I knew what the Insert statement looked like so I could build an insert statement wrapped with a begin tran/rollback around it so I could test the insert without actually changing my data.  I then tossed in some set statistics IO ON and enabled Include Actual Execution Plan so I could see what was happening.

“Wait, what’s this? What’s this 300K rows read? And why is it doing a clustered index scan on this table?”  This was a disconcerting. The field I was comparing was the clustered index, it should be a seek!

So I looked more closely at the trigger. There were two changes I ended up making.

       -- Link Accounts
       --MERGE INTO GQF_AccountMaster T
       --USING Inserted S
       --ON (CAST(T.ClientId AS VARCHAR(255)) = S.External_Id__c
       --AND S.Transformation in ('Account'))
       --WHEN MATCHED THEN UPDATE
       --SET T.SFID = S.Id
       --;
       
       if (select transformation from Inserted) ='Account'
       begin
              MERGE INTO GQF_AccountMaster T
              USING Inserted S
              ON T.ClientId  = S.External_Id__c
              WHEN MATCHED THEN UPDATE
              SET T.SFID = S.Id
       end

An astute DBA will notice that CAST in there.  Given the design, the Inserted table field External_Id__C is sort of a catch all for all sorts of various types of IDs and some in fact could be up to 255 characters. However, in the case of an Account it’s a varchar(10).

The original developer probably put the CAST in there since they didn’t want to blow up the Merge statement if it compared a transformation other than an Account. (From what I can tell, T-SQL does not guarantee short-circuit evaluation, if I’m wrong, please let me know and point me to definitive documentation.) However, the minute you cast that, you lose the ability to seek using the index, you have to use a scan.

So I rewrote the commented section into an IF to guarantee we were only dealing with Account transformations and then I stripped out the cast.

Then I reran and watched. My index scan of 300K rows was down to a seek of 3 rows. The trigger now performed in subsecond time. Not bad for an hour or so of work. That and some other improvements meant that now we could handle a few 1000 inserts and updates in the time it was previously taking to do 10 or so.  It’s one of those days where I like to think my client got their money’s worth out of me.

Slight note: Next week I will be at PASS Summit so not sure if/when I’ll be blogging. But follow me on Twitter @stridergdm.

NY ComicCon

Last week I talked about Kids These Days. This past weekend I went with my daughter to NY ComicCon. It was a late 8th grade graduation present she had requested. Due to me messing things up last year, we missed our chance to go, so I made up for it this year. And it was well worth it, for a couple of reasons. I want to focus on two, one topical and one personal. The topical first.

The topic is in the above photograph.  I apologize for it being blurry, “I’m a DBA Jim, not a photographer.”  But I took it for a reason. This was the panel for a talk titled: Join the Resistance! (Journey to Star Wars: The Rise of Skywalker). It was an interesting panel that talked about the books they wrote that cover the time between The Last Jedi to this December’s The Rise of Skywalker. But partway through listening, something dawned on me about the panel.  Can you figure out what I realized?

It’s there in the picture, but if not, let me list the panelists: authors Rebecca Roanhorse, Justina Ireland, Kevin Shinick, Ethan Sacks, Delilah S. Dawson, audiobook narrator Marc Thompson and moderator Ashley Eckstein.

What strikes you about that list of names? Now compare that to the panels you see at a number of tech events such as various SQL events. Note what it’s not. This is NOT a MANEL!

Science Fiction has for far too long been treated as the domain of boys and then later men. Marketing for decades often focused on boys. It was assumed that every boy wanted to be Han Solo or Luke Skywalker or Captain Kirk.  Women in shows and books were often only there as props for the male characters to react to. Granted, this statement isn’t 100% true, even Princess Leia had some meat to her character in the original Star Wars (back before it was episode IV or A New Hope.) Even then though, she served the role set out in much of mythology as the princess in distress to be rescued. Fortunately her role and the role of women in Star Wars was greatly expanded over the series, to the point now where Rey is our hero.

Ahsoka Tano in triplicate!

Ahsoka Tano in triplicate!

And this panel shows exactly how equitable the Star Wars universe has become. The moderator was Ahsley Eckstein, who voices the character Ahsoka Tano in various animated Star Wars series. Three of the authors on the panel were women. In other words, women were well represented.

Think about this when planning your tech event such as SQL Saturday. Do you have equal representation? “But wait Greg, there’s just not that women doing SQL! I only had 3 women apply to talk and 30 men!” I’m going to give you some advice. Ask for more women. Talk to those three, see if they know anyone who might want to speak, but was too nervous to put in a submission. Talk to Kathi Kellenberger and Rie Irish of the PASS Virtual Group Women in Technology.  Yes, there may not be as many women in tech as men, but I can guarantee that there’s more than you think and that it won’t change without encouragement and representation. If you as a guy get invited to speak on a panel, make sure there’s diversity. Turn down opportunities if it looks like it’s going to be a manel. Call out your fellow community members if they’re engaging in sexist behavior. It’s not always comfortable,especially if it’s a friend or a co-worker, but it needs to be done. Do your part.

If ComicCon can have an equitable panel in regards to Star Wars, you can do the same in regards to SQL or other tech panels.

Now for the personal:

Live Long and Prospoer

Autograph and picture with two amazing women, Nichelle Nichols and my daughter Rebecca.

Two amazing women: Nichelle Nichols is an amazing woman and helped represent African Americans on television in the 1960s and helped inspire people like Whoopi Goldberg and Mae Jemison. And as for my daughter, her future and journey is in front of her.  I will admit to basically being speechless in front of such an icon and here I am, still three days later grinning ear to ear thinking “I was in the presence of Uhura!”

(BTW, for those who recognize it, that’s a 1st edition Star Fleet Technical Manual with her signature. It also contains the signature of George Takei and James Doohan.)

 

Old Dogs and New Tricks

One problem with writing a weekly blog is sometimes you get the same idea in your head and realize you’re about to repeat yourself. I want to write about learning new stuff and started to repeat stuff I said here. I suppose I could just put a pointer to that and be done but… nah.

Several ideas prompted this week’s theme for this blog, the most recent being Grant Fritchey’s blog on using Extended Events. He makes some good points and I want to add my own thoughts.

I’ll start by admitting I still often use Profiler. I know it. It’s “easy”.  Well, no, not really. A better description would be “It’s familiar”. Truth is, I’ve often found the interface a bit clunky and I have to do more steps than I want to narrow down to trace exactly what I want.

But, about two weeks ago, one of my clients had an issue with a run-away query that expanded their tempdb to about 400GB before it rolled back. We wrote it off as a fluke; until it happened again the next day.  Now we had a pattern. I decided that we needed to monitor the server about the same time the next day to see if it would occur again. Now, of course one can sit there and run queries like sp_whoisactive, but I wanted more.  Profiler might work, but I figured it was time for this old dog to learn, or at least practice new tricks. I’ll admit, I basically googled for what I wanted, but I quickly found a trace I could modify and run for my needs.  30 minutes later and I had a nice extended event setup and monitoring the tempdb.

Now, as fate would have it, that run-away query hasn’t shown up since then, so in a sense the trace hasn’t fulfilled it’s goal. But, it’s lightweight enough that I’ve decided to leave it. And, the results are easily accessible to others if I’m out of town.

In the past year or so, it’s really hit me how much my role as a DBA or IT professional has really changed from two or more decades ago. There’s stuff that I do now that wasn’t possible then and there’s stuff then that I would do that I don’t worry about now or can’t even do (who out there recalls the ability to setup SQL Server database “files” on raw partitions for the speed boost?)

Over two decades ago I wrote a fairly impressive batch file that could install a client’s application on the proper drive. It used a lot of commands most people weren’t even aware of in the batch language (this was DOS, so not even as good as what CMD in Windows NT and above gives us).  Nowadays, I’d use PowerShell.

My original programming was in Fortran. Nowadays, I tend to sling code in VB.Net or C#.

It’s ok at times to fall back on what’s familiar. Often it can be faster and easier for a single project. But in the long-term, one really needs to learn what’s new and apply what one can.

My advice, pick a new technology or skill, and use it, even if for one project.  I’m not going to be an expert in Extended Events anytime soon, but now at least I can say, I’ve used it.  I’m far from an expert in PowerShell, but I’ve now been paid for 3 (and soon 4) articles on using it.

If this old dog can learn a new trick so can you.

And, listen to music you didn’t grow up on. As much as I love to listen to the music I’m familiar with while working, I often branch out. Yes, I’ve been known to listen to some Taylor Swift and Charlie XCX. And yesterday was a bit of Imagine Dragons and Meute. Two very different styles of music, but still a good listen.

What new trick will you learn this month?

Challenge Accepted!

Monica Rathbun in a recent blog post commented on how hard it is to write a blog post in under 5 minutes and challenged her readers to try to do it.

The only thing I can say is… challenge accepted.

But what to write about?

How about how I write, or rather how an idea gets into a blog post.

I have to admit, some Tuesdays my mind is blank. I sit at the screen, sometimes for 5 minutes or longer and my mind draws a blank. That’s rare. Fortunately, I often, sometime in the previous 6 days or so get an idea in my head and start to think about what I should write on it. It might have been a particular issue at work I had to solve, so I might be focusing on a more technical SQL or PowerShell focused blog.  Or it might be something I’ve seen that amused me.  This means I mull the thoughts over in my head and often have a basic outline before I put fingers to keyboard. The can help me cut down on the time I spent blogging.

I’ve also got about a dozen drafts saved in WordPress where I simply write a few lines of an idea for future posts. These are my saving graces. When I really can’t think of an idea I’ll go back and pull one of those up and finish them, such as this one which lay in draft status for months.

So, looking I think I failed. I think this one took just over 5 minutes. And to save time, I’m ignoring adding a picture, so you get the default. For now.

 

Busy Weekend Volunteering

As I mentioned previously, I was on vacation for about 10 days and got back to Albany very early Wednesday morning (or late Tuesday night depending on how one looks at it.) And once back from vacation I had to jump right back into two other events I had previously put on my schedule. This meant I didn’t have much time to catch up on work or sleep. But it was worth it.

A confluence of events meant that I ended up being double booked this past weekend. The first event was some special cave rescue training called a Small Party Assisted Rescue (SPAR) class. This was a 3 day class, Friday through Sunday. However, in addition, students had the chance to show up Thursday night in order to test on their skills before participating.  I was both an instructor for this class as well as the site and course organizer. My second event was SQL Saturday Albany, which I had been selected to speak at. I’m also the User Group coordinator that sponsors this event. This double booking meant that I couldn’t instruct at the SPAR on Saturday. I do want to note that at both events there were a number of other volunteers, and some were doing even more work than I was.

Between these two events, it meant I was getting about 6 hours of sleep a night plus putting in a lot of driving. It was a long, tiring, essentially 3.5 day weekend starting on Thursday. Additionally the jet-lag made it seem even longer.

Why do I mention all this? Because, both events are very important to me and cover two large areas of my life. I’ve previously written about some of my SQL Saturday experiences and SQL Pass experiences.  This is part of my professional life. I feel very strongly about volunteering and speaking at these SQL events. I enjoy running our local Capital Area SQL Server User Group (CASSUG) for the same reason. I’m a better DBA because of the shared experiences of my fellow speakers. I’ve written about this previously here and elsewhere in this blog. I hope I’ve helped others.

WP_20190720_002

Deborah Melkin discusses normalized vs. star schemas.

On the other side, as my slide deck often points out, I’m a caver. More critically I’m the Northeastern Regional Coordinator for the National Cave Rescue Commission. I’ve had the privilege of teaching 100s of people how to perform cave rescue, been a media resource during the 2018 Thai rescue, and have spoken and written on the subject. I am by no means an expert, I’m always learning, as are all my fellow instructors. But, we all are not only willing, but want to spend the time and money and effort to teach others. We are passionate about it.  I don’t mean this lightly. For this particular SPAR, while about 1/2 the instructors lived within 2 hours of the event and it was an easy drive, the rest either drove 5-8 hours, or spent all day flying on standby to get here or to get home. None were reimbursed for any of their expenses and in fact had to pay for linens if they wanted them.  They also had to take 2 days or more days off of work to come to New York.

Next summer, I will be the course coordinator for our 2020 National Weeklong here in New York State. This will bring close to 100 people to New York for a week of 14 hour days of teaching and learning cave rescue techniques. Fortunately, I will have a LOT of help organizing this event. But again, all the instructors and staff are volunteers who will travel at their own expense to be here and help teach.

So I spent my weekend volunteering, because I’m passionate about it. How was your weekend?

 

Marshmallows

Though I attended RPI, which is generally considered an engineering school, my degree is a BS in Computer Science. I say that because I consider myself more of a scientist than an engineer at times. And honestly, we all start out as scientists, but many of us lose that along the way.

Anyone who has had a small child has observed a scientist in action. No, they’re not in a lab full of test tubes and beakers and flasks giving off noxious smells. But they are in the biggest lab there is, the world. They also don’t necessarily realize it. Nor do parents. But every time they drop a Cheerio, they’re testing gravity.  Fortunately (or unfortunately depending on your point of view) so far every time they’ve managed to prove that gravity works. This is the most obvious example, but when you stop to think about it, much of the first few years of life is all about experimenting. Most of the time it goes well, but sometimes, as a burnt hand will attest, the experiment has a less than ideal outcome.

And it’s the fear of burned hands that leads to parents to utter that common  refrain, “Don’t touch that!” or the variation “Don’t do that!”.  Soon, over time, our experimentation starts to get reined in until we do very little of it. This can be inhibiting.

Years ago I used to teach an “Introduction to Windows” adult education class. It was I believe a 6 week class and I taught several over the course of a couple of years. It didn’t take me long to realize the biggest constraint on the students ability to succeed in the class was that they had internalized “Don’t do that, you might break something.” Once I realized that, half my teaching pedagogy simply became, “Touch that, you won’t break it, and if you do, it’s not a big deal, and if it is, we’ll fix it anyway.” Seriously, more than anything else, I had to encourage most of my students to experiment with the computer.

More recently I realized I had stopped doing as many experiments in my life as I should be doing. About 1.5 weeks ago I attended a Wilderness Medicine Conference a friend of mine had told me about. At the end of the very wet, cold, rainy day, a bunch of us went outside and tried to start a fire. Starting a fire, let alone in such conditions was something most of the students had never done. I had, but not in years. With some effort, and experimentation, including using the outside box of a single serving size package of Fruit Loops, we finally managed to get the fire going.

But this got me thinking. When I go hiking, I carry a tiny ziplock back in my jacket with some firestarting materials. They’re there in case of an emergency. But, the thing is, I had never actually tried them and realized if I didn’t know how well they worked in practice, I couldn’t rely on them in emergency. So, I went outside, and started a fire. And I learned that yes, my materials ARE adequate, but the dryer lint needed to be pulled apart more than I realized. I tried again later in the week, and added the use of a toilet paper roll to form sort of a chimney so the starting fire would draft better. This, and the better pulling of the lint worked even better and a single match was sufficient this time.  This gave me more confidence that in an emergency, in less than ideal conditions I could get an actual fire going.

But, I wasn’t done! Our microwave broke this weekend. But, before I wrote it off, I wanted to make sure it wasn’t a fluke or something else. So, in this case I decided to get a bag of marshmallows and lay them out inside the microwave to see if I was getting ANY energy out of the magnatron. Turns out, nope, nada, nothing. So, today or tomorrow I will be buying a new microwave. But, it was a fun, and later tasty experiment.

Without delving deep into the scientific method here, I’ll say at a simple level, science is about having a hypothesis and testing it. The testing it is important.

To bring this back to SQL. First, you have a hypothesis that your backups will work. Have you tested that hypothesis? If not, do so immediately. Even if they do, you might learn something now that will be important when you have to do it for real. Perhaps you learn the volume your backups are on only has write access. Or perhaps you learn you need to retrieve your encryption keys and the person who controls access to them is on vacation. Or perhaps your RPO is 4 hours and the restore takes 6 hours.  So, experiment.

query plan

Capture of a random query plan

Recently for one client I’ve spent some time experimenting with various changes to help improve the performance of some queries. Not everything I tried worked, but some things did. So, again experiment.

I’m curious what recent experiments you may have done, SQL or otherwise. What were their outcomes?