Re: Data model metadata design and data driven joins
Posted by: Rick James
Date: January 09, 2011 12:18PM

Key-Value fiasco on steroids! While it probably will work, it will _not_ scale.

Here's my advice in situations like this. There would be one (or more) Entity table...
1. Decide which fields you will actually _search_ on (use in a WHERE clause). Make them columns, and index them.
2. Put the rest of the stuff in JSON (or XML or ...) and store the resulting string in a TEXT field.

This design gives you
* Searchability. (Key-Value gives terrible performance and very clumsy SELECT queries with lots of JOINs.)
* Compactness. (This can be further enhanced by compressing the JSON and putting it into a BLOB.)
* Flexibility. The original has one level flexibility. JSON provides even more flexibility because you can have arrays and other structures in the blob of 'other attributes'.
* Your code (in PHP or whatever) can easily build/parse JSON, so those attributes are readily available.

In a typical situation there are multiple Entities. Each would be implemented as described, and with the appropriate explicitly indexed columns. Entity examples, using movies: Person (includes actors, directors, etc), Movie, Genre. Since there are many cases of persons both acting and directing, I deliberately did Person instead of Actor plus Director.

In the Movie example, there need to be many-to-many relationships between the Entities.
* Person:Movie -- Whether the Person acted or directed the move would be in the relation table.
* Movie:Genre
* Optionally even Person:Person -- if you are tracking who is married to whom.

Some rants:

http://forums.mysql.com/read.php?20,253353 (linked data)
http://forums.mysql.com/read.php?125,401536 (Database efficiency question)
http://forums.mysql.com/read.php?10,381215 (Different data types)
http://forums.mysql.com/read.php?24,367895 (How to speed up Query with WHERE AND/OR, with Subqueries using IN)
http://forums.mysql.com/read.php?10,355723 (Searching by using an index table, efficient queries?)
http://forums.mysql.com/read.php?20,400660 (“CACHE INDEX” and “LOAD INDEX INTO CACHE”)
http://forums.mysql.com/read.php?10,248799 (Opinions on this schema please =))
http://forums.mysql.com/read.php?115,356718 (table/query help)
http://forums.mysql.com/read.php?21,355863 (Large number of columns causing - Unknown Error)
http://forums.mysql.com/read.php?10,291247 (Help collating multiple rows from multiple tables into a single row)
http://forums.mysql.com/read.php?10,271718 (How best to storing User Profile data)
http://forums.mysql.com/read.php?10,268256 (Create tables: Shall i use one table or different tables in order to store data?)
http://forums.mysql.com/read.php?115,267274 (Query Optimization)
http://forums.mysql.com/read.php?10,379859 (school exercise I am suck on)

Options: ReplyQuote


Subject
Written By
Posted
Re: Data model metadata design and data driven joins
January 09, 2011 12:18PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.