I have a 12million row table, so not enormous, but I want to optimize it for reads as much as possible.
for example currently running
SELECT *
FROM hp.historicalposition
WHERE instrumentid = 1167 AND fundid = 'XXX'
ORDER BY date;
returns 4200 rows and is taking about 4 seconds the first time it is run and 1 second the second time.
What indices might help and and are there any other suggestions?
CREATE TABLE hp.historicalposition
(
date date NOT NULL,
fundid character(3) NOT NULL,
instrumentid integer NOT NULL,
quantityt0 double precision,
quantity double precision,
valuation character varying,
fxid character varying,
localt0 double precision,
localt double precision,
CONSTRAINT attrib_fund_fk FOREIGN KEY (fundid)
REFERENCES funds (fundid) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT attrib_instr_fk FOREIGN KEY (instrumentid)
REFERENCES instruments (instrumentid) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
dateis a bad name for a column (it is a typename) 3) do you have valid statistics on your table ? - joopinstrumentidappears twice in the create command. - Clodoaldo Neto