Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id F099E63271E for ; Tue, 5 Jan 2010 13:38:44 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 68688-02 for ; Tue, 5 Jan 2010 17:38:34 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-fx0-f227.google.com (mail-fx0-f227.google.com [209.85.220.227]) by mail.postgresql.org (Postfix) with ESMTP id 3565B632507 for ; Tue, 5 Jan 2010 13:38:33 -0400 (AST) Received: by fxm27 with SMTP id 27so1991434fxm.3 for ; Tue, 05 Jan 2010 09:38:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:sender:from:to:cc:references :in-reply-to:subject:date:message-id:mime-version:content-type :content-transfer-encoding:x-mailer:thread-index:content-language; bh=grmbs14a2ymp5F3g6pt50Gs0nic+l48hbhcqNbWDeAc=; b=doYy7bC8Guag9pCpqsbhoKYQ0lYqrE2u5sUImvW4mw9ylQQZ8CrDbPj4L8DsLaMjzU bsDP/R1KtqbJv1OIhvl1v/D88wk0BT6/kgzqbXvwR4SUSySuiFtEhYrl56EihWKFz20k bz0J5PbXd82++0tQZ27TyWa4lj+hYdBq3fuzA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:from:to:cc:references:in-reply-to:subject:date:message-id :mime-version:content-type:content-transfer-encoding:x-mailer :thread-index:content-language; b=ky9gMXvgvlTPVidRnqqkC4BFdTMVlMpK+d5f/+rYCgPrYh0atsehUyH1sn7XT2LhfJ ipk+AKsxdE6eMM4HN4tpdXLoy6f6fp+7AzdAFM9x1AU6RM/bLmoGFiqo3ar15a5kefBi cQ7svOkKJAHcEBrTdsM6xt0aD1M1A2PffWdQc= Received: by 10.223.27.79 with SMTP id h15mr11681156fac.23.1262713112656; Tue, 05 Jan 2010 09:38:32 -0800 (PST) Received: from Stargate7 (217.64ec54.tvnetwork.hu [84.236.100.217]) by mx.google.com with ESMTPS id 9sm29072017fks.22.2010.01.05.09.38.28 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 05 Jan 2010 09:38:29 -0800 (PST) From: =?iso-8859-2?Q?Keresztury_Bal=E1zs?= To: "'Fernando Hevia'" Cc: References: <000f01ca8d87$88e71f30$9ab55d90$@hu> <2C6DE1FB86AB4DFD9B8D19853E7F5560@iptel.com.ar> In-Reply-To: <2C6DE1FB86AB4DFD9B8D19853E7F5560@iptel.com.ar> Subject: Re: forced sequential scan when condition has current_user Date: Tue, 5 Jan 2010 18:38:23 +0100 Message-ID: <000901ca8e2d$e320f1a0$a962d4e0$@hu> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-2" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: AcqNh4f2gu1cCG5xSkGKVHZTq8YcswAicEGgAAblJQA= Content-Language: hu X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=3.189 tagged_above=-10 required=5 tests=BAYES_50=0.001, FH_DATE_PAST_20XX=3.188 X-Spam-Level: *** X-Archive-Number: 201001/45 X-Sequence-Number: 36925 You are right along with the others, the seq scan was only forced = because of the varchar-text comparision.. Using the cast solves the problem. Thanks for the answers everyone! Balazs -----Original Message----- From: Fernando Hevia [mailto:fhevia@ip-tel.com.ar]=20 Sent: Tuesday, January 05, 2010 3:16 PM To: 'Keresztury Bal=E1zs'; pgsql-performance@postgresql.org Subject: RE: [PERFORM] forced sequential scan when condition has current_user =20 > -----Mensaje original----- > De: Keresztury Bal=E1zs >=20 > hi, >=20 > just a small question: is it normal that PostgreSQL 8.4.1=20 > always uses sequential scanning on any table when there is a=20 > condition having the constant "current_user"? Of course there=20 > is a btree index set on that table, but the DBMS just doesn't=20 > want to utilize it. When I replace current_user to any=20 > string, the planner uses the index normally. >=20 > I can demonstrate it with the following simple query: >=20 > SELECT psz.kotesszam FROM projekt.projektszervezet psz WHERE=20 > psz.felhasznalo_id =3D current_user; >=20 Probably you are comparing different types. Try explicitly casting current_user to text: SELECT psz.kotesszam FROM projekt.projektszervezet psz WHERE=20 psz.felhasznalo_id =3D current_user::text