Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 2B9939FBE16 for ; Tue, 3 Jul 2007 16:23:49 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 49598-04 for ; Tue, 3 Jul 2007 16:23:45 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from kuber.nabble.com (kuber.nabble.com [216.139.236.158]) by postgresql.org (Postfix) with ESMTP id 630089FBDB8 for ; Tue, 3 Jul 2007 16:23:45 -0300 (ADT) Received: from isper.nabble.com ([192.168.236.156]) by kuber.nabble.com with esmtp (Exim 4.63) (envelope-from ) id 1I5nyS-0006zS-Ia for pgsql-performance@postgresql.org; Tue, 03 Jul 2007 12:23:44 -0700 Message-ID: <11418991.post@talk.nabble.com> Date: Tue, 3 Jul 2007 12:23:44 -0700 (PDT) From: smiley2211 To: pgsql-performance@postgresql.org Subject: Re: Query is taking 5 HOURS to Complete on 8.1 version In-Reply-To: <11416966.post@talk.nabble.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Nabble-From: smiley2211@yahoo.com References: <11416966.post@talk.nabble.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=1.372 tagged_above=0 required=5 tests=AWL=-0.292, BAYES_40=-0.185, FORGED_YAHOO_RCVD=1.849 X-Spam-Level: * X-Archive-Number: 200707/21 X-Sequence-Number: 25705 Here are the VIEWS in question: query = (explain analyze select id from people_consent LIMIT 1;) CREATE OR REPLACE VIEW temp_consent AS SELECT p.id, max(en.enrolled_at) AS daterecorded, a.answer FROM people p, enrollments en, encounters ec, encounters_questions_answers eqa, questions_answers qa, answers a WHERE (qa.question_tag::text = 'consentTransfer'::text OR qa.question_tag::text = 'shareWithEval'::text) AND eqa.question_answer_id = qa.id AND ec.id = eqa.encounter_id AND ec.enrollment_id = en.id AND p.id = en.person_id AND qa.answer_id = a.id GROUP BY p.id, a.answer UNION SELECT p.id, max(c.entered_at) AS daterecorded, a.answer FROM people p, ctccalls c, ctccalls_questions_answers cqa, questions_answers qa, answers a WHERE (qa.question_tag::text = 'consentTransfer'::text OR qa.question_tag::text = 'shareWithEval'::text) AND cqa.question_answer_id = qa.id AND c.id = cqa.call_id AND p.id = c.person_id AND qa.answer_id = a.id GROUP BY p.id, a.answer; CREATE OR REPLACE VIEW temp_consent2 AS SELECT DISTINCT temp_consent.id, temp_consent.daterecorded FROM temp_consent WHERE temp_consent.answer::text = 'Yes'::text ORDER BY temp_consent.daterecorded DESC, temp_consent.id; CREATE OR REPLACE VIEW people_consent AS SELECT people.id, people.firstname, people.lastname, people.homephone, people.workphone, people.altphone, people.eligibilityzipcode, people.address1, people.address2, people.city, people.state, people.zipcode1, people.zipcode2, people.email, people.dayofbirth, people.monthofbirth, people.yearofbirth, people.ethnic_detail, people.external_id, people.highestlevelofeducation_id, people.ethnicgroup_id, people.ethnicotherrace, people.entered_at, people.entered_by, people.besttimetoreach_id, people.language_id, people.otherlanguage, people.gender_id, people.hispaniclatino_id, people.canscheduleapt_id, people.mayweleaveamessage_id, people.ethnictribe, people.ethnicasian, people.ethnicislander FROM people WHERE (people.id IN ( SELECT temp_consent2.id FROM temp_consent2)) UNION SELECT people.id, '***MASKED***' AS firstname, '***MASKED***' AS lastname, '***MASKED***' AS homephone, '***MASKED***' AS workphone, '***MASKED***' AS altphone, '***MASKED***' AS eligibilityzipcode, '***MASKED***' AS address1, '***MASKED***' AS address2, '***MASKED***' AS city, '***MASKED***' AS state, '***MASKED***' AS zipcode1, '***MASKED***' AS zipcode2, people.email, '***MASKED***' AS dayofbirth, '***MASKED***' AS monthofbirth, '***MASKED***' AS yearofbirth, people.ethnic_detail, people.external_id, people.highestlevelofeducation_id, people.ethnicgroup_id, people.ethnicotherrace, people.entered_at, people.entered_by, people.besttimetoreach_id, people.language_id, people.otherlanguage, people.gender_id, people.hispaniclatino_id, people.canscheduleapt_id, people.mayweleaveamessage_id, people.ethnictribe, people.ethnicasian, people.ethnicislander FROM people WHERE NOT (people.id IN ( SELECT temp_consent2.id FROM temp_consent2)); -- View this message in context: http://www.nabble.com/Query-is-taking-5-HOURS-to-Complete-on-8.1-version-tf4019778.html#a11418991 Sent from the PostgreSQL - performance mailing list archive at Nabble.com.