Re: Bad performance of SELECT ... where id IN (...)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Sep 27, 2009 at 1:03 AM, Tom Lane <tgl@xxxxxxxxxxxxx> wrote:
> Xia Qingran <qingran.xia@xxxxxxxxx> writes:
>> I have a big performance problem in my SQL select query:
>> select * from event where user_id in
>> (500,499,498, ... ,1,0);
>> The above SELECT always spends 1200ms.
>
> Your EXPLAIN ANALYZE shows that the actual runtime is only about 240ms.
> So either the planning time is about 1000ms, or transmitting and
> displaying the 134K rows produced by the query takes that long, or some
> combination of the two.  I wouldn't be too surprised if it's the data
> display that's slow; but if it's the planning time that you're unhappy
> about, updating to a more recent PG release might possibly help.  What
> version is this anyway?
>
>                        regards, tom lane

Oh, It is a problem.

Forgot to talk about my platform. I am running PostgreSQL 8.4.0 on
FreeBSD 7.2-amd64 box, which has dual Xeon 5410 CPUs, 8GB memory and 2
SATA disks.

And my postgresql.conf is listed as follow:
---------------------------------------------------------------------------------------

listen_addresses = '*'		# what IP address(es) to listen on;
port = 5432				# (change requires restart)
max_connections = 88			# (change requires restart)
superuser_reserved_connections = 3
ssl = off				# (change requires restart)
tcp_keepalives_idle = 0		# TCP_KEEPIDLE, in seconds;
tcp_keepalives_interval = 0		# TCP_KEEPINTVL, in seconds;
tcp_keepalives_count = 0		# TCP_KEEPCNT;
shared_buffers = 2048MB			# min 128kB or max_connections*16kB
temp_buffers = 32MB			# min 800kB
max_prepared_transactions = 150		# can be 0 or more, 0 to shutdown the
prepared transactions.
work_mem = 8MB				# min 64kB
maintenance_work_mem = 1024MB		# min 1MB
max_stack_depth = 8MB			# min 100kB
max_files_per_process = 16384		# min 25
vacuum_cost_delay = 100			# 0-1000 milliseconds
vacuum_cost_page_hit = 1		# 0-10000 credits
vacuum_cost_page_miss = 10		# 0-10000 credits
vacuum_cost_page_dirty = 20		# 0-10000 credits
vacuum_cost_limit = 500		# 1-10000 credits
bgwriter_delay = 500ms			# 10-10000ms between rounds
bgwriter_lru_maxpages = 100		# 0-1000 max buffers written/round
bgwriter_lru_multiplier = 2.0		# 0-10.0 multipler on buffers scanned/round
fsync = off				# turns forced synchronization on or off
synchronous_commit = off		# immediate fsync at commit
wal_sync_method = fsync		# the default is the first option
full_page_writes = off			# recover from partial page writes
wal_buffers = 2MB			# min 32kB
wal_writer_delay = 200ms		# 1-10000 milliseconds
commit_delay = 50			# range 0-100000, in microseconds
commit_siblings = 5			# range 1-1000
checkpoint_segments = 32		# in logfile segments, min 1, 16MB each
checkpoint_timeout = 6min		# range 30s-1h
checkpoint_completion_target = 0.5	# checkpoint target duration, 0.0 - 1.0
checkpoint_warning = 30s		# 0 is off
enable_bitmapscan = on
enable_hashagg = on
enable_hashjoin = on
enable_indexscan = on
enable_mergejoin = on
enable_nestloop = on
enable_seqscan = on
enable_sort = on
enable_tidscan = on
seq_page_cost = 1.8			# measured on an arbitrary scale
random_page_cost = 2			# same scale as above
cpu_tuple_cost = 0.15			# same scale as above
cpu_index_tuple_cost = 0.07		# same scale as above
cpu_operator_cost = 0.03		# same scale as above
effective_cache_size = 3072MB
geqo = on
geqo_threshold = 20
geqo_effort =  7         		# range 1-10
geqo_pool_size = 0			# selects default based on effort
geqo_generations = 0			# selects default based on effort
geqo_selection_bias = 2.0		# range 1.5-2.0
default_statistics_target = 500		# range 1-1000
constraint_exclusion = partition
from_collapse_limit = 20
join_collapse_limit = 20		# 1 disables collapsing of explicit
log_destination = 'syslog'
syslog_facility = 'LOCAL2'
syslog_ident = 'postgres'
client_min_messages = notice		# values in order of decreasing detail:
log_min_messages = error		# values in order of decreasing detail:
log_error_verbosity = terse		# terse, default, or verbose messages
log_min_error_statement = panic	# values in order of decreasing detail:
log_min_duration_statement = -1	# -1 is disabled, 0 logs all statements
silent_mode = on
debug_print_parse = off
debug_print_rewritten = off
debug_print_plan = off
debug_pretty_print = off
log_checkpoints = off
log_connections = off
log_disconnections = off
log_duration = on
log_hostname = off
log_line_prefix = ''			# special values:
log_lock_waits = off			# log lock waits >= deadlock_timeout
log_statement = 'none'			# none, ddl, mod, all
log_temp_files = -1			# log temporary files equal or larger
track_activities = on
track_counts = on
update_process_title = off
log_parser_stats = off
log_planner_stats = off
log_executor_stats = off
log_statement_stats = off
autovacuum = on			# Enable autovacuum subprocess?  'on'
log_autovacuum_min_duration = 10	# -1 disables, 0 logs all actions and
autovacuum_max_workers = 3		# max number of autovacuum subprocesses
autovacuum_naptime = 10min		# time between autovacuum runs
autovacuum_vacuum_threshold = 100	# min number of row updates before
autovacuum_analyze_threshold = 50	# min number of row updates before
autovacuum_vacuum_scale_factor = 0.2	# fraction of table size before vacuum
autovacuum_analyze_scale_factor = 0.1	# fraction of table size before analyze
autovacuum_freeze_max_age = 200000000	# maximum XID age before forced vacuum
autovacuum_vacuum_cost_delay = 30	# default vacuum cost delay for
autovacuum_vacuum_cost_limit = 200	# default vacuum cost limit for
datestyle = 'iso, mdy'
client_encoding = utf-8		# actually, defaults to database
lc_messages = 'C'			# locale for system error message
lc_monetary = 'C'			# locale for monetary formatting
lc_numeric = 'C'			# locale for number formatting
lc_time = 'C'				# locale for time formatting
default_text_search_config = 'pg_catalog.english'
deadlock_timeout = 60s
max_locks_per_transaction = 32		# min 10
regex_flavor = basic		# advanced, extended, or basic
---------------------------------------------------------------------------------------

Thanks a lot.
-- 
夏清然
Xia Qingran
qingran.xia@xxxxxxxxx
Sent from Beijing, 11, China
Joan Crawford  - "I, Joan Crawford, I believe in the dollar.
Everything I earn, I spend." -
http://www.brainyquote.com/quotes/authors/j/joan_crawford.html

-- 
Sent via pgsql-performance mailing list (pgsql-performance@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance


[Postgresql General]     [Postgresql PHP]     [PHP Users]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Yosemite]

  Powered by Linux