Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 1597AEC32BA for ; Thu, 12 Apr 2012 19:09:41 -0300 (ADT) Received: from mail-wi0-f178.google.com ([209.85.212.178]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SISCy-0005XA-Ag for pgsql-performance@postgresql.org; Thu, 12 Apr 2012 22:09:41 +0000 Received: by wibhq7 with SMTP id hq7so2404581wib.1 for ; Thu, 12 Apr 2012 15:09:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:date:from:organization:user-agent:mime-version:to :subject:content-type:content-transfer-encoding:x-gm-message-state; bh=mT6qZflPlTM7UUMpGO+cc8SHfxp8xgzWntcuiLk1E4Q=; b=mH5FBRUo/4NNd17mSKntiVklMeZDusadsgTy6ingMxnnKjLap2KdQQNbmAybjxOLhh BePcUJzQP0q1scvLf8htadT+X47VBa87GcOhLzDBKUWbEMSh4XB4Llt4oE+bed3jSlkc ppGUyggkufSv/eZh6U1EaaqNaPmwu5wuQQEFLGVy5ITIEWWGAQu6TqIWSwxG+3p9mcYR 4W5ZX02ZbIqf7ZOVfEvk2x6G9rHg7ajUy1J6iAjNtSZq3ci6UDv1QhxPuXZjWO1PfSL/ kTvD0l32a02Ds8NEgeH8jh7lSvleYOHVUL3Okp7E5GamPqGk0eOZstjkO/+yVW+hlher bzwg== Received: by 10.180.100.2 with SMTP id eu2mr9541437wib.1.1334268566658; Thu, 12 Apr 2012 15:09:26 -0700 (PDT) Received: from [192.168.1.100] (7.167.73.86.rev.sfr.net. [86.73.167.7]) by mx.google.com with ESMTPS id l5sm329368wia.11.2012.04.12.15.09.25 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 12 Apr 2012 15:09:25 -0700 (PDT) Message-ID: <4F875293.1000100@nuxeo.com> Date: Fri, 13 Apr 2012 00:09:23 +0200 From: Benoit Delbosc Organization: Nuxeo User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.28) Gecko/20120313 Lightning/1.0b2 Thunderbird/3.1.20 MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Slow fulltext query plan Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gm-Message-State: ALoCoQmcBOHUYCnrFSv7ni0YaOzfbYcJ2U8CsAvmHfOc6r6vj5I+BM99iCq29ne3Gb4fk5ozmCUw X-Pg-Spam-Score: -2.6 (--) X-Archive-Number: 201204/94 X-Sequence-Number: 46740 Hi, I would like to understand why the following query execution don't use any fulltext indexes and takes more than 300s (using lot of temporary files): EXPLAIN ANALYZE SELECT hierarchy.id FROM hierarchy JOIN fulltext ON fulltext.id = hierarchy.id, TO_TSQUERY('whatever') query1, TO_TSQUERY('whatever') query2 WHERE (query1 @@ nx_to_tsvector(fulltext.fulltext)) OR (query2 @@ nx_to_tsvector(fulltext.fulltext_title)); The query plan is here: http://explain.depesz.com/s/YgP While if I replace the query2 by query1 in the second clause: EXPLAIN ANALYZE SELECT hierarchy.id FROM hierarchy JOIN fulltext ON fulltext.id = hierarchy.id, TO_TSQUERY('whatever') query1, TO_TSQUERY('whatever') query2 WHERE (query1 @@ nx_to_tsvector(fulltext.fulltext)) OR (query1 @@ nx_to_tsvector(fulltext.fulltext_title)); It is 5 order of magniude faster (15ms) using the gin indexes: http://explain.depesz.com/s/RLa The nx_to_tsvector is an immutable function with the following code: SELECT TO_TSVECTOR('english', SUBSTR($1, 1, 250000)) Here is the list of indexes: hierarchy: "hierarchy_pk" PRIMARY KEY, btree (id) fulltext: "fulltext_fulltext_idx" gin (nx_to_tsvector(fulltext::character varying)) fulltext: "fulltext_fulltext_title_idx" gin (nx_to_tsvector(fulltext_title::character varying)) fulltext and fulltext_title are text type. And some PostgreSQL configuration: PostgreSQL 9.1.2 on x86_64-unknown-linux-gnu shared_buffers: 4GB effective_cache_size: 10GB work_mem: 20MB Thanks for your work and enlightenment ben