DP-300 Microsoft Azure Database – Evaluate performance improvements

  • By
  • July 10, 2023
0 Comment

1. 63, 68. identify and implement index changes for queries

In this video we’re going to have a look at identifying and implementing index changes for queries together with assessing index design for performance. So we’ve had a look at what indexes are in previous videos. So they stop us from having to go through the entirety of a table and allow us to seek a particular point. So what are the requirements for or indexes? Well, first of all, a big table. If you’ve got a small table, you probably don’t need an index. Small tables, even if you provide an index, may just use a scan anyway. You should have a small column size. So the best are things like numerics, but if you’ve got others like smaller text sizes, then that could be good as well.

So having an index on an Nvarchar 60 probably not that good. You should use columns which are in the where clauses and they need to be sagable. So in other words, we’ve had a look at when you’re using functions like year and left and other things, they just don’t work with indexes with sags, whereas if you used other things those are sagable. So less than greater than that sort of thing. So if you’re using a like then this is a perfectly well formed Sargable where clause. So wear hai is at the beginning. However, if I said where hai is anywhere, well, I can’t use an index for that because I would have to go through all of the items of the index anyway. So how do you create an index? Well, in TSQL you would say create and then you would either have a non clustered or a clustered index.

So name of index so I usually put IX underscore and then the table and then underscore and then the individual columns that he was indexing because the clustered or nonclassed index name needs to be unique. So create clustered or nonclustered I’ll talk about the differences in just a moment. Index the name of the index on and then the name of the table and then in brackets, that’s where you put the columns. Now what is a clustered index as opposed to a non clustered index? Well, you’re only allowed one clustered index per table. It’s frequently used with primary keys. When you create a primary key, you also create automatically a clustered index. It resorts the table based on the index. So a heap is a table without a clustered index. Once you have a clustered index, it gets resorted. So you should use it for frequently used queries and range queries. So between x and y, clustered indexes, when created with primary keys, use the unique clustered index.

So that means that there can only be one particular raw with each value. If you’re using multiple columns and it’s only one particular raw for the combination of the values, it is possible to create a nonunique clustered index. Most of the time it will be unique. So these are things that should be accessed sequentially in ranges. It’s quite good for identity columns. So identity columns are automatically created data columns. So it starts off one, two, three. In other words, it’s a sequential numbering. You don’t actually specify, the computer does. And clustered indexes are frequently used. So, whereas clustered indexes resorts a table, and you can only have one per table, because you can’t sort a table two different ways at the same time.

You can have as many nonclassed indexes as you want. It creates a separate index. But beyond, if you insert a row, update a row, delete a row, merge data sets together, then all of the indexes will need to be adjusted. So if you’ve got too many indexes, that could be slowing down your machine. Now, you don’t have to index the entire table. Suppose you have a where, a frequently used query with a very specific where. So where the city is equal to offer. Well, you could have an index that looks at just that particular where clause, that’s called a filtered index.

Now let’s imagine a hypothetical index. So I’ll create this index and it’s got references to all of these particular rows. And this happens on a particular page. And then there’s a new page which has everything else, and then another page which has everything else as well. So each of these are on separate but linked pages. And there’s also a hierarchy which says, go to this page if you want one to eight, this for nine to 17, this for 18 to 25. And this is all that we can contain on a particular page in this example. Now, what happens if I insert raw number 16? Well, I need to put it in here because an index needs to be in the right order, but I haven’t got any room. So what I need to do is break the page and create a separate page, maybe 16 goals on this page, 17 goals on the next page. It doesn’t then redo everything, it just creates a new page.

Now, suppose you didn’t want your index to use up all of the available space because you knew that you were going to be adding additional information. So at the time of creating the index, you wanted it to say, just allow five for each particular page. So it could have eight in terms of capacity. But you’re just saying, actually all I want is five. Well, you can do that with something called the fill factor. So I can say with fill factor equals, and in this case it would be five divided by eight or 62 or so. So now, if I have this index and Raw 15 comes along, then good news, here’s my page. It’s only got five items on it, I can just insert it, no need for the page to split, which obviously will take some time. And finally we can say that it is going to be sorted ascending or descending, just like with an order by.

