So I need help to figured it out what Index(es) I need to create to improve the performance of this query:
SELECT DISTINCT F.nif, F.nomef
FROM fornecedor F, produto P
WHERE F.nif = P.forn_primario AND P.categoria = 'Fruta';
The tables fornecedor and produto are created this way:
Fornecedor
create table fornecedor (
nif char(9) not null unique,
nomef varchar(80) not null,
constraint nif_size CHECK (Length(nif)=9),
constraint pk_fornecedor primary key(nif));
Produto
create table produto (
ean char(13) not null unique,
design varchar(255) not null,
categoria varchar(80) not null,
forn_primario char(9) not null,
data date not null,
constraint ean_size CHECK (Length(ean)=13),
constraint pk_produto primary key(ean),
constraint fk_produto_categoria foreign key(categoria) references categoria(nome) ON DELETE CASCADE,
constraint fk_produto_fornecedor foreign key(forn_primario) references fornecedor(nif));
I dont know if I need to create a Multiple-Key Index like:
CREATE INDEX multiple_idx ON produto (forn_primario,categoria);
or something else???