Re: forced sequential scan when condition has current_user

From: "Fernando Hevia" <fhevia(at)ip-tel(dot)com(dot)ar>
To: 'Keresztury Balázs' <balazs(at)gaslightmusic(dot)hu>, <pgsql-performance(at)postgresql(dot)org>
Subject: Re: forced sequential scan when condition has current_user
Date: 2010-01-05 14:15:38
Message-ID: 2C6DE1FB86AB4DFD9B8D19853E7F5560@iptel.com.ar
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

> -----Mensaje original-----
> De: Keresztury Balázs
>
> hi,
>
> just a small question: is it normal that PostgreSQL 8.4.1
> always uses sequential scanning on any table when there is a
> condition having the constant "current_user"? Of course there
> is a btree index set on that table, but the DBMS just doesn't
> want to utilize it. When I replace current_user to any
> string, the planner uses the index normally.
>
> I can demonstrate it with the following simple query:
>
> SELECT psz.kotesszam FROM projekt.projektszervezet psz WHERE
> psz.felhasznalo_id = current_user;
>

Probably you are comparing different types. Try explicitly casting
current_user to text:

SELECT psz.kotesszam FROM projekt.projektszervezet psz WHERE
psz.felhasznalo_id = current_user::text

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Andy Colson 2010-01-05 15:03:12 Re: pg_connect takes 3.0 seconds
Previous Message Brad Nicholson 2010-01-05 13:17:38 Re: DB is slow until DB is reloaded