Setting a Teradata primary index for a write replace stage

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
bcarlson
Premium Member
Premium Member
Posts: 772
Joined: Fri Oct 01, 2004 3:06 pm
Location: Minnesota

Setting a Teradata primary index for a write replace stage

Post by bcarlson »

I am using a Teradata Enterprise stage and I want to explicitly state the primary index to use when creating a target table (using the replace option). In DB2, I would use the syntax 'key=mykey1,mykey2'. Does this option work for Teradata as well? If so, what is the syntax? Is it any different than DB2? Is there documentation for it?

Note - I have not done an exhaustive search on DSXChange or in the documentation, but I have searched.

Thanks!

Brad
It is not that I am addicted to coffee, it's just that I need it to survive.
bcarlson
Premium Member
Premium Member
Posts: 772
Joined: Fri Oct 01, 2004 3:06 pm
Location: Minnesota

Post by bcarlson »

By the way, the reason I need this is because my input dataset has a 3-field natural key. The first 2 will not partition well. By default, if I do not specify a primary index (aka partitioning key), then DataStage will use the first field in the dataset as the key. Since that field will not distribute well, I need to use a different field and need to explicitly state in the dboptions.

Brad.
It is not that I am addicted to coffee, it's just that I need it to survive.
bcarlson
Premium Member
Premium Member
Posts: 772
Joined: Fri Oct 01, 2004 3:06 pm
Location: Minnesota

Post by bcarlson »

Okay, answering my own question. It is late and my coffee has run out. After digging a bit more in the documentation I found the primary index option right in front of my nose. Not sure how I missed it.

Anyway, thank you for sharing in my brain fart! Problem solved (drink more coffee before thinking).

Brad.
It is not that I am addicted to coffee, it's just that I need it to survive.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

So, coffee is a brain laxative? Or is it lack of coffee?

:lol:
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
bcarlson
Premium Member
Premium Member
Posts: 772
Joined: Fri Oct 01, 2004 3:06 pm
Location: Minnesota

Post by bcarlson »

Beans beans the magical fruit, the more you drink the more you ... think, so lets have beans for every drink!
It is not that I am addicted to coffee, it's just that I need it to survive.
Tariq1981
Participant
Posts: 2
Joined: Thu Jun 19, 2008 6:23 pm

Post by Tariq1981 »

bcarlson wrote:Okay, answering my own question. It is late and my coffee has run out. After digging a bit more in the documentation I found the primary index option right in front of my nose. Not sure how I missed it.

Anyway, thank you for sharing in my brain fart! Problem solved (drink more coffee before thinking).

Brad.
I want to define those keys as unique primary index. Teradata EE define them as primary index only which is not unique. Anyone can help me please?
throbinson
Charter Member
Charter Member
Posts: 299
Joined: Wed Nov 13, 2002 5:38 pm
Location: USA

Post by throbinson »

How about a Unique Secondary Index definition in the Close Command? Why the requirement for a UPI?
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Hmmm... isn't a "primary" index by definition unique? :?
-craig

"You can never have too many knives" -- Logan Nine Fingers
throbinson
Charter Member
Charter Member
Posts: 299
Joined: Wed Nov 13, 2002 5:38 pm
Location: USA

Post by throbinson »

You mean a Primary Key. A Primary Index is how the data gets hashed across AMPS in a Teradata DBMS. They can be two very different things.
Tariq1981
Participant
Posts: 2
Joined: Thu Jun 19, 2008 6:23 pm

Post by Tariq1981 »

throbinson wrote:You mean a Primary Key. A Primary Index is how the data gets hashed across AMPS in a Teradata DBMS. They can be two very different things.
Yah Right. What I know that UPI give us some performance advantages over the PI. Please correct me If I am wrong. So, we want to define those keys as UPI.
bcarlson
Premium Member
Premium Member
Posts: 772
Joined: Fri Oct 01, 2004 3:06 pm
Location: Minnesota

Post by bcarlson »

throbinson wrote:You mean a Primary Key. A Primary Index is how the data gets hashed across AMPS in a Teradata DBMS. They can be two very different things.
The Pimary Index is indeed how data is hashed across the amps, but a Unique Primary Index gives the same benefit (and better performance) as a primary key. Most of the TD Masters and DBA's that we have worked with have recommended UPI's vs. PKs.

Unfortunately, I do not know how to create them dynamcially with the TD Ent. stage and the replace option.

Just a thought... Have you tried enforcing a unique sort on the same key(s) prior to replacing your table? I wonder if DS is smart enough to recognize that if teh data is unique going into the TD stage, that the PI it creates should also be unique....

Brad.
It is not that I am addicted to coffee, it's just that I need it to survive.
hamzaqk
Participant
Posts: 249
Joined: Tue Apr 17, 2007 5:50 am
Location: islamabad

Post by hamzaqk »

The usage of UPI or USI depends on what you really require and what the needs are in terms of performance. Performance is really an issue when we need to pull data out of a table join it to some other table etc. Primary key is just a concept to enforce uniqueness to a record and in TD we apply this by both USI and UPI. They both work in the same way, the only difference is how the data is internally referenced in Teradata. In UPI you have a hashed value that points to the actual data on the amp. in USI you have a hashed value which then points to a value which has the information pertaining to where the data is stored on the amps. Just an extra hop! Secondary indexes do not form the basis of data distribution also.

P.S a combination of USI and a PI would be a good idea to be put on a table if you want data to be uniformly distributed amongst amps and at the same time to enforce uniqueness on an incoming record.

i am sleepy. hope it made sence :?
Teradata Certified Master V2R5
Post Reply