Special meaning of NL string

Поиск
Список
Период
Сортировка
Искать

Special meaning of NL string

От:
"Vellinga, Fred" <fred.vellinga@nl.verizonbusiness.com>
Дата:
Hello,
 
I wonder if there is an issue with the string 'NL'. In my application NL stands for Netherlands and is thus a country code abreviation.
 
The query
 
SELECT COUNT(*) FROM Table WHERE Field1 = 'NL' OR Field2 = 'NL'
 
does a sequence scan instead of an index scan, and is thus very slow. If I replace NL by BE (Belgium) the query does an index scan. If I replace OR by AND it also does an index scan. So apparently the string NL in the OR Where clause decides the query planner not to execute an index scan. The database encoding schema is SQL_ASCII.
 
Thanks,
Fred Vellinga
 
 

Re: Special meaning of NL string

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
"Vellinga, Fred"  writes:
> The query
> SELECT COUNT(*) FROM Table WHERE Field1 = 'NL' OR Field2 = 'NL'
> does a sequence scan instead of an index scan, and is thus very slow. If I
> replace NL by BE (Belgium) the query does an index scan.

Probably, 'NL' is a lot more common than 'BE' in your table ... the
planner does examine statistics while deciding what sort of scan to use.
		regards, tom lane

Re: Special meaning of NL string

От:
"Vellinga, Fred" <fred.vellinga@nl.verizonbusiness.com>
Дата:

Tom,

Thanks for your answer. The problem is indeed related to the statistics.
The isssue now seems to find out why the statistics are 'incorrect' every day.
My gues is the following: we run every night the command VACUUM ANALYZE. This command return wrong statistics info. Because when I run ANALYZE only on a table, everything is fine.

We are on PosgreSQL 7.4.

Groet,
Fred Vellinga

-----Original Message-----
From: Tom Lane [mailto:tgl@sss.pgh.pa.us]
Sent: 11 April 2006 04:58
To: Vellinga, Fred
Cc: 'pgsql-sql@postgresql.org'
Subject: Re: [SQL] Special meaning of NL string

"Vellinga, Fred" <fred.vellinga@nl.verizonbusiness.com> writes:
> The query
> SELECT COUNT(*) FROM Table WHERE Field1 = 'NL' OR Field2 = 'NL' does a
> sequence scan instead of an index scan, and is thus very slow. If I
> replace NL by BE (Belgium) the query does an index scan.

Probably, 'NL' is a lot more common than 'BE' in your table ... the planner does examine statistics while deciding what sort of scan to use.

                        regards, tom lane

FAQ