473,413 Members | 2,051 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

columns in index

Hello,

What is the driving factor when making more columns indexable?
Should i see if i can modify existing indexes and merge new columns in
existing indexes or create a new index with new column?
regards,


jagdip

May 7 '07 #1
2 2411
db2admin wrote:
Hello,

What is the driving factor when making more columns indexable?
Should i see if i can modify existing indexes and merge new columns in
existing indexes or create a new index with new column?
Depends on how the column(s) is/are going to be used in queries. If you
have columns that are going to be filtered on (WHERE), sorted (ORDER
BY), or grouped (GROUP BY) then it may be worth defining an entirely
new index for them.

Alternatively, it may be worth shifting those columns to the front of
the column list of existing indexes (assuming this won't adversely
affect other queries which filter/sort on the columns which currently
appear at the front of the indexes' columns).

Finally, if the columns are simply being retrieved (not
filtered/sorted) it may still be worth updating index definitions to
attempt to achieve "pure index" queries where the table isn't touched
at all. For example, in small tables I often do something like the
following:
CREATE TABLE MYTABLE (
COLA INTEGER NOT NULL,
COLB INTEGER NOT NULL,
COLC INTEGER NOT NULL
);

CREATE UNIQUE INDEX MYTABLE_PK
ON MYTABLE (COLA)
INCLUDE (COLB, COLC)
ALLOW REVERSE SCANS;

ALTER TABLE MYTABLE
ADD CONSTRAINT PK PRIMARY KEY (COLA);

In the above definition, queries against MYTABLE which only filter or
sort on COLA will never touch the table. For example:

SELECT COLB, COLC FROM MYTABLE WHERE COLA 100;

The query above should use the index to figure out the set of rows to
retrieve, and should then retrieve the values of COLB and COLC straight
from the leaves of the index (the INCLUDEd columns are effectively a
tuple hanging off the leaves of the index tree).

Given the above definitions, if I have several queries some of which
filter/sort on COLB and COLC, and others which only filter/sort on COLC
I might consider creating the following definition:

CREATE INDEX MYTABLE1 ON MYTABLE(COLC, COLB);

All such queries could utilize the index above (including those that
only filter/sort on COLC as it appears before COLB in the index column
list). There'd be little point defining another index with COLB at the
front unless I had another set of queries that filtered/sorted on COLB
alone.
HTH,

Dave.

--

May 7 '07 #2
On May 7, 2:23 pm, "Dave Hughes" <d...@waveform.plus.comwrote:
db2admin wrote:
Hello,
What is the driving factor when making more columns indexable?
Should i see if i can modify existing indexes and merge new columns in
existing indexes or create a new index with new column?

Depends on how the column(s) is/are going to be used in queries. If you
have columns that are going to be filtered on (WHERE), sorted (ORDER
BY), or grouped (GROUP BY) then it may be worth defining an entirely
new index for them.

Alternatively, it may be worth shifting those columns to the front of
the column list of existing indexes (assuming this won't adversely
affect other queries which filter/sort on the columns which currently
appear at the front of the indexes' columns).

Finally, if the columns are simply being retrieved (not
filtered/sorted) it may still be worth updating index definitions to
attempt to achieve "pure index" queries where the table isn't touched
at all. For example, in small tables I often do something like the
following:

CREATE TABLE MYTABLE (
COLA INTEGER NOT NULL,
COLB INTEGER NOT NULL,
COLC INTEGER NOT NULL
);

CREATE UNIQUE INDEX MYTABLE_PK
ON MYTABLE (COLA)
INCLUDE (COLB, COLC)
ALLOW REVERSE SCANS;

ALTER TABLE MYTABLE
ADD CONSTRAINT PK PRIMARY KEY (COLA);

In the above definition, queries against MYTABLE which only filter or
sort on COLA will never touch the table. For example:

SELECT COLB, COLC FROM MYTABLE WHERE COLA 100;

The query above should use the index to figure out the set of rows to
retrieve, and should then retrieve the values of COLB and COLC straight
from the leaves of the index (the INCLUDEd columns are effectively a
tuple hanging off the leaves of the index tree).

Given the above definitions, if I have several queries some of which
filter/sort on COLB and COLC, and others which only filter/sort on COLC
I might consider creating the following definition:

CREATE INDEX MYTABLE1 ON MYTABLE(COLC, COLB);

All such queries could utilize the index above (including those that
only filter/sort on COLC as it appears before COLB in the index column
list). There'd be little point defining another index with COLB at the
front unless I had another set of queries that filtered/sorted on COLB
alone.

HTH,

Dave.

--
thanks a lot dave
your response was very valuable.

May 7 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Nikola Pecigos | last post by:
Hi, I have the following problem: We have an Oracle 9.2 with one table "document" which contains a path to the filesystem. If I want to index these files (HTML, PDF, World, Excel, etc.), I...
7
by: Alex | last post by:
Hi Everone, I need some advice on how to setup 4 columns where the outside two are absolute (120px) and the inner two (side by side) are relevent (Fluid) and change with the screen. Here's my...
14
by: gilles27 | last post by:
I am currently undertaking a review of the primary keys in a SQL Server 2000 database with a view to improving performance of queries. I have heard that, in the case of compound primary keys, it...
10
by: VA | last post by:
I got the following function to swap table columns from somewhere on the Internet function swapColumns (table, colIndex1, colIndex2) { if (table && table.rows && table.insertBefore && colIndex1...
1
by: Joseph Shraibman | last post by:
You can CREATE INDEX on multiple columns, and you can CREATE INDEX on a functions, but can you create an index on multiple columns and functions? For example if I want to create an index on...
5
by: explode | last post by:
I made a procedure Public Sub Novo(ByVal nova1 As String, ByVal nova2 As String) that creates a new oledbDataAdapter with insert update select and delete commads. I also added that commands can...
4
by: RichHamilton | last post by:
I have created a datagrid from a query, but when I display it it displays ALL the columns. I want to hide some columns. So I added this line applicantsDataGrid.Columns.Visible = false; ...
5
by: Romulo NF | last post by:
Greetings, I´m back here to show the new version of the drag & drop table columns (original script ). I´ve found some issues with the old script, specially when trying to use 2 tables with...
8
by: Sham | last post by:
I am trying to perform the following query on a table that has been indexed using Full Text Search. The table contains multiple columns than have been indexed. (Below, all xml columns are...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.