1. Trang chủ
  2. » Công Nghệ Thông Tin

Brad’s Sure Guide to SQL Server Maintenance Plans- P23 pptx

5 221 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Rebuild Index Task
Trường học Standard University
Chuyên ngành Database Management
Thể loại Hướng dẫn
Năm xuất bản 2023
Thành phố Standard City
Định dạng
Số trang 5
Dung lượng 556,9 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

For this example, we are going to keep things simple, so let's assume we want to perform the Rebuild Index task for all user databases.. The Define Rebuild Index Task screen reappears, a

Trang 1

For this example, we are going to keep things simple, so let's assume we want to perform the Rebuild Index task for all user databases In this case, choose the option shown in Figure 7.2, and then click OK.

Figure 7.2: To keep things simple, select the "All user databases" option.

The Define Rebuild Index Task screen reappears, and the two drop-down boxes I referred to

earlier are displayed below the Databases drop-down box, but they are grayed out, as shown

in Figure 7.3

Figure 7.3: The "Object" and "Selection" drop down boxes are not available.

Trang 2

So what's going on? Why are these two options grayed out? The reason is that these two options are only available if you select one database on which to run the Rebuild Index task Since we selected All user databases, they are not available.

Selecting a Specific Database

Although it does not apply to our example, let's take a look at what happens if you select only

a single database, such as AdventureWorks, for the task To do this, select These databases

from the screen shown in Figure 7.2 and then check the checkbox for AdventureWorks

When you click OK, this section of the Define Rebuild Index Task screen will look as shown

in Figure 7.4

Figure 7.4: When a single database is selected, then the "Object" drop-down box

becomes available.

Notice that Specific databases now appears in the Databases drop-down box, the Object box

is now available, and the Selection box is still, for the time being, grayed out.

What the Object and Selection options allow you to do is to selectively rebuild some of the

indexes in your database, and not others If you click on the Object drop-down box, you'll see

the choices as shown in Figure 7.5

Figure 7.5: You must select either "Table" or "View."

Notice that there are three choices for Object If you leave the default option selected, Tables and views, then the Rebuild Index task will be applied to the indexes associated with all tables and all indexed views in the selected database In other words, you haven't changed anything In order to narrow the scope of the task to specific objects, you need to choose either Table or View Having done this, the Selection drop-down box becomes available For

example, choose Table, and then click on "Select one or more" in the now available Selection

Trang 3

Figure 7.6: You can select which tables you want to rebuild with the Rebuild Index task.

Now, you get the option of selecting specific tables within the AdventureWorks database,

to which this task should apply For example, you could choose to rebuild only the indexes associated with the dbo.ErrorLog table, or you could select some combination of tables, by checking each of the relevant checkboxes

Why would you want to rebuild the indexes for some tables and not others? Actually, there is

a very good reason for this In most databases, there are some tables that are virtually static; they rarely if ever change, and so there is no benefit in rebuilding their associated indexes

as they don't, over time, develop wasted empty space or become logically fragmented By selecting only those indexes that really need defragmenting, you can reduce the time it takes

to perform the Rebuild Index task and, at the same time, reduce the resource overhead associated with this task

The problem I see is that most people who are using the Maintenance Wizard won't have the knowledge to determine which indexes are relatively static and which are subject to a lot of wasted space and logical fragmentation If you are at the level where you know how to evaluate each index using the sys.dm_db_index_physical_stats DMF, in order to apply a selective rebuild process, then the chances are you are probably better off implementing this process using T-SQL or PowerShell scripts, and avoiding use of the Maintenance Plan Wizard

in the first place

Before we move on, let's briefly consider the View option that is available in the Object

drop-down box, as shown in Figure 7.7

Trang 4

Figure 7.7: You can select which indexed views you want to rebuild with the Rebuild

Index task.

In this case, View doesn't refer to conventional views, but to indexed views Indexed views

are physical views, unlike regular views, which are only materialized when they are called by

a query Because indexed views are physical, they need rebuilding just like regular indexes

As per my advice with regard to the Table option, if you need this kind of granularity for the

maintenance of your indexes, you shouldn't be using the Maintenance Plan Wizard for this task

Trang 5

While I have taken a little time to explain what the Object and Selection drop-down boxes

do, I am recommending that you don't use then, as they just make Maintenance Plans overly complicated, defeating the benefit of using them in the first place

Free space options

We still have several more choices to make before we are done configuring this task Note that the discussion of these options assumes that each of your tables has a clustered index, and is not a heap A heap is a table without a clustered index As a best practice, all tables should have a clustered index

The first two choices are listed under Free space options and include Reorganize pages with the default amount of free space and Change free space per page percentage to, as shown

in Figure 7.8 You can choose one option or the other, but not both

Figure 7.8: These options can have a significant impact on the Rebuild Index task.

The default option of Reorganize pages with the default amount of free space is a little

confusing First, it says reorganize, not rebuild Remember, we are working on the Rebuild Index task, not the Reorganize Index task Don't let this confuse you into thinking that selecting this option reorganizes indexes, rather than rebuilding them It does the latter, and this is actually a mistake in the user interface It really should say "rebuild," not "reorganize." The second part of this first option says "default amount of free space." What does that mean? When creating a SQL Server index, there is an option to create the index with a certain amount of free space on each data page This setting is known as the fill factor If an index

is created without specifying a fill factor, then the default fill factor is used, which is 100 (actually 0, but 0 means the same thing as a 100% fill factor) This means that no free space is created for the data pages of an index

The potential problem with a fill factor of 100 arises when data is added to a table as a result

of an INSERT or UPDATE, and a new row needs to be added to a data page If there is no room for it, then SQL Server will reorganize the rows, moving some of the rows onto a new data page, and leaving some on the old data page This is known as page splitting While page

splitting is a normal SQL Server activity, too much page splitting can cause performance

Ngày đăng: 04/07/2014, 23:20

TỪ KHÓA LIÊN QUAN