postgresql - SQL subquery sort -
could 1 kind assist me following:
i have query results in 2 columns 1 being straight (columna) table while other generated subquery (columnb). if sort (i.e. order by) on columnb slower response when doing same on columna (50+ times). there way speed sort on columnb in order come close speeds achieved when sorting columna?
note: engine postgres
update: query looks similar to:
select columna, array_to_string(array(select ... tableb ...), '%') columnb tablea ... order columna
any advice appreciated.
update #2: solved doing sort in new query , feeding results main query (using statement select partial number of rows instead of whole set gave me performance needed). replied.
in query
select columna, array_to_string(array(select ... tableb ...), '%') columnb tablea ... order columna
operations on columnb can't take advantage of index. not that, sort have deal columns width of many concatenated rows.
your best bet reconsider why need sorted, because sort order of expression array_to_string(...)
arbitrary. it's arbitrary, because you're not sorting within select statement that's argument array()
.
i using array_to_string capture number of values need process later. see alternative?
a select statement capture number of values.
if need "to further process" values in sorted order, you're better off returning results of select...order statement without using array functions. way, application code can process values in order walking result set. won't have parse values out of "%" delimited string.
Comments
Post a Comment