Saturday, March 19, 2011

SQLRally

Well, I have my flight booked and registered as a speaker. Looking over the speaker provided schedule, there are many sessions to choose from in the Business Intelligence track. My first goal is to get as much SSIS and Data Mart design training as I can over the 2 days of sessions.

I still have not decided about what Pre-Conference session I want to attend. Grant Fritchey’s Query Tuning is number one on the list, but learning BI from the Pragmatic Motley Crew would probably benefit my career as a better choice. Then, there is Kevin Kline teaching Personal Development. Since I will be attending regular BI sessions, I am leaning towards Kevin Kline’s PD, with Grant a close second (you can never get too much performance tuning advice).

sqlrally_banner

This past week at work, I was tasked with adding columns to a Fact table that a consultant started to work on before the end of the contract with their company. I noticed performance problems with the additions to the Inserts and Updates. After investigating, I found out using NOT Null and Default on the Alter Table Add column was best since some of the existing rows were not going to have values. The ETL had to be changed for Daily and Monthly updates.

The Monthly Updates were taking between 4 and 8 hours. After digging a little more, the Monthly Updates where not updating just the current period, but all data. By Adding a WHERE CURRENT_PERIOD = ‘Y"’, the processed reduced to 10 minutes.

Also, a fact table had 6 Non-clustered indexes, no primary key and no clustered index. This is taking a little more work because of the structure of the fact table, but an additional clustered index after removing all non-clustered. Then, adding Non-cluster indexes back after updating their structure to exclude the new non-clustered columns were appropriate, help take the 9-10 hour process down to 3 hours 10 minutes. Also, a big thanks to the Network/Infrastructure group that has enabled us to have a dev/test/prod environment that are almost all equal. That is a blessing not many shop s have.

Unbelievable!!! Whenever I am able to work on something like this, I have a tendency to try and tune more and more and more… never finishing. But it also reinforces all the training and real world experience in action and validate I am on the right track.

There is so much to learn in the Database world, but stopping and concentrating on a few items to become an expert gets harder and harder.

God Bless,

Thomas

Thursday, February 17, 2011

Got an Issue, get a Tissue…

I heard a preacher say this in a sermon, and thought about ‘issues’ on our servers. Rather than just complain about developers, I decided to tackling the queries my self. So, here is a list of the ones I dealt with in the past month or 2. please enjoy.

CXPACKET is not the problem 

I found a query in our month end process that had a lot of CXPACKETS. This was discovered through Ignite8 from Confio. This tool brings to the top of the heap, the most costly queries based on waits. I can also just look at a day, like end of moth, or even a database among other slice and dice capabilities.

image

I took the query and placed it in SSMS, and did a Display Estimated Query Plan and got an index suggestion that would improve performance 99%. It was the Sub-Query columns, PatNo + LocationCode with Include Column ClaimDate. The new index took about 15 minutes to create on a 48 million row table, but the Cost went from 3300+ to <5. WOW!!! From a 3-4 hour data retrieval to ~1 hour and no more parallelism.

image

Thanks again Confio!!!

 

Bad SQL

Over the last 6 months in the BI group, I have discovered some SQL that turned bad after more and more rows accumulate in the tables that are queried. The problem with the query is that the function has to be performed on ever row.

Taking these trims out, which were not needed because it was populating a staging table, then comparing to the Fact table, reduced the TempDB usage tremendously. If you look at the SET STATISTICS IO ON values below, you can see the before and after effects.

