0% found this document useful (0 votes)
101 views3 pages

TAFJ Promoted Columns

Uploaded by

lolitaferoz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
101 views3 pages

TAFJ Promoted Columns

Uploaded by

lolitaferoz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

TAFJ Promoted Columns

This section explains how to promote columns for TAFJ for performance improvements.
Promoted columns are relational columns where data is generated via a function when it is
inserted/updated. Therefore, these columns will perform better when indexed over an xml
index. NOTE THAT THIS WILL ONLY WORK FOR SINGLE VALUE COLUMNS. To index
multi-value columns see Oracle’s XMLINDEX clause. The advanced USE CASE shows how
to index a multi-value without XMLINDEX, but it requires a code change that probably
wouldn’t work with a normal T24 use case.

This SQL mode command outputs a script to create a promoted column for indexing. Use it
with the SPOOL command.

CREATE-PROMOTED-COL <<FUNCTION NAME>> ATTRIBUTE=<<Att# in Dict>>


DATATYPE=<<( NUMBER|VARCHAR)>> LENGTH=<<Length for Col>>COLNAME=<<COL
to index>> TABLENAME=<<table>>

Here is an example:

tafj@localhost:TB201507>SPOOL

tafj@localhost:TB201507>CREATE-PROMOTED-COL IX_RANK ATTRIBUTE=2


DATATYPE=VARCHAR LENGTH=30 COLNAME=RANK TABLENAME=FBNK_CURRENCY

tafj@localhost:TB201507>SPOOL

The resulting script should show up under $TAFJ_HOME/log/DBTools.

Below are examples of what to do for each database.

Promoting Columns for SQLServer example


Below is an example of how to promote the RANK column (xml attribute 1) on the
FBNK_CURRENCY table

set QUOTED_IDENTIFIER on;


go

CREATE FUNCTION udf_RANK_CURRENCY_C1 (@xmlrecord XML)


RETURNS integer
WITH SCHEMABINDING
BEGIN
RETURN @xmlrecord.value('(/row/c1/text())[1]', 'integer')
END

ALTER TABLE FBNK_CURRENCY


ADD RANK AS dbo.udf_RANK_CURRENCY_C1(XMLRECORD) PERSISTED

CREATE INDEX ix_FBNK_CURRENCY_RANK ON FBNK_CURRENCY(RANK)


Promoting Columns for DB2 example

drop function extractC1_INT@

create function extractC1_INT(xmlrecord


XML) returns INTEGER
language sql contains sql
no external action deterministic
return xmlcast(xmlquery('$t/row/c1' passing xmlrecord as "t") as

varchar(10))@ set integrity for FBNK_CURRENCY off@

alter table FBNK_CURRENCY add RANK INTEGER


generated always as (extractC1_INT(XMLRECORD))@

set integrity for FBNK_CURRENCY immediate checked force

generated @ create index IX_FBNK_CURRENCY_RANK on

FBNK_CURRENCY(RANK)@

Promoting Columns for Oracle example


alter table
fbnk_currency
add (
RANK number(10) as (NVL(CAST(extractValue(xmlrecord,'/row/c1') as
NUMBER),0))
);

create index IX_FBNK_CURRENCY_RANK on FBNK_CURRENCY(RANK)

Drop and Recreate the Views (All Databases)


Drop and recreate view so that the new column will go directly to the rdbms
column and not the XML column when the view is queried. (View can be
retrieved from the particular database or generated by using DBImport with
DBImport logging set to DEBUG in
$TAFJ_HOME/conf/TAFJTrace.properties. Here you just want to regenerate the
VIEW ONLY for the PARTICULAR TABLE ONLY)

Oracle example of getting the view definition from the


database: SQL> set long 100000
SQL> select text from all_views where view_name = 'TAFJV_FBNK_CURRENCY';

This is a DB2 example only for recreating the view to use the new column RANK.

CREATE VIEW
TAFJV_FBNK_CURRENCY as
SELECT a.RECID, a.XMLRECORD
"THE_RECORD"
,a.RECID "CURRENCY_CODE"
,RANK "RANK"
,XMLCAST(XMLQUERY('$d/row/c2[position()=1]' passing a.XMLRECORD as "d") as
VARCHAR(4000)) "NUMERIC_CCY_CODE"
,XMLCAST(XMLQUERY('$d/row/c3[position()=1]' passing a.XMLRECORD as "d") as VARCHAR(4000)) "CCY_NAME"
,XMLQUERY('$d/row/c3' passing a.XMLRECORD as "d") "CCY_NAME_3"
,XMLCAST(XMLQUERY('$d/row/c4[position()=1]' passing a.XMLRECORD as "d") as VARCHAR(4000))
"NO_OF_DECIMALS"
,XMLCAST(XMLQUERY('$d/row/c5[position()=1]' passing a.XMLRECORD as "d") as VARCHAR(4000))
"QUOTATION_CODE"
,XMLCAST(XMLQUERY('$d/row/c6[position()=1]' passing a.XMLRECORD as "d") as VARCHAR(4000))
"QUOTATION_PIPS"
,XMLCAST(XMLQUERY('$d/row/c7[position()=1]' passing a.XMLRECORD as "d") as VARCHAR(4000))
"DAYS_DELIVERY"

You might also like