In case you have your own slow SQL query, you can optimize it automatically here.
For the query above, the following recommendations will be helpful as part of the SQL tuning process.
You'll find 3 sections below:
CREATE INDEX data_sample_idx_microscope_id_tow_id ON data_entry_sample (microscope_id,tow_id);
SELECT
d.tow_id AS text
FROM
data_entry_tow AS d
WHERE
EXISTS (
SELECT
1
FROM
data_entry_sample AS d0
WHERE
(
d0.tow_id = d.tow_id
)
AND (
(
(
d0.microscope_id <> '0'
)
OR (
d0.microscope_id IS NULL
)
)
OR (
d0.microscope_id IS NULL
)
)
)