WHERE LTrim(TRim(column) = LTrim(RTrim(column)

WORKTABLE used

Table 'Worktable'. Scan count 1929907, logical reads 33462081, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.

Table 'Worktable'. Scan count 0, logical reads 0, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.

Table 'AUDIT_STAGING'. Scan count 10, logical reads 193381, physical reads 161, read-ahead reads 26709, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.

Table 'AUDIT'. Scan count 6, logical reads 85351, physical reads 20, read-ahead reads 82695, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.

WHERE column = column

Removed RTrim(LTrim())

(4622 row(s) affected)

Table 'AUDIT_STAGING'. Scan count 2, logical reads 188552, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.

Table 'AUDIT'. Scan count 2, logical reads 145602, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.

The ‘Worktable’ was being created in TempDB, thus slowing down the query. Amazing what some investigation can do

Answer To SQLSaturday #57 Question

Hash and non-hash Aggregate Streams – Someone in the session Execution Plan Basics asked me what was the difference between these two, and I did not have an answer. Rather than trying to make something up, I told the person I did not know, explained how many different new Execution Plan objects I see all the time, and said I would find out. The SQL Community is amazing!!!

Well, Craig Freedman’s blog answers this question.

Here is a quote from him:

“Stream aggregate is great for scalar aggregates and for aggregations where we have an index to provide a sort order on the group by column(s) or where we need to sort anyhow (e.g., due to an order by clause).

The other aggregation operator, hash aggregate, is similar to hash join.  It does not require (or preserve) sort order, requires memory, and is blocking (i.e., it does not produce any results until it has consumed its entire input).  Hash aggregate excels at efficiently aggregating very large data sets.”

God Bless,

Thomas

Tuesday, January 25, 2011

WHAT?!?! TheSmilingDBA speaking at #SQLRally

SQLRally Banner

WOW!!! That is all I have been thinking for the last 12-14 hours. My Session (3rd Normal Form: That's Crazy Talk!!! has been selected as the Design catagory for SQLRally )SQLRally.com. Thanks for the votes, and Thank You Lord!!!

Please go vote for the next round of sessions. http://www.zoomerang.com/Survey/WEB22BQZ99LQMG/ I have a second session (Execution Plan Basics) in the DBA Admin secion, but now that I have one session, you can vote for someone else's session. Do not want to be a hog.

God Bless,
Thomas

Tuesday, January 18, 2011

SQLRally voting, SQL Saturday #57 Houston, etc.

I bet I cannot copy these copyrighted pictures, but here goes.
SQLRALLY.com       image
Please go to SQLRally to vote for my session (3rd Normal Form: That’s Crazy Talk) in Orlando. This would be a great opportunity for me to expand the user base with my favorite session. This session was created when a SQL Server Central QOD (Question of the Day) had a large percentage of people not correctly answering a question about table design. Database design is such an important part of the Development Process (SDLC) that the new developers and DBAs in the SQL Community need to be taught these simple concepts.

Paul White { Blog | Twitter } has a great article today on Database Design on SQL Server Central. Paul Nielsen and Louis Davidson are some of the better known Database Design SQL Server people.

There are many other great sessions you can vote for, so please be apart of the community. The Rally is May 11-13, 2011 in Orlando. There are some pre-rally all day sessions. A great presenter is Grant Fritchey doing Execution Plans and Tuning. I hope I can make the session because it is sure to be informative and entertaining.

SQLSaturday #57 in Houston is less than 2 weeks away. If you can get to Houston on January 29th, do not miss this FREE day of SQL Server training. Click here to see a session list of the 7 tacks with 6 sessions per track. #SqlSat has gone viral. Yes, I said viral…and did I say FREE!!!

These FREE events are an unbelievable source of FREE SQL Server education, networking and chances for new presenters to get there feet wet.

The reading and work in the BI department has keep me so busy, I have not had time to Blog much…more reading than blogging. I do have 2 drafts saved about when not to use functions in WHERE clauses and when not to use the Missing Index suggestion on a Query plan.

Hopefully, I can get to these in February.

God Bless,
Thomas

Thursday, December 23, 2010

CXPACKET – that mysterious wait type

At my current employer, we have experience various levels of CXPACKET waits causing or thinking that is causes problems.

The first assumption we made that the CXPACKET wait was a problem came from SQL Server error message that suggested using OPTION (MAXDOP 1). Googling the details of the error, which included the words resource semaphore, was bringing up nothing. Calls to Microsoft Premier Support was not helping either. So, we changed queries that had long CXPACKET waits (some queries would never finish) or the Resource Semaphore deadlocking to use OPTION (MAXDOP 1) and we just waited for the query to run long (at least it finished). This happened to about 5 long running queries in our OLTP system when we converted to SQL Server 2005 and larger production machines.

A good read about this situation can be located here from Bart Duncan. Thanks Bart!!!

So, we thought every time we see CXPACKET waits, we had this same problem. The SQL Server community would make comments like CXPACKET is not the problem or look at your Query Plan. Tune the query, etc. etc. But I could not see the forest through the trees.

Now, after a couple of years of reading and using various tools for performance tuning, I have now realized why some in the SQL community keep saying that CXPACKET is not the problem. The problem I was having with this statement was they were either not communicating what the problem was or my limited understanding of performance tuning hindered me from comprehending the solution. And I really believed I knew what performance tuning was all about. Man, I was wrong. And finally still today I know there is more to learn.

Our OLTP system has 5 to 1 Reads to Writes. An analysis by EMC for a new VMAX gave us these statistics. This means that long processing queries were victim to this perceived notion that CXPACKET wait was our problem. This also included our OLAP system which is Cognos and I am now a member of this department. We just assumed it was a wait problem.

Adam Machanic has a great utility called sp_WhoIsActive. By default, it does not show CXPACKET waits. He also has a recorded session on Parallel Processing which I was blessed to host for Adam and the PASS Performance Virtual Chapter. He also has a series with SQL University, which I suggest reading. Also, Paul White ( Blog | Twitter ) has been trying to clue me in on CXPACKET via Twitter for sometime now. If sp_WhoIsActive is hard to understand, first start with sp_who3, another great monitoring tool. Thanks Mr. Denny

I have 2 executions of sp_whoIsAtive in my shortcuts in SSMS:

Ctrl+7 - exec dbo.[sp_WhoIsActive] '', 'session', 'Replication%', 'program'

image

Ctrl+8 - exec dbo.[sp_WhoIsActive] @filter = '', @filter_type =  'session', @not_filter = 'Replication%', @not_filter_type = 'program', @get_task_info = 2

image

The filter is for not seeing transaction replication in the view. The Ctrl+8 has the @get_task_info = 2 which shows a combination of CXPACKET and other waits associated with the SPID execution. This is really cool stuff for a DBA geek.

After reading the above links and riffling through some execution plans, I came to an ah hah moment when I saw a Display Estimated Query Plan and the Actual Query Plan not be the same. The difference included a Nested Loop in the estimate that did a Lookup and then a Hash Loop with 2 Index Scans in the actual plan.

What I came to realize was that if I tune the query and tables(indexes), parallelism sometimes goes away. Did you get that? …it goes away. Why?  Because now the actual plan does not need to run in parallel for the best plan.

Another one came when I realized the table (Fact table in a Data Warehouse with 30+ million rows) did not have a clustered index, but many non-clustered indexes. The suggested index from the Missing Index feature of SSMS showed a new Non-clustered index, when I applied it, it did not help 90+% like the missing index feature said. So, I went to the table, found the no clustered index on table, combined the surrogate keys into a clustered index and the Query Plan cost went from 1000+ to less than 50.

WOW!!! Now I get it. Thanks Adam, Paul and others for being patient with me

One more thing, I do not remember where I saw this, but in the sys.dm_os_waiting_tasks, when  exec_content_id = 0 and the wait is CXPACKET, that means the process is waiting for parallel processing to finish, and is a valid wait.

I think I will dig up some of these old query tuning experiences and try to show others through this blog what I have found. Maybe even a step by step process I go through nowadays to find problems with performance.

Now, back to the ETL on Data Marts.

God Bless,

Thomas

Wednesday, November 3, 2010

SQLSaturday #56 BI Edition in Dallas

Since I was missing PASS this year, not happy, I decided to drive to Dallas to attend a BI Edition of SQLSaturday on Oct 23rd, 2010.

This event was scaled back from a full SQLSaturday with 2 sponsors, Microsoft and Artis. So, there was not a lot of Vendor information, which help the Dallas SQLSaturday crew not have to attend to them. They were probably able to see some sessions instead.

Got to meet Ryan Adams along with Trevor, Tim Mitchell, Vic Prabhu and some new faces.

    

Above are Vic and Tim, the crowd and Sean.

Here are some more pictures.

         

    

     

More Pictures: http://picasaweb.google.com/dfwsqlsaturday/SQL_Saturday_Oct23#

I presented Transition from DBA to BI Architect, a new presentation. The main points were learning Dimensional Modeling which is not denormalization, but an actual technique and learning the Design Process, SDLC, for a BI department. If you were like me, my DBA duties included more support than design. So, I went through the last couple of months of work I have been doing along with the books I have been reading and bring my developer hat back into the mix.

SQL Server Deep Dives has a great section on BI. 2 authors were at this event, John Welch (Data Profiling) and Erin Welker (BI for the relational guy). It was amazing, as I was presenting and talking about the book, Erin walked into the main room, then I meet John in the Speakers room.

CXPACKET series coming soon.

God Bless,

Thomas

Thursday, October 7, 2010

Houston Tech Fest and Vacation

I will be heading to Houston on Friday afternoon to visit with other Microsoft technology geeks and speak/attend  Houston Tech Fest. Patrick LeBlanc ( Blog | Twitter ) and William Assaf ( Blog | Twitter) from Baton Rouge will be on the same track together giving the tech event some SQL Server sessions. It looks like there are some other SQL Server sessions from Tim Mitchell,  Trevor Barkhouse and Geoff Hiten.
It is great to be able to share the experience I have gained over the years, and network with others that have similar interests in SQL Server. I always meet one or 2 people in the industry to help with me in learning more tricks and tips.

Then, starting Sunday, I will drive to Kanuga, North Carolina for the 3rd year in a row to See The Leaves. This is a week of vacation away from the busy days of work and life to read, pray and meditate.
I plan on reading Richard Foster’s book on Spiritual Disciplines and Phillip Yancey’s Soul Survivor. The wood carving has hooked me for arts and crafts for the week and I plan of updating the walking cane and making a gift for Alex and Janet.

This past couple of weeks I have dove into Dimensional Modeling and using SSIS to ETL data from a supposedly Relational Database, but more and more looking like a database created by Object Oriented developers. Lots of inherent looking transaction tables as well as lookup tables.

I am still using the Kimball Methods (and books) to create and populate these Data Marts. I seemed to have a good feel for Dimensions, but the Fact tables I am struggling to hang on to the normalized structure just cause I know how to report off them. Other contractors seemed to do the same thing with the Facts – they are just transaction tables.

A little more practice and reports should get me out of the normalized only mentality. 

God Bless,
Thomas LeBlanc