clinic-database

First query

SELECT COUNT(*) FROM visits where animal_id = 4;

Solution:

Added index on the animal_id column in the visits table.

CREATE INDEX animal_id ON visits (animal_id);

Before:

Screen Shot 2021-10-28 at 10 03 50

After:

Screen Shot 2021-10-28 at 10 10 27

Second query

SELECT * FROM visits where vet_id = 2;

Solution:

Added index on both the animal_id and vet_id columns in the visits table.

CREATE INDEX vet_animal ON visits (vet_id, animal_id);

Before:

Screen Shot 2021-10-28 at 10 21 31

After:

Screen Shot 2021-10-28 at 10 28 30

Third query

SELECT * FROM owners where email = 'owner_18327@mail.com';

Solution:

Added index on email column in the owners table.

CREATE INDEX email_id ON owners (email);

Before:

Screenshot (37)

After:

Screenshot (39)