Create more fields and avoid JOIN decreases load?

1

I have 3 tables that are linked:

1ª tabela: 
GRADE (grade de horários)
Campos: ID - GRADE - ESTADO - VALIDADE 

2ª tabela: 
BLOCOS (blocos de horários da grade)
Campos: ID - ID_GRADE - BLOCO - DIA_SEMANA - DURACAO

3ª Tabela:
COMERCIAIS
resumidamente estes campos: ID, ID_CLENTE, ID_GRADE, ID_BLOCO

I'm using a FK to bind the IDs to their respective references in the tables.

My question is: In the 3rd table can be to see the foreign key ID_GRADE , which is also in the 2nd and I put it thinking of reducing the load in the database, because if by chance I try to put the table GRADE in ESTADO-> desativado , the system will first check if there is any record to run before changing its state to disabled.

I know I could do this using JOIN in the BLOCKS table, but I think if I can save ID_GRADE , I avoid using JOIN , since the COMMERCIAL table will have many records.

Is my thinking correct or am I creating atoa fields?

    
asked by anonymous 23.06.2016 / 21:09

2 answers

1

Do not repeat the field, use JOIN, create an index in the column. Think about the relationship that exists between your entities. Then analyze the performance of the query.

    
23.06.2016 / 21:49
1

Not recommended for doing this

Pros:

You gain in performance in queries;

Visibly it is better to consult the table.

Cons:

Your application will have to treat the two tables when it changes;

You lose in disk size, since the table will be larger;

-

There are others, but I think these are the ones we should look into more.

In order to avoid performance problems, it is best to work with primary keys, do work on the indexes and maintain them.

In the company I work with we have tables with thousands of lines and working right with the indexes we make queries with great performances.

You can also search for bank tunning, but this is another story too rs

    
23.06.2016 / 21:59