Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id B3499633404 for ; Tue, 5 Jan 2010 10:14:15 -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 36573-08 for ; Tue, 5 Jan 2010 14:14:04 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from pyxis.powervt.com.ar (unknown [190.11.152.66]) by mail.postgresql.org (Postfix) with ESMTP id ABAEA6330AC for ; Tue, 5 Jan 2010 10:14:04 -0400 (AST) Received: from pcfhevia ([186.124.123.2]) by pyxis.powervt.com.ar (IPGroup Mail Server) with ASMTP id 1OT48953; Tue, 05 Jan 2010 11:13:57 -0300 From: "Fernando Hevia" To: =?Windows-1252?Q?'Keresztury_Bal=E1zs'?= , References: <000f01ca8d87$88e71f30$9ab55d90$@hu> Subject: Re: forced sequential scan when condition has current_user Date: Tue, 5 Jan 2010 11:15:38 -0300 Organization: IP-TEL Message-ID: <2C6DE1FB86AB4DFD9B8D19853E7F5560@iptel.com.ar> MIME-Version: 1.0 Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Office Outlook 11 Thread-Index: AcqNh4f2gu1cCG5xSkGKVHZTq8YcswAicEGg X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 In-Reply-To: <000f01ca8d87$88e71f30$9ab55d90$@hu> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=3.289 tagged_above=-10 required=5 tests=BAYES_50=0.001, FH_DATE_PAST_20XX=3.188, RDNS_NONE=0.1 X-Spam-Level: *** X-Archive-Number: 201001/42 X-Sequence-Number: 36922 =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