Received: from ant.utdt ([200.41.62.131]) by hub.org (8.9.3/8.9.3) with ESMTP id PAA34975 for ; Thu, 18 May 2000 15:44:25 -0400 (EDT) (envelope-from mig@utdt.edu) From: mig@utdt.edu Received: (from mig@localhost) by ant.utdt (8.8.7/8.8.7) id QAA04835; Thu, 18 May 2000 16:38:29 -0300 Date: Thu, 18 May 2000 16:38:29 -0300 Message-Id: <200005181938.QAA04835@ant.utdt> X-Authentication-Warning: ant.utdt: mig set sender to mig@utdt.edu using -f To: klcollins@wsicorp.com CC: pgsql-sql@postgresql.org In-reply-to: <3924405E.15014E6B@wsicorp.com> (message from Kate Collins on Thu, 18 May 2000 15:11:27 -0400) Subject: Re: SQL command speed References: <3924405E.15014E6B@wsicorp.com> X-Archive-Number: 200005/65 I believe the PostgreSQL optimizer is fooled by many ORs and switches to sequential scans: it cannot estimate properly the quantity of results that will be returned. Try it in one go, as $sql = "SELECT notam_id, TO_CHAR(full_issue_date, 'DD-MON-YYYY HH24:MI') FROM notam_details WHERE item_a IN ('EGKB','EGDM','EGHH','EGGD','EGVN','EGFF', 'EGDC','EGTC','EGDR','EGTE','EGLF','EGTG', 'EGBJ','EGLC','EGKK','EGLL','EGSS','EGGW', 'EGMD','EGDL','EGUM','EGHD','EGHE','EGKA', 'EGHI','EGMC','EGDG','EGFH','EGDY','EGJA', 'EGJB','EGJJ')"; The optimizer should (I think) like this better and use the indices, without requiring that you iterate the queries from the frontend. As I am trying to learn these things too, I will appreciate knowing about the result of your tests: please keep me posted. Thanks Miguel Sofer