Could one be so kind to assist me with a following:
I have a query that results in two columns one being straight (columnA) from a table while other generated from subquery (columnB). If I do a sort (i.e. ORDER BY) on columnB I get much slower response then when doing the same on columnA (50+ times). Is there a way to speed up the sort on columnB in order to come close to speeds achieved when sorting columnA?
Note: Engine is Postgres
Update: Query looks similar to:
select columnA, array_to_string(array(select ... from tableB where ...), '%') as columnB
from tableA
where ...
order by columnA
Any advice is much appreciated.
Update #2: Solved it by doing sort in new query and then feeding the results to the main query (using where statement to select only partial number of rows instead of a whole set which gave me performance I needed). Thanks everybody that replied.
JOIN