-- my table and indexescreate table "order"( serial bigint, id bigint primary key, "accountId" bigint not null, symbol varchar(8) not null, side varchar(4) not null, px decimal(18, 9), qty decimal(18, 9), "ordRejReason" varchar, text varchar, orderingpx decimal(18, 9) as (case side when 'Buy' then 10000000 - px else px end));
create index orderbook_idx on "order"(symbol, side, orderingpx, serial);create index account_symbol_idx on "order"("accountId", symbol);
-- explain show me this query use the index orderbook_idx, and it's fast
select * from "order" where symbol = ? and side = ? ;
-- explain show me this query use the index orderbook_idx also, buy it's very slow,
-- even if the index contains the columns order by columns
select * from "order" where symbol = ? and side = ? order by orderingpx, serial;select * from "order" where symbol = ? and side = ?
ORDER BY symbol, side, orderingpx, serial