Write array column or multiple records?

1

I am in doubt as to the best performance / performance option in reading the data. Targeting one with many records and being accessed all the time.

I need to specify which districts the customer is serving, ie a customer for several neighborhood ID's, it is better to do ...

Bank Structure Examples

Customer | Neighborhoods

1005 | 1,2,3,4,5,6,7,8,9,10,11,12 (ColumnArray)

OR

1005 | 1

1005 | 2

1005 | 3

...

    
asked by anonymous 20.10.2017 / 02:44

1 answer

1

In the first approach you are creating multivalued columns:

Cliente | Bairros

1005 | 1,2,3,4,5,6,7,8,9,10,11,12 (ColunaArray)

What is the problem with this approach? In a nutshell, every time you need to find all customers in a particular neighborhood you will have to do a like search, that is, a generic search in the neighborhoods column, this can be much worse than having "multiple relationships", I speak in terms of performance and maintenance (manipulation) of the data.

I found a very interesting post about multivalued columns in databases: link

In the second approach, using a table for clients , one for neighborhoods and a third for maintaining many-to-many relationships > You remove this problem regarding multivalued columns. Benefits? You will have standard tables ( First Normal Form or 1FN ), and simplify the process of finding customers by neighborhoods.

  

First Normal Form (1FN) - This is considered a part of the   relationship definition in the basic relational model. Its definition provides   that all the attributes of a relation must have their defined values   on atomic or indivisible domains. In other words, the fields   of a table must not be composite or multivalued. See below   a figure that shows the normalization of a table that is not in the   1FN for two relations.

For more information on the normal forms: link

It is important to keep in mind that there may be special cases where multivalued columns are required, however, whenever possible it would be advisable to avoid using this approach.

    
20.10.2017 / 04:02