473,406 Members | 2,769 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,406 software developers and data experts.

Functional Index.. How to?

Hi Friends,
How to create the functional index in db2? Is it possible to do
that? I refered in online doc. But i am unable to find anything..

Thanks,
Thiru.
WantedToBeDBA.
Nov 12 '05 #1
10 7139
WantedToBeDBA wrote:
Hi Friends,
How to create the functional index in db2? Is it possible to do
that? I refered in online doc. But i am unable to find anything..

Thanks,
Thiru.
WantedToBeDBA.

DB2 does not support fucntional indexes. Teh closest match woudl be a
column genefrated by an expression. It is the same as a functional index
in the sense that you can exploit indexes on predicates with expressions.
The upside is that you can also benefit from the feature on table
access. The downside is that it takes memory in the data page.

Example:
CREATE TABLE T(c1 varchar(10), uc1 GENERATED ALWAYS AS (UPPER(c1)));
CREATE INDEX i1 ON T(uc1);
INSERT INTO T(c1) VALUES ('hello'), ('world');
SELECT c1 FROM T WHERE UPPER(c1) = 'HELLO';

Cheers
Serge
Nov 12 '05 #2
Serge,
are you saying that the optimizer could choose INDEX i1 for the query
SELECT c1 FROM T WHERE UPPER(c1) = 'HELLO'; ?
Is the query rewritten as SELECT c1 FROM T WHERE uc1 = 'HELLO'? I don't
have the latest the greatest release

Nov 12 '05 #3
ak************@yahoo.com wrote:
Serge,
are you saying that the optimizer could choose INDEX i1 for the query
SELECT c1 FROM T WHERE UPPER(c1) = 'HELLO'; ?
Is the query rewritten as SELECT c1 FROM T WHERE uc1 = 'HELLO'? I don't
have the latest the greatest release

Correct. The feature was added in DB2 V7.1 so unless you are out of date
beyond hope you will have it. It's quite popular. Lots of posters in
this group us it.

Cheers
Serge
Nov 12 '05 #4
Serge,
What will if the case be like this..

select max(numberic column) from tablename where <conditions>
Thiru
WantedToBeDBA.

Nov 12 '05 #5
Thiru wrote:
Serge,
What will if the case be like this..

select max(numberic column) from tablename where <conditions>
Thiru
WantedToBeDBA.

You mean you want to precompute the max()? Neither functional indexes
nor generated columns help here since both operate on a per/row basis.
What you need here are Materializeed Query Tables (MQT) (aka
"materialized views" or "indexed views" if you talk Oracle or MS SQL
Server speak).
Take a look at the CREATE TABLE statement with the AS clause.

Cheers
Serge
Nov 12 '05 #6
>> What you need here are Materializeed Query Tables (MQT)
....<<
depending on the conditions, there could be a lot of lock contention on
the MQT. Just imagine an MQT defined as select max(numberic column)
from tablename <no where clause>. If you set the MQT up as refresh
immediate, you have in fact serialized access to the table, as only one
transaction at a time has an update lock on the only row in the MQT.
If you don't want stale data (refresh deferred) and cannot afford that
much lock contention, you might find index covering a better
alternative.
Also you could add a column to MQT's definition to reduce lock
contention, like this:
select max(numberic column), another_column from tablename group by
another_column

Nov 12 '05 #7
ak************@yahoo.com wrote:
What you need here are Materializeed Query Tables (MQT)


...<<
depending on the conditions, there could be a lot of lock contention on
the MQT. Just imagine an MQT defined as select max(numberic column)
from tablename <no where clause>. If you set the MQT up as refresh
immediate, you have in fact serialized access to the table, as only one
transaction at a time has an update lock on the only row in the MQT.
If you don't want stale data (refresh deferred) and cannot afford that
much lock contention, you might find index covering a better
alternative.
Also you could add a column to MQT's definition to reduce lock
contention, like this:
select max(numberic column), another_column from tablename group by
another_column

The lock on the MQT would be per group. Presuming decent access
serialization would thus also be per group.
There is no free lunch.....

Cheers
Serge
Nov 12 '05 #8
Serge,

I'm not sure I'm following you. modifying 1 row in the base tqble will
lock only one row in the MQT.
When you say 'per group', do you mean the group in MQT definition?

BTW, using incremental refresh, we can join a refresh-deferred MQT with
its staging table. Since all the modifications insert to the staging
table, there is no additional lock contention. As long as both the MQT
and the staging table are small, the join is a snap - you get the
current information real quick.Naturally one need to refresh
frequently, otherwise the join slows down.

Although this approach works, it's a little bit tricky, so I'd prefer
index covering most of the time

Nov 12 '05 #9
Maybe there was a misunderstanding.
I understood the post meant that adding an MQT would serialize updates
due to locking.
Let's assume we an MQT which rolls events into a months.
It si correct that if I update two separate events in the same month
there will be a lock collision on the row of the MQT olding teh rolled
up information. Two events updated in separate months howvere would not
collide.

Cheers
Serge
Nov 12 '05 #10
>> Let's assume we an MQT which rolls events into a months.
It si correct that if I update two separate events in the same month
there will be a lock collision on the row of the MQT olding teh rolled
up information. Two events updated in separate months howvere would not

collide
... <<

Yes, of course, I would completely agree. However, sometimes it is not
easy to get rid of collisions - whatever GROUP BY we try to use, some
statement will eventually touch a row in every group, effectively
locking the whole table.

BTW, in certain cases we do want to serialize and lock contention on
MQT is OK

Nov 12 '05 #11

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

Similar topics

5
by: Mike Mascari | last post by:
Let's assume I have a table like so: CREATE TABLE employees ( employeeid text not null, name text not null ); CREATE INDEX i_employees ON employees(lower(name)); Let's also assume that...
2
by: Josué Maldonado | last post by:
Hello list, Is there a way to create indexes using functions like these: substring(prod_no,8,4) to_char(fkardex,'YYYYMM') substr(facnum,1,2) Help says is not possible but I would like to...
5
by: pmelies | last post by:
One of our web servers is not handling requests for ASP.net pages. We get a "A dynamic link library (DLL) initialization routine failed." error message, though nothing is recorded in the event...
1
by: David Garamond | last post by:
I want to know how functional indexes are used "in the real world". Here are the common uses: * non-unique index on the first parts of a longish text field (SUBSTRING(field)) to save disk space,...
7
by: Janning Vygen | last post by:
Hi, i searched the docs and the archives and was really wondering that i have not found anything searching for "functional index primary key". i would like to have a table of members with...
4
by: Dennis Gearon | last post by:
Is the following example a good, and correct one, for using a functional index? (the 'flip_bits' function would have to be written, and for the correct size of bit(N) ): I think I came up with a...
0
by: Oracle10 | last post by:
Please can anybody tell me if oracle considers index if decode is used? To explain myself, in my where clause I have one condition tab1.col1|| '-' ||tab1.col2 = decode(tab2.col1,'ALL',tab1.col1||...
2
by: Deepa Jeevagan | last post by:
Hi, The application I am currently working on is developed in Oracle 8i. I have a table which has a nullable numeric column say CustNo. This column has an index defined on it and oracle uses...
1
by: smruti | last post by:
What is functional index?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
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...
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,...

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.