
-- indexes speed our list up..

CREATE INDEX cohead_orderdate  ON cohead  USING btree  (cohead_orderdate);
  
CREATE INDEX itemloc_locsite  ON itemloc USING btree  (itemloc_itemsite_id, itemloc_location_id);

-- this does not exist??  - what was it supposed to do?
--CREATE INDEX itemsite_costcode_id_key   ON itemsite  USING btree  (itemsite_costcode_id );

 
CREATE INDEX evntlog_stdcost_ix  ON evntlog USING btree  (evntlog_number, evntlog_evnttime, evntlog_evnttype_id);


 
CREATE INDEX location_name_ix  ON location USING btree  (location_name);

CREATE INDEX itemlocdist_series_idx  ON itemlocdist  USING btree  (itemlocdist_series);
CREATE INDEX itemlocdist_itemlocdist_id_idx  ON itemlocdist  USING btree  (itemlocdist_itemlocdist_id);
CREATE INDEX itemlocdist_source_type_idx  ON itemlocdist  USING btree  (itemlocdist_source_type);
CREATE INDEX itemlocdist_itemsite_id_idx  ON itemlocdist  USING btree  (itemlocdist_itemsite_id);
CREATE INDEX itemlocpost_itemlocseries_idx  ON itemlocpost  USING btree  (itemlocpost_itemlocseries);


CREATE INDEX itemloc_ls_idx  ON itemloc   USING btree  (itemloc_ls_id);
CREATE INDEX itemloc_expiration_idx  ON itemloc   USING btree  (itemloc_expiration);
CREATE INDEX itemloc_warrpurc_idx  ON itemloc   USING btree  (itemloc_warrpurc);
                   
CREATE INDEX itemsite_controlmethod_idx     ON itemsite   USING btree  (itemsite_controlmethod);
CREATE INDEX item_inv_uom_idx ON item USING btree  (item_inv_uom_id);
-- post invoice / invoiceitem view speed?

--CREATE INDEX invcitem_coitem_idx  ON invcitem USING btree  (invcitem_coitem_id);
 
CREATE INDEX  shipitem_invcitem_idx  ON shipitem USING btree  (shipitem_invcitem_id);
CREATE INDEX invcitem_coitem_idx  ON invcitem USING btree  (invcitem_coitem_id);


-- from 4.0?
DROP INDEX IF EXISTS invcitemtax_taxhist_parent_id_idx;
CREATE INDEX invcitemtax_taxhist_parent_id_idx ON invcitemtax (taxhist_parent_id);


CREATE INDEX item_type_ix  ON item  USING btree  (item_type);

CREATE INDEX invchead_cust_id_idx  ON invchead  USING btree  (invchead_cust_id);


CREATE INDEX shiphead_order_type_idx  ON shiphead USING btree  (shiphead_order_type);
CREATE INDEX cust_partialship_backorder_idx  ON custinfo USING btree  (cust_partialship, cust_backorder);
CREATE INDEX coitem_subnumber_warranty_qtyshipped_idx  ON coitem USING btree  (coitem_subnumber, coitem_warranty, coitem_qtyshipped);
CREATE INDEX item_type_idx  ON item USING btree  (item_type);
CREATE INDEX itemsite_controlmethod_costmethod_freeze_idx  ON itemsite USING btree  (itemsite_controlmethod, itemsite_costmethod, itemsite_freeze);
CREATE INDEX salesaccnt_custtype_prodcat_idx  ON salesaccnt USING btree  (salesaccnt_custtype_id, salesaccnt_prodcat, salesaccnt_custtype);
CREATE INDEX prodcat_code_idx  ON prodcat USING btree  (prodcat_code);
CREATE INDEX custtype_code_idx  ON custtype USING btree  (custtype_code);
CREATE INDEX period_start_end_idx  ON period USING btree  (period_start, period_end);
CREATE INDEX yearperiod_start_end_idx  ON yearperiod USING btree  (yearperiod_start, yearperiod_end);
CREATE INDEX accnt_type_idx  ON accnt USING btree  (accnt_type);
CREATE INDEX itemloc_qty_expiration_warrpurc_ls_id_idx  ON itemloc USING btree  (itemloc_qty, itemloc_ls_id, itemloc_expiration, itemloc_warrpurc);
CREATE INDEX metric_value_idx  ON metric USING btree  (metric_value);
CREATE INDEX invhist_posted_idx  ON invhist USING btree  (invhist_posted);
CREATE INDEX invbal_period_id_idx  ON invbal USING btree  (invbal_period_id);
CREATE INDEX usrgrp_username_idx  ON usrgrp USING btree  (usrgrp_username);
CREATE INDEX shipitem_invoiced_idx  ON shipitem USING btree  (shipitem_invoiced);
CREATE INDEX aropenalloc_doctype  ON aropenalloc USING btree  (aropenalloc_doctype);
CREATE INDEX invchead_posted_idx  ON invchead USING btree  (invchead_posted);
CREATE INDEX orderseq_name_idx  ON orderseq USING btree  (orderseq_name);
CREATE INDEX recv_posted  ON recv USING btree  (recv_posted);



--- used to optimize last purchase price lookup


CREATE INDEX  poitem_line_date  on poitem USING btree ( poitem_duedate, poitem_linenumber, poitem_pohead_id, poitem_itemsite_id);

 
 CREATE INDEX  checkhead_checkdate_ix  on checkhead USING btree ( checkhead_checkdate);
CREATE INDEX  checkhead_voided_ix on checkhead USING btree ( checkhead_void, checkhead_voided);

CREATE INDEX checkhead_recip_type_ix on checkhead USING btree ( checkhead_recip_type);
CREATE INDEX checkhead_journalnumber_ix on checkhead USING btree (               checkhead_journalnumber);

CREATE INDEX apapply_journalnumber_ix on apapply USING btree (               apapply_journalnumber);
CREATE INDEX apapply_checkhead_id_ix on apapply USING btree (               apapply_checkhead_id);

CREATE INDEX apapply_target_apopen_id_ix on apapply USING btree (               apapply_target_apopen_id);
CREATE INDEX apapply_source_apopen_id_ix on apapply USING btree (               apapply_source_apopen_id);

CREATE INDEX apopen_closedate_ix on apopen USING btree (               apopen_closedate);
CREATE INDEX apopen_distdate_ix on apopen USING btree (               apopen_distdate);

CREATE INDEX apopen_discount_ix on apopen USING btree (               apopen_discount);
CREATE INDEX apopen_notes_ix on apopen USING btree (               apopen_notes);