Dude you can take into account in your JOIN also the size of records of each table and make Join accordingly, for example:
TDCUPANT = 900.000 registros
FINAFIM = 300.000 registros
OUTRA_TABELA = 1.000 registros
Your join should start with the smaller tables, that is, for
OUTRA_TABELA
, then FINAFIM
and last TDCUPANT
. Why this?
Well, when the database reaches the last join table, most of the records will already be separated, filtered, taking less time inside the table with 900,000 records.
Of course in your case does not help much, but should improve the performance a little.
You can also create indexes for the fields involved in the relationship, in [i:19c2cdec39]where[/i:19c2cdec39] e no [i:19c2cdec39]order by[/i:19c2cdec39]
.
What are indexes?
Indices are, roughly speaking, like the index of a book. It is for him that the database is oriented to find the records more quickly. Every database has this feature.
To create index in Firebird for example do this:
CREATE UNIQUE INDEX NOME_DO_INDEX ON FORNECEDORES (CNPJ,FANTASIA,RAZAO)
Here, I'm creating a unique index with the name
[b:b2b8d0c71d]NOME_DO_INDEX[/b:b2b8d0c71d], na tabela [b:b2b8d0c71d]FORNECEDORES [/b:b2b8d0c71d]com os campoas [b:b2b8d0c71d]CNPJ, FANTASIA e RAZAO[/b:b2b8d0c71d]
. Because it is unique ([b:b2b8d0c71d]UNIQUE[/b:b2b8d0c71d])
I can not include a vendor with the same [b:b2b8d0c71d]CNPJ, FANTASIA e RAZAO[/b:b2b8d0c71d]
that already exists in the database.
You can create as many indexes as necessary for your database. But content is not just for this utility. Indexes help data integrity such as Checks, Constraints, and Foreign Keys. They help in sorting and etc.
source: link