Postgresql, the server is rather weak - 512 MB of RAM, Internet channel 10 MB. The number of rows in the table - 2.5 million
Table columns:
CREATE TABLE public.well_completions ( year smallint, name character varying(255), operator_num integer, facility_num character varying(255), facility_name character varying(255), well_name character varying(255), api_county_code character varying(255), api_seq_num character varying(255), sidetrack_num character varying(255), api_num character varying(255), formation_code character varying(255), formation character varying(255), county character varying(255), field_name character varying(255), field_code integer, qtrqtr character varying(255), sec character varying(255), twp character varying(255), range character varying(255), meridian character varying(255), dist_e_w integer, dir_e_w character varying(255), dist_n_s integer, dir_n_s character varying(255), lat numeric, "long" numeric, ground_elev numeric, utm_x integer, utm_y integer, spud_date timestamp without time zone, td_date timestamp without time zone, wbmeasdepth integer, wbtvd integer, gas_type character varying(255), test_date timestamp without time zone, well_bore_status character varying(255), status_date timestamp without time zone, first_prod_date timestamp without time zone, form_status_date timestamp without time zone, formation_status character varying(255), complete_date timestamp without time zone ) Created an index:
CREATE INDEX yearindex ON public.well_completions USING btree (year); Simplest query
SELECT * FROM well_completions WHERE year='2000'; The pgadmin3 runs in a minute. Through python:
cursor.execute(query) for row in cursor.fetchall(): I do not wait for the execution I tried:
cursor.execute(query) for row in cursor: Even longer. I put a breakpoint, so it is in a minute somewhere in 10 thousand records of all extracts. Judging by EXPLAIN - the query uses an index. Tried to change work_mem and buffered - the same speed
year='2000'toyear=2000just in case. How many records in the table foryear=2000, i.e. which showsSELECT count(*) FROM well_completions WHERE year=2000;? - MaxU