Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
arethaking
Creator II
Creator II

What is Synthetic key. And how to avoid it?

Hi all,

I got an error message to re-lode my tables in Qlikview file.

please help

1 Solution

Accepted Solutions
arvind1494
Specialist
Specialist

You can find more info about Synthetic keys in the QlikView manual.

The concept is, when you join two tables, it can be done based on primary key and foreign key relationship based on a particular column. We can treat it as a normal join between the two tables. The problem starts when the joining is on more than one columns.

The synthetic key scenario is when you have same column name for more than one columns between the loaded tables (e.g. C1 & C2 is common between Table 1 & Table 2). QlikView internally relates those tables based on the common column names and create another internal table (synthetic table) with the matching columns and a synthetic key generated by all possible combined values of the matching columns (C1, C2 and Synthetic Key column....starts with '$'). The impact could be a datamodel with unncessery jumble as well as wastage of memory. e.g. think of two tables with millions of rows. If they have synthetic keys between them, that would generate another table, with large number of rows...and completely unnecessery...finally, eating up memory. And a 'not so well' designed datamodel can of course lead to performance impact in terms of time, as you know.

Now, the question is, if you really want to get rid of the issue, how to fix it.

1. Using QUALIFY

This enforces QlikView to qualify all/selected fields. Qualify implements the check on full path of the field (e.g. Field is designated by Tablename.FieldName).

e.g.

Qualify *;
turns qualification on for all field names of the subsequent table(s).

Qualify “*_Name”;
turns qualification on for all field names ending with _Name in the ssubsequent table(s).

Qualify “Name_*”;
turns qualification on for all field names Starting with Name_ in the ssubsequent table(s).

Qualify “Amt*”,Profit;
turns qualification on for Profit and all field names starting with Amt.

Qualify S???;
turns qualification on for four character field names starting with S.

Ofcourse you don't always need to qualify ALL the fields of a table. E.g. you have C1 & C2, two common columns between Table 1 & Table 2. C1 is used to join the 2 tables and C2 is the column that you think might create Syn Key. You will do something like:

Qualify *;

Unqualify C1;

Select * from Table1;

Select * from Table2;

This will ensure that only C1 is used to join the two tables, eventually nullifying the possibility of Syn Key.

2. Autonumber

If you need to concat the Syn Key candidate fields and create your own key, you can use Autonumber/Autonumberhash128/Autonumberhash256 function. This will create a unique integer value for each distinct combination of the concateneted columns. Autonumberhash128 and Autonumberhash256 creates 128bit and 256bit values respectively.

E.g. In the previous example, autonumber(C1&C2) or autonumberhash128(C1,C2) or autonumberhash256(C1,C2) will create the necessery uniqueness.

One word of cauton using Autonumber is, as they are system generated, you do not have any control over the values. And for external QVDs, since the range of unique autonumber values are limited, uniqueness is not guranted. the hash128 and hash256 functions particularly address this issue and widens the range to ensure uniqueness.

3. Aliasing

If you alias the comflicting fields, i.e. the Syn Key candidate fields, they would be treated as different fields and will not be joined automatically by QV. This is a simple solution based on how flexible the requirements are, in renaming the fields.

Ofcourse you will find many other examples in this forum/QV manual that will strenthen your concept. This is my understanding from my experience with QV. Please let me know if it answers your question on my post.

View solution in original post

6 Replies
Anonymous
Not applicable

Hi Aretha ,

Follow this link , it has detailed explanation of Synthetic keys and how to handle them .

Hope this helps.

Regards

Anonymous
Not applicable

Anil_Babu_Samineni

Question is not full filled?

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
arvind1494
Specialist
Specialist

You can find more info about Synthetic keys in the QlikView manual.

The concept is, when you join two tables, it can be done based on primary key and foreign key relationship based on a particular column. We can treat it as a normal join between the two tables. The problem starts when the joining is on more than one columns.

The synthetic key scenario is when you have same column name for more than one columns between the loaded tables (e.g. C1 & C2 is common between Table 1 & Table 2). QlikView internally relates those tables based on the common column names and create another internal table (synthetic table) with the matching columns and a synthetic key generated by all possible combined values of the matching columns (C1, C2 and Synthetic Key column....starts with '$'). The impact could be a datamodel with unncessery jumble as well as wastage of memory. e.g. think of two tables with millions of rows. If they have synthetic keys between them, that would generate another table, with large number of rows...and completely unnecessery...finally, eating up memory. And a 'not so well' designed datamodel can of course lead to performance impact in terms of time, as you know.

Now, the question is, if you really want to get rid of the issue, how to fix it.

1. Using QUALIFY

This enforces QlikView to qualify all/selected fields. Qualify implements the check on full path of the field (e.g. Field is designated by Tablename.FieldName).

e.g.

Qualify *;
turns qualification on for all field names of the subsequent table(s).

Qualify “*_Name”;
turns qualification on for all field names ending with _Name in the ssubsequent table(s).

Qualify “Name_*”;
turns qualification on for all field names Starting with Name_ in the ssubsequent table(s).

Qualify “Amt*”,Profit;
turns qualification on for Profit and all field names starting with Amt.

Qualify S???;
turns qualification on for four character field names starting with S.

Ofcourse you don't always need to qualify ALL the fields of a table. E.g. you have C1 & C2, two common columns between Table 1 & Table 2. C1 is used to join the 2 tables and C2 is the column that you think might create Syn Key. You will do something like:

Qualify *;

Unqualify C1;

Select * from Table1;

Select * from Table2;

This will ensure that only C1 is used to join the two tables, eventually nullifying the possibility of Syn Key.

2. Autonumber

If you need to concat the Syn Key candidate fields and create your own key, you can use Autonumber/Autonumberhash128/Autonumberhash256 function. This will create a unique integer value for each distinct combination of the concateneted columns. Autonumberhash128 and Autonumberhash256 creates 128bit and 256bit values respectively.

E.g. In the previous example, autonumber(C1&C2) or autonumberhash128(C1,C2) or autonumberhash256(C1,C2) will create the necessery uniqueness.

One word of cauton using Autonumber is, as they are system generated, you do not have any control over the values. And for external QVDs, since the range of unique autonumber values are limited, uniqueness is not guranted. the hash128 and hash256 functions particularly address this issue and widens the range to ensure uniqueness.

3. Aliasing

If you alias the comflicting fields, i.e. the Syn Key candidate fields, they would be treated as different fields and will not be joined automatically by QV. This is a simple solution based on how flexible the requirements are, in renaming the fields.

Ofcourse you will find many other examples in this forum/QV manual that will strenthen your concept. This is my understanding from my experience with QV. Please let me know if it answers your question on my post.

balabhaskarqlik

Share your sample script, then it's possible to give an idea on that.

qlikviewwizard
Master II
Master II

Hi,

If you get any error, please provide screen or sample data.