

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think you should start here: Cartesian product - Wikipedia. What is the aim behind your question?
- Marcus


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
to give an overview on what it is and why it is bad and how it is formed all in a short summary

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
>>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...
