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: 
aaronnayan
Creator III
Creator III

Help and info with Cartesian Product

Hi can someone give me information and description on when a Cartesian product is made?

-Description

-Disadvantages

-Benefits in some cases

-how it is created

anything else that you can think of

Many thanks guys

1 Solution

Accepted Solutions
marcus_malinow
Partner - Specialist III
Partner - Specialist III

Ok,

What is a Cartesian product?

When you join two tables (A and B) together which have no common fields, all combinations of your first table will be joined to all combinations of your second table.

For example

Table 1

Field 1     Field 2

f1v1          f2v1

f1v2          f2v2

Table 2

Field 3     Field 4

f3v1          f4v1

f3v2          f4v2

Cartesian product

Field 1     Field 2     Field 3     Field 4

f1v1          f2v1          f3v1          f4v1

f1v1          f2v1          f3v2          f4v2

f1v2          f2v2          f3v1          f4v1

f1v2          f2v2          f3v2          f4v2

Disadvantages

the main disadvantage is the sheer amount of memory required when dealing with large tables. Also you will be duplicating data with little benefit. Why not just keep your source tables separate if they have no relationship?

Benefits

The one time I would consider using a cartesian join is when creating an As At calendar. There are several examples of how to do this here on the community.

Hope that helps.

Marcus

View solution in original post

5 Replies
marcus_sommer

I think you should start here: Cartesian product - Wikipedia. What is the aim behind your question?

- Marcus

aaronnayan
Creator III
Creator III
Author

to give an overview on what it is and why it is bad and how it is formed all in a short summary

marcus_malinow
Partner - Specialist III
Partner - Specialist III

Ok,

What is a Cartesian product?

When you join two tables (A and B) together which have no common fields, all combinations of your first table will be joined to all combinations of your second table.

For example

Table 1

Field 1     Field 2

f1v1          f2v1

f1v2          f2v2

Table 2

Field 3     Field 4

f3v1          f4v1

f3v2          f4v2

Cartesian product

Field 1     Field 2     Field 3     Field 4

f1v1          f2v1          f3v1          f4v1

f1v1          f2v1          f3v2          f4v2

f1v2          f2v2          f3v1          f4v1

f1v2          f2v2          f3v2          f4v2

Disadvantages

the main disadvantage is the sheer amount of memory required when dealing with large tables. Also you will be duplicating data with little benefit. Why not just keep your source tables separate if they have no relationship?

Benefits

The one time I would consider using a cartesian join is when creating an As At calendar. There are several examples of how to do this here on the community.

Hope that helps.

Marcus

marcus_sommer

A cartesian product itself isn't bad - it depends on what do you want to do. Usually it will be created with joins between tables and if there are no common keys you could get depending on the join-type a cartesian product. The more important point will therefore be to understand how joins work and when they could have unexpected results - when maybe the keys are missing or in a different relation as assumed.

Therefore beside the above mentioned link take a look here: Join (SQL) - Wikipedia

- Marcus

jonathandienst
Partner - Champion III
Partner - Champion III

>>why it is bad

Not always - I have on several occasions deliberately constructed a Cartesian product because it was needed for certain types of analysis. However, if that is not the intention, then they can easily blow up to consume all available memory followed by a crash...

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein