Subject Inappropriate optimization?
Author jebem_ti_registraciju
In pseudo code

create procedure (param integer)
for select * from table t
where (:param is null) or (t.field = :param)

The intention was to enable procedure to return all
records if a parameter is not provided. Aditional
conditions are posible. When parameter is provided
we have unindexed reads of all records in a table,
causing extreme slow execution.

Is there a way to make this possible and fast?

if () then
for *
for *

is not an option because select is big, it has three unions.