Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

What is synthetic keys? How it can be avoided?

Hi All,

What is synthetic keys? How it can be avoided?

Thanks,

Attitude

19 Replies
Not applicable
Author

Hi,

Please go through Page 473 of QlikView Reference Manaual. It will give your fair idea about Synthetic key and it can be avoided in two ways.

1. Use Qualify

2. Use Alias

Cheers,

DJ

SunilChauhan
Champion
Champion

if more than  one column linked between two tables its create sythetic key.

and you remove it using qualify/unqualify.

qualify all the fields

and unqulify the key field.

synthetic key creates  synthetic tables in Contol +T(table viewer)

sythetic table tells you how many fields creates synthic key

hope this help

Sunil Chauhan
m_woolf
Master II
Master II

You might want to read a thread titled "Should we stop worrying and love the synthetic key?" by John Witherspoon

Not applicable
Author

Hi At tude,

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.

Gabriel
Partner - Specialist III
Partner - Specialist III

Hi,

Synthetic Keys

When two or more input tables have two or more fields in common, this

implies a composite key relationship. QlikView handles this through synthetic

keys. These keys are anonymous fields that represent all occurring

combinations of the composite key. When the number of composite keys

increases, depending on data amounts, table structure and other factors,

QlikView may or may not handle them gracefully. QlikView may end up

using excessive amount of time and/or memory. Unfortunately the actual

limitations are virtually impossible to predict, which leaves only trial and

error as a practical method to determine them.

I think the best way to avoid Synthetic Keys is to (a) Rename the fields, (b) if you don't need the one of the field you delete it from your script.

Best Regards,

Gabriel

Anonymous
Not applicable
Author

By using qualify key word or by changing the field name

Not applicable
Author

Hi,

When we load data into qlikview there could be occasions where the fields of two tables may be the same name. The qlikview creates associations when loading the data to make it easier to manipulate but it could cause a problem when there are more than one pair of matching fields in two tables.

Solution: As the guys have mentioned above, you should rename it using either alias or qualify.

If you use the alias you can give a field name of your choosing eg: DeliveryDate as OrderDeliveryDate.

If you use the qualify keyword it would append the table name and then the field name - <table_name>.fieldname.

As there is no chance of tables with similar names, the qualify keyword will be a preferred choice if there are may fields to be changed. However if there is only a handful of fields, then you can use the field aliasing.

Hope this helps!

Not applicable
Author

Synthetic keys is a Complex Keys consisting of two or more fields connecting tables, Resource Heavy, May slow down calculations, Make a document harder to understand and maintain and Should be removed if possible.

How to Removed Synthetic keys:

- Renaming a fileds use( As) ex: Customer as %Customer

-Adding a Remarks or comment out unneccesary fields ex: // Customer,

-Concatenating fields

vishsaggi
Champion III
Champion III

Hello,

Go through the below link you will get more insights on the raised topic.

Synthetic keys: to have or not to have ?

Thanks,

V.