So the default is ascending. If you happen to be using a particular query, lots of queries why it’s descending, then you might want to create the index that way. So this is how we can create an index in TSQL. Now you can’t do this for the Azure SQL Database, but in other types of databases you could in SSMS go to the indexes part, right and click and go New Index and have a visual way of doing that. As you can see, it just gives you an index template for the Azure SQL Database. So if I connect to a different database, I’m going to connect to my local database. So this could be like an SQL Server on Azure Virtual Machine and go to a particular table and right and click on Indexes and go to New Index.

Here we can see we can create clustered indexes and non clustered indexes and so forth and actually have a dialog box to do that, but that is not available in Azure SQL Database. Just a quick note about Column store. Now we won’t be talking too much about Column Store, but just to let you know, the traditional way of having data stored. So like this is called Raw Store. So we have each raw contained within a set unit. In SQL Server 2012, they introduced Column Store and it wasn’t that good in terms of number of situations when you can use it in 2012, but it got a lot better in 2014 and then got even better in 2016. So what Column Store does is it stores each column separately and then you have to get it together at the end.

So for instance, just like you get ranges of rows together, well, it’s the same way of being able to get columns together. So the advantage of this, if you’ve got a huge amount of data, your data warehouse we’re talking about, wouldn’t it be a lot easier to be able to just say, okay, give me all of the roles with this particular city and what a Column Store table does, and therefore a Column Store index does. Is it concentrates on a particular city or anything else in a page and it compresses it down.

So it says this is City 112-3456 and it has a list of all of the meanings of what city one and two and so forth are in the page header. We’ll be looking at Column Store later when we talk about the use of compression for tables and indexes. But if you see what Column Store is, it’s not the standard type of index, it’s an index on a different type of table. However, Column Store indexes are generally available in more status for Azure Database. So creating a table use create clustered or nonclustered or unique clustered. You could have unique nonclustered if you want index, name of the index on name of table and then in brackets the columns. You could have a filtered index if you use the where clause. And you can have spaces in the index.

So it takes more pages, but there’s less on each page if you use the with fill factor and that is expressed as a percentage. Except you don’t use a percentage sign, so it goes from one to 10. And finally, if you no longer need an index, you can always drop it. If I write and click on an index and go to script index as drop, you can see it’s a very simple drop index. Name of index on the name of the table. So it’s the first part, but just not using the words unique, non, clustered or clustered.

Comments
* The most recent comment are at the top

Interesting posts

IBM Certified Data Scientist: Building a Career in Data Science

In today’s digital age, data is the new oil, driving decision-making and innovation across industries. The role of a data scientist has become one of the most sought-after positions in the tech world. If you’re considering a career in data science, obtaining the IBM Certified Data Scientist certification can be a game-changer. This certification not… Read More »

How to Balance Work and Study While Preparing for IT Certification Exams

Balancing work and study while preparing for IT certification exams can feel like an uphill battle. Juggling a full-time job and intense study sessions requires careful planning, discipline, and creativity. The pressure of meeting job responsibilities while dedicating time and energy to study can be overwhelming. However, with the right strategies and mindset, you can… Read More »

10 Highest Paying IT Certifications

In the ever-evolving world of information technology, certifications are more than just a feather in your cap – they’re a ticket to higher salaries and advanced career opportunities. With the tech landscape constantly shifting, staying updated with the most lucrative and relevant certifications can set you apart in a competitive job market. Whether you’re aiming… Read More »

Strategies for ISACA Certified Information Systems Auditor (CISA) Exam

Are you ready to take your career in information systems auditing to the next level? The ISACA Certified Information Systems Auditor (CISA) exam is your ticket to becoming a recognized expert in the field. But let’s face it, preparing for this comprehensive and challenging exam can be daunting. Whether you’re a seasoned professional or just… Read More »

Preparing for Juniper Networks JNCIA-Junos Exam: Key Topics and Mock Exam Resources

So, you’ve decided to take the plunge and go for the Juniper Networks JNCIA-Junos certification, huh? Great choice! This certification serves as a robust foundation for anyone aiming to build a career in networking. However, preparing for the exam can be a daunting task. The good news is that this guide covers the key topics… Read More »

Mastering Microsoft Azure Fundamentals AZ-900: Essential Study Materials

Ever wondered how businesses run these days without giant server rooms? That’s the magic of cloud computing, and Microsoft Azure is a leading cloud platform. Thinking about a career in this exciting field? If so, mastering the Microsoft Certified: Azure Fundamentals certification through passing the AZ-900 exam is the perfect starting point for you. This… Read More »

img