I have to implement a many to many relationships between table in postgresql.
The default
SQL way to do this is to create :
As I am in postgresql I can do this in three differents way :
Which implementations will be faster ?
Regards,
PS : Usage is to create a json
representation of data1 containing all data2
It depends on how you will end up using them.
The first one: data1/data2+relation
is a "general purpose" implementation that will be fast for most uses. It's focused on the generic modeling of entities and its flexibility. The great thing about this option is that it will more easily survive future [unpredictable] changes in the model or application.
The second one data1/data2+array
, and third one data1/data2+json
are special cases that can be very fast for a reduced number of cases. If you need to optimize these ones, then these solutions can be great. However, they won't address very well other cases, and they could become real slow for general queries.
Bottom line: I would [very personally] go with the first one, unless I have a real strong reason to use one of the other ones.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.