473,804 Members | 3,675 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2434
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
7390
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 have to use the datastore type "FILE_DATASTORE". Another table "lng_text" stores the titles and descriptions for multiple languages for each row in table "document".
7
3247
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 rough layout:
14
4766
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 is important to select the correct order for the columns within the key. For instance, imagine a table called OrderLine which has primary key columns as follows- Ledger OrderNumber
10
12763
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 != colIndex2) { for (var i = 0; i < table.rows.length; i++) { var row = table.rows; var cell1 = row.cells; var cell2 = row.cells;
1
1539
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 lower(textfield), intfield ---------------------------(end of broadcast)--------------------------- TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
5
2182
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 change depending how many columns are in a Table. I add a new column with this code: Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Try...
4
1047
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; But that gives me this error: Inner Exception
5
13817
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 drag&drop on the same page (which was not possible). Now i´ve a new concept of the script, more object oriented. I´ve also commented the whole code so you guys can easier understand it engine. What exactly we need when trying to make a column drag &...
8
5118
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 indexed). dbo.maintable(ProfileID int pk) dbo.fts_table(ProfileID int pk fk, col1 xml, col2 xml, col3 xml) I want to perform a query that will return any rows that contain ‘x’ and ‘y’ in any columns. I.e. ‘x’ could be in col1 and ‘y’ could be in
0
9585
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10586
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10338
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10082
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7622
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6856
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5658
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3823
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.