diff --git "a/pgsql-performance.200409" "b/pgsql-performance.200409" new file mode 100644--- /dev/null +++ "b/pgsql-performance.200409" @@ -0,0 +1,35095 @@ +From pgsql-performance-owner@postgresql.org Tue Aug 31 21:16:48 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 624515E3F15 + for ; + Tue, 31 Aug 2004 21:16:47 -0300 (ADT) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 21408-06 + for ; + Wed, 1 Sep 2004 00:16:43 +0000 (GMT) +Received: from silmaril.syscor.priv (h24-108-208-253.sbm.shawcable.net + [24.108.208.253]) + by svr1.postgresql.org (Postfix) with ESMTP id AF0755E470A + for ; + Tue, 31 Aug 2004 21:16:40 -0300 (ADT) +Received: from syscor.com (strider.syscor.priv [192.168.1.3]) + by silmaril.syscor.priv (8.12.8/8.12.8) with ESMTP id i810GpYe021386 + for ; Tue, 31 Aug 2004 17:16:51 -0700 +Message-ID: <41351546.7090600@syscor.com> +Date: Tue, 31 Aug 2004 17:18:14 -0700 +From: Ron St-Pierre +User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; + rv:1.4) Gecko/20030624 +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: pgsql-performance@postgresql.org +Subject: Re: Table UPDATE is too slow +References: <4134BF36.3000504@syscor.com> +In-Reply-To: <4134BF36.3000504@syscor.com> +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200408/492 +X-Sequence-Number: 8128 + +Thanks for everyone's comments (Thomas, Steinar, Frank, Matt, William). +Right now I'm bench-marking the time it takes for each step +in the end of day update process and then I am going to test a few things: +- dropping most indexes, and check the full processing time and see if +there is any noticeable performance degradation on the web-end +- wrapping the updates in a transaction, and check the timing +- combining the two +- reviewing my shared_buffers and sort_memory settings + +Thanks +Ron + + +From pgsql-performance-owner@postgresql.org Wed Sep 1 02:32:18 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id E14CE5E4714 + for ; + Wed, 1 Sep 2004 02:32:15 -0300 (ADT) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 02919-10 + for ; + Wed, 1 Sep 2004 05:32:09 +0000 (GMT) +Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) + by svr1.postgresql.org (Postfix) with ESMTP id 37AFC5E46F8 + for ; + Wed, 1 Sep 2004 02:32:09 -0300 (ADT) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i815W9n7001615; + Wed, 1 Sep 2004 01:32:09 -0400 (EDT) +To: Ron St-Pierre +Cc: pgsql-performance@postgresql.org +Subject: Re: Table UPDATE is too slow +In-reply-to: <4134BF36.3000504@syscor.com> +References: <4134BF36.3000504@syscor.com> +Comments: In-reply-to Ron St-Pierre + message dated "Tue, 31 Aug 2004 11:11:02 -0700" +Date: Wed, 01 Sep 2004 01:32:08 -0400 +Message-ID: <1613.1094016728@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/1 +X-Sequence-Number: 8129 + +Ron St-Pierre writes: +> Does anyone have some idea on how we can increase speed, either by +> changing the updates, designing the database +> differently, etc, etc? This is currently a big problem for us. + +> Other notables: +> The UPDATE is run from a within a function: FOR rec IN SELECT ...LOOP +> RETURN NEXT rec; UPDATE dataTable..... + +One point that I don't think was made before: by doing a collection of +updates in this serial one-at-a-time fashion, you are precluding any +possibility of query optimization over the collection of updates. It +might win to dump the update data into a temp table and do a single +UPDATE command joining to the temp table. Or not --- quite possibly not +--- but I think it's something to think about. + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Wed Sep 1 03:46:02 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 16C645E46E9 + for ; + Wed, 1 Sep 2004 03:46:00 -0300 (ADT) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 24888-02 + for ; + Wed, 1 Sep 2004 06:45:55 +0000 (GMT) +Received: from mail.census.gov.ph (mail.census.gov.ph [203.172.28.120]) + by svr1.postgresql.org (Postfix) with ESMTP id 195FD5E46C3 + for ; + Wed, 1 Sep 2004 03:44:31 -0300 (ADT) +Received: from notnot (gateway.census.gov.ph [203.172.28.97]) + by mail.census.gov.ph (8.12.8/8.12.8) with ESMTP id i816fDkJ025384 + for ; Wed, 1 Sep 2004 14:41:14 +0800 +Message-Id: <200409010641.i816fDkJ025384@mail.census.gov.ph> +From: "Michael Ryan S. Puncia" +To: +Subject: Changing the column length +Date: Wed, 1 Sep 2004 14:42:00 +0800 +MIME-Version: 1.0 +Content-Type: multipart/alternative; + boundary="----=_NextPart_000_0000_01C49031.D7EC2070" +X-Mailer: Microsoft Office Outlook, Build 11.0.5510 +Thread-Index: AcSP7sh4P972DUg0Q32hVoK8vZQ1RQ== +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 +X-MailScanner: Found to be clean by NSO mail server. +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.1 tagged_above=0.0 required=5.0 tests=HTML_70_80, + HTML_MESSAGE +X-Spam-Level: +X-Archive-Number: 200409/2 +X-Sequence-Number: 8130 + +This is a multi-part message in MIME format. + +------=_NextPart_000_0000_01C49031.D7EC2070 +Content-Type: text/plain; + charset="us-ascii" +Content-Transfer-Encoding: 7bit + +Hi , + + I am sorry that my question is out of line with this +group(performance) but I need + +an urgent help :-( .pls .. I need to know how to change the length of the +column. + + + +Thanks and hoping that u will not ignore my question + + + + +------=_NextPart_000_0000_01C49031.D7EC2070 +Content-Type: text/html; + charset="us-ascii" +Content-Transfer-Encoding: quoted-printable + + + + + + + + + + + + +
+ +

Hi ,

+ +

         &n= +bsp;  I am sorry that my question is out of line with +this group(performance) but I need

+ +

an urgent help L …pls= + .. I need +to know how  to change the length of the column.

+ +

 

+ +

Thanks and hoping that u will not ignore my question

+ +

 

+ +
+ + + + + +------=_NextPart_000_0000_01C49031.D7EC2070-- + + +From pgsql-performance-owner@postgresql.org Wed Sep 1 04:53:05 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id CF7775E46F8 + for ; + Wed, 1 Sep 2004 04:53:04 -0300 (ADT) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 47983-02 + for ; + Wed, 1 Sep 2004 07:52:57 +0000 (GMT) +Received: from smtp-bal.opennet.it (noder32-48.opennet.it [212.110.32.48]) + by svr1.postgresql.org (Postfix) with SMTP id 4D10B5E46CE + for ; + Wed, 1 Sep 2004 04:52:53 -0300 (ADT) +Received: (qmail 13818 invoked from network); 1 Sep 2004 07:51:52 -0000 +Received: from unknown (HELO comai04) (212.110.56.34) + by 0 with SMTP; 1 Sep 2004 07:51:52 -0000 +Message-ID: <002c01c48ff9$312280f0$0501a8c0@comai04> +From: "Stefano Bonnin" +To: +Subject: Fw: Query performance issue with 8.0.0beta1 +Date: Wed, 1 Sep 2004 09:56:30 +0200 +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 6.00.2800.1437 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/3 +X-Sequence-Number: 8131 + + +----- Original Message ----- +From: "Stefano Bonnin" +To: "Josh Berkus" +Sent: Monday, August 30, 2004 4:13 PM +Subject: Re: [PERFORM] Query performance issue with 8.0.0beta1 + + +> This is my postgres.conf, I have changed only the work_mem and +> shared_buffers parameters. +> +> >DID you +> > configure it for the 8.0 database? +> +> What does it mean? Is in 8.0 some important NEW configation parameter ? +> +> # pgdata = '/usr/local/pgsql/data' # use data in another +> directory +> # hba_conf = '/etc/pgsql/pg_hba.conf' # use hba info in another +> directory +> # ident_conf = '/etc/pgsql/pg_ident.conf' # use ident info in +another +> directory +> # external_pidfile= '/var/run/postgresql.pid' # write an extra pid file +> #listen_addresses = 'localhost' # what IP interface(s) to listen on; +> # defaults to localhost, '*' = any +> #port = 5432 +> max_connections = 100 +> #superuser_reserved_connections = 2 +> #unix_socket_directory = '' +> #unix_socket_group = '' +> #unix_socket_permissions = 0777 # octal +> #rendezvous_name = '' # defaults to the computer name +> #authentication_timeout = 60 # 1-600, in seconds +> #ssl = false +> #password_encryption = true +> #krb_server_keyfile = '' +> #db_user_namespace = false +> +> shared_buffers = 2048 # min 16, at least max_connections*2, 8KB +> each +> work_mem = 2048 # min 64, size in KB +> #maintenance_work_mem = 16384 # min 1024, size in KB +> #max_stack_depth = 2048 # min 100, size in KB +> +> #max_fsm_pages = 20000 # min max_fsm_relations*16, 6 bytes each +> #max_fsm_relations = 1000 # min 100, ~50 bytes each +> +> #max_files_per_process = 1000 # min 25 +> #preload_libraries = '' +> +> #vacuum_cost_delay = 0 # 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 = 200 # 0-10000 credits +> +> #bgwriter_delay = 200 # 10-5000 milliseconds +> #bgwriter_percent = 1 # 1-100% of dirty buffers +> #bgwriter_maxpages = 100 # 1-1000 buffers max at once +> +> #fsync = true # turns forced synchronization on or off +> #wal_sync_method = fsync # the default varies across platforms: +> # fsync, fdatasync, open_sync, or +> open_datasync +> #wal_buffers = 8 # min 4, 8KB each +> #commit_delay = 0 # range 0-100000, in microseconds +> #commit_siblings = 5 # range 1-100 +> #checkpoint_segments = 3 # in logfile segments, min 1, 16MB each +> #checkpoint_timeout = 300 # range 30-3600, in seconds +> #checkpoint_warning = 30 # 0 is off, in seconds +> +> #archive_command = '' # command to use to archive a logfile +> segment +> +> #enable_hashagg = true +> #enable_hashjoin = true +> #enable_indexscan = true +> #enable_mergejoin = true +> #enable_nestloop = true +> #enable_seqscan = true +> #enable_sort = true +> #enable_tidscan = true +> +> #effective_cache_size = 1000 # typically 8KB each +> #random_page_cost = 4 # units are one sequential page fetch cost +> #cpu_tuple_cost = 0.01 # (same) +> #cpu_index_tuple_cost = 0.001 # (same) +> #cpu_operator_cost = 0.0025 # (same) +> +> #geqo = true +> #geqo_threshold = 12 +> #geqo_effort = 5 # 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 = 20 # range 1-1000 +> #from_collapse_limit = 8 +> #join_collapse_limit = 8 # 1 disables collapsing of explicit JOINs +> +> #log_destination = 'stderr' # Valid values are combinations of stderr, +> # syslog and eventlog, depending on +> # platform. +> +> # This is relevant when logging to stderr: +> #redirect_stderr = false # Enable capturing of stderr into log files. +> # These are only relevant if redirect_stderr is true: +> #log_directory = 'pg_log' # Directory where logfiles are written. +> # May be specified absolute or relative to +> PGDATA +> #log_filename_prefix = 'postgresql_' # Prefix for logfile names. +> #log_rotation_age = 1440 # Automatic rotation of logfiles will happen +> after +> # so many minutes. 0 to disable. +> #log_rotation_size = 10240 # Automatic rotation of logfiles will happen +> after +> # so many kilobytes of log output. 0 to +> disable. +> +> # These are relevant when logging to syslog: +> #syslog_facility = 'LOCAL0' +> #syslog_ident = 'postgres' +> +> +> # - When to Log - +> +> #client_min_messages = notice # Values, in order of decreasing detail: +> # debug5, debug4, debug3, debug2, +debug1, +> # log, notice, warning, error +> +> #log_min_messages = notice # Values, in order of decreasing detail: +> # debug5, debug4, debug3, debug2, +debug1, +> # info, notice, warning, error, log, +> fatal, +> # panic +> +> #log_error_verbosity = default # terse, default, or verbose messages +> +> #log_min_error_statement = panic # Values in order of increasing severity: +> # debug5, debug4, debug3, debug2, +debug1, +> # info, notice, warning, error, +> panic(off) +> +> #log_min_duration_statement = -1 # -1 is disabled, in milliseconds. +> +> #silent_mode = false # DO NOT USE without syslog or +> redirect_stderr +> +> # - What to Log - +> +> #debug_print_parse = false +> #debug_print_rewritten = false +> #debug_print_plan = false +> #debug_pretty_print = false +> #log_connections = false +> #log_disconnections = false +> #log_duration = false +> #log_line_prefix = '%t %u %d ' # e.g. '<%u%%%d> ' +> # %u=user name %d=database name +> # %r=remote host and port +> # %p=PID %t=timestamp %i=command tag +> # %c=session id %l=session line number +> # %s=session start timestamp +> # %x=stop here in non-session processes +> # %%='%' +> log_statement = 'all' # none, mod, ddl, all +> #log_hostname = false +> +> +> +#--------------------------------------------------------------------------- +> # RUNTIME STATISTICS +> +#--------------------------------------------------------------------------- +> +> # - Statistics Monitoring - +> +> #log_parser_stats = false +> #log_planner_stats = false +> #log_executor_stats = false +> #log_statement_stats = false +> +> # - Query/Index Statistics Collector - +> +> #stats_start_collector = true +> #stats_command_string = false +> #stats_block_level = false +> #stats_row_level = false +> #stats_reset_on_server_start = true +> +#--------------------------------------------------------------------------- +> # CLIENT CONNECTION DEFAULTS +> +#--------------------------------------------------------------------------- +> +> # - Statement Behavior - +> +> #search_path = '$user,public' # schema names +> #check_function_bodies = true +> #default_transaction_isolation = 'read committed' +> #default_transaction_read_only = false +> #statement_timeout = 0 # 0 is disabled, in milliseconds +> +> # - Locale and Formatting - +> +> #datestyle = 'iso, mdy' +> #timezone = unknown # actually, defaults to TZ environment +> setting +> #australian_timezones = false +> #extra_float_digits = 0 # min -15, max 2 +> #client_encoding = sql_ascii # actually, defaults to database encoding +> +> # These settings are initialized by initdb -- they might be changed +> lc_messages = 'it_IT.UTF-8' # locale for system error message +> strings +> lc_monetary = 'it_IT.UTF-8' # locale for monetary formatting +> lc_numeric = 'it_IT.UTF-8' # locale for number formatting +> lc_time = 'it_IT.UTF-8' # locale for time formatting +> +> # - Other Defaults - +> +> #explain_pretty_print = true +> #dynamic_library_path = '$libdir' +> +> +> +#--------------------------------------------------------------------------- +> # LOCK MANAGEMENT +> +#--------------------------------------------------------------------------- +> +> #deadlock_timeout = 1000 # in milliseconds +> #max_locks_per_transaction = 64 # min 10, ~260*max_connections bytes each +> +> +> +#--------------------------------------------------------------------------- +> # VERSION/PLATFORM COMPATIBILITY +> +#--------------------------------------------------------------------------- +> +> # - Previous Postgres Versions - +> #add_missing_from = true +> #regex_flavor = advanced # advanced, extended, or basic +> #sql_inheritance = true +> #default_with_oids = true +> +> # - Other Platforms & Clients - +> +> #transform_null_equals = false +> +> +> +> ************************ +> Thanks +> +> PS. I'm sorry for the late answer but I was not in office. +> +> ----- Original Message ----- +> From: "Josh Berkus" +> To: "Stefano Bonnin" ; +> +> Sent: Friday, August 27, 2004 7:14 PM +> Subject: Re: [PERFORM] Query performance issue with 8.0.0beta1 +> +> +> > Stefano, +> > +> > > Hi, I have just installed 8.0.0beta1 and I noticed that some query are +> > > slower than 7.4.2 queries. +> > +> > Seems unlikely. How have you configured postgresql.conf? DID you +> > configure it for the 8.0 database? +> > +> > -- +> > Josh Berkus +> > Aglio Database Solutions +> > San Francisco +> > +> + + +From pgsql-odbc-owner@postgresql.org Wed Sep 1 05:33:13 2004 +X-Original-To: pgsql-odbc-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id C288B5E46EE + for ; + Wed, 1 Sep 2004 05:33:10 -0300 (ADT) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 62113-04 + for ; + Wed, 1 Sep 2004 08:33:06 +0000 (GMT) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by svr1.postgresql.org (Postfix) with ESMTP id C1A595E46F9 + for ; Wed, 1 Sep 2004 05:33:05 -0300 (ADT) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by news.hub.org (8.12.9/8.12.9) with ESMTP id i818X2Lq063011 + for ; Wed, 1 Sep 2004 08:33:02 GMT + (envelope-from news@news.hub.org) +Received: (from news@localhost) + by news.hub.org (8.12.9/8.12.9/Submit) id i818JqVw058197 + for pgsql-odbc@postgresql.org; Wed, 1 Sep 2004 08:19:52 GMT +From: "Markus Donath" +X-Newsgroups: comp.databases.postgresql.interfaces.odbc +Subject: Re: odbc/ado problems +Date: Wed, 1 Sep 2004 10:19:48 +0200 +Organization: Hub.Org Networking Services +Lines: 46 +Message-ID: +References: <005a01c48f7f$9ff8ae70$0102a8c0@pomme001> +X-Complaints-To: usenet@news.hub.org +X-Priority: 3 +X-MSMail-Priority: Normal +X-Newsreader: Microsoft Outlook Express 6.00.2800.1437 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 +To: pgsql-odbc@postgresql.org +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.8 tagged_above=0.0 required=5.0 + tests=PRIORITY_NO_NAME +X-Spam-Level: +X-Archive-Number: 200409/1 +X-Sequence-Number: 4376 + +hello, + +did you use a read only / forward only cursor (adOpenForwardOnly) ? +this is the fastest way to retreive data, other cursor types are much slower +with postgres odbc. + +bye, +Markus Donath. + + +"Kroh Istv�n" schrieb im Newsbeitrag +news:005a01c48f7f$9ff8ae70$0102a8c0@pomme001... +> Hi all! +> +> I'm new here, so hello to everybody! +> +> I'm in a deep truble using postgesSQL 7.2.0 on a low-end pc with SUSE 8. +I'm +> using some databases from that pc through odbc (7.3.200). Until now i had +no +> problems with this solution, everithing worked fine. But today i wrote a +> small app, that converts/copies some data from a database to an other +> database. +> +> During this work i wrote a simple query as follows: +> select pers_driving_license from person where pers_id=23456 +> +> This should return a single varchar(20) field. Running this query over +> ADO/ODBC from a Delphi app tooks 50-100 secs. If i run this from pgAdmin +II. +> it takes some msecs. +> +> The output of explain is: +> Index Scan using person_id_index on person (cost=0.00..3.14 rows=1 +width=4) +> +> Any idea? +> +> Thanks in advance: steve +> +> +> ---------------------------(end of broadcast)--------------------------- +> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org +> + + + +From pgsql-performance-owner@postgresql.org Wed Sep 1 05:45:42 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id D97C15E46F9 + for ; + Wed, 1 Sep 2004 05:45:41 -0300 (ADT) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 64552-06 + for ; + Wed, 1 Sep 2004 08:45:32 +0000 (GMT) +Received: from quasar.skima.is (quasar.skima.is [212.30.200.205]) + by svr1.postgresql.org (Postfix) with ESMTP id 065E75E46CE + for ; + Wed, 1 Sep 2004 05:45:31 -0300 (ADT) +Received: from wp2000 ([157.157.178.195] [157.157.178.195]) by + quasar.skima.is; + Wed, 1 Sep 2004 08:45:28 Z +Message-Id: <00ed01c49000$57ffd400$0100000a@wp2000> +From: "gnari" +To: "Michael Ryan S. Puncia" , + +References: <200409010641.i816fDkJ025384@mail.census.gov.ph> +Subject: Re: Changing the column length +Date: Wed, 1 Sep 2004 08:47:38 -0000 +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 5.00.2919.6700 +X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6700 +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/4 +X-Sequence-Number: 8132 + +From: "Michael Ryan S. Puncia" + +> I am sorry that my question is out of line with this +> group(performance) but I need + +-general might be more appropriate + +> +> an urgent help :-( .pls .. I need to know how to change the length of the +> column. + +add a new column, use update to copy values from old column, +use alter table to rename columns + +gnari + + + +From pgsql-performance-owner@postgresql.org Wed Sep 1 06:15:32 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 67B8F5E3F15 + for ; + Wed, 1 Sep 2004 06:15:30 -0300 (ADT) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 76279-05 + for ; + Wed, 1 Sep 2004 09:15:20 +0000 (GMT) +Received: from smtp-bal.opennet.it (noder32-48.opennet.it [212.110.32.48]) + by svr1.postgresql.org (Postfix) with SMTP id 0AB845E4713 + for ; + Wed, 1 Sep 2004 06:15:13 -0300 (ADT) +Received: (qmail 573 invoked from network); 1 Sep 2004 09:14:13 -0000 +Received: from unknown (HELO comai04) (212.110.56.34) + by 0 with SMTP; 1 Sep 2004 09:14:13 -0000 +Message-ID: <065501c49004$b2864770$0501a8c0@comai04> +From: "Stefano Bonnin" +To: "Josh Berkus" +Cc: +References: <007c01c48c03$269b50c0$0501a8c0@comai04> + <200408271014.29619.josh@agliodbs.com> + <006a01c48e9b$964fe530$0501a8c0@comai04> + <200408300954.51268.josh@agliodbs.com> +Subject: Re: Query performance issue with 8.0.0beta1 +Date: Wed, 1 Sep 2004 11:18:52 +0200 +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 6.00.2800.1437 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/5 +X-Sequence-Number: 8133 + +Server HP: Intel(R) Pentium(R) 4 CPU 2.26GHz +RAM 1GB +OS: RedHat 8 +And the disk: + + kernel: megaide: driver version 05.04f (Date: Nov 11, 2002; 18:15 EST) + kernel: megaide: bios version 02.06.07221605 + kernel: megaide: LD 0 RAID1 status=ONLINE sectors=156297343 +capacity=76317 MB drives=2 + kernel: scsi0 : LSI Logic MegaIDE RAID BIOS Version 2.6.07221605, 8 +targs 1 chans 8 luns + kernel: Vendor: LSILOGIC Model: LD 0 IDERAID Rev: + kernel: Type: Direct-Access ANSI SCSI revision: +02 + +Thanks. +RedS + + +----- Original Message ----- +From: "Josh Berkus" +To: "Stefano Bonnin" +Sent: Monday, August 30, 2004 6:54 PM +Subject: Re: [PERFORM] Query performance issue with 8.0.0beta1 + + +> Stefano, +> +> > This is my postgres.conf, I have changed only the work_mem and +> > shared_buffers parameters. +> +> And not very much, I see. +> +> > >DID you +> > > configure it for the 8.0 database? +> > +> > What does it mean? Is in 8.0 some important NEW configation parameter ? +> +> Well, there are but they shouldn't affect your case. However, there +are a +> lot of other settings that need to be adjusted. Please post your +hardware +> plaform information: OS, CPU, RAM, and disk setup. +> +> -- +> Josh Berkus +> Aglio Database Solutions +> San Francisco +> + + +From pgsql-admin-owner@postgresql.org Wed Sep 1 07:06:33 2004 +X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 330265E471A; + Wed, 1 Sep 2004 07:06:32 -0300 (ADT) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 94058-08; Wed, 1 Sep 2004 10:06:23 +0000 (GMT) +Received: from tino.sinectis.com.ar (tino.sinectis.com.ar [216.244.192.232]) + by svr1.postgresql.org (Postfix) with ESMTP id 18AC45E4711; + Wed, 1 Sep 2004 07:06:20 -0300 (ADT) +Received: by tino.sinectis.com.ar (Postfix, from userid 99) + id 501786C4EA; Wed, 1 Sep 2004 07:06:22 -0300 (GMT+3) +Content-Type: text/plain +Content-Disposition: inline +Content-Transfer-Encoding: 8bit +MIME-Version: 1.0 +X-Mailer: Sinectis Webmail 5.6.16-1.5.1 +From: G u i d o B a r o s i o +To: pgsql-performance@postgresql.org +Subject: slower every day +Cc: pgsql-admin@postgresql.org +Reply-To: gbarosio@uolsinectis.com.ar +Message-Id: <20040901100622.501786C4EA@tino.sinectis.com.ar> +Date: Wed, 1 Sep 2004 07:06:22 -0300 (GMT+3) +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/1 +X-Sequence-Number: 14704 + +Dear all, + + I am currently experiencing troubles with the performance of my critical's database. + + The problem is the time that the postgres takes to perform/return a query. For example, trying the \d command takes between 4 or 5 seconds. This table is very big, but I am not asking for the rows, only asking the table schema, so...why is this so slow?!?!? My last administrative action into this table was a reindex to all the indexes via the BKI in standalone mode. I thought I suceed, but this was las saturday. Today I am in the same situation again. + + The only change that I've done was a highest level of debug in the conf file (loggin lot of stuff). + I understand that this could lack on performance, but when I've changed the .conf file to the usual .conf file (with less debug), and pg_ctl reload(ed) it, it goes on debuging as in the first state, in the higher level. Is this a known issue? + + My conclusion is that I can aquire high levels of debug while the server is running, editing the .conf file, and pg_reload(ing) it, but I can go back then, unless I pg_restart the server. Is this ok? + +Some info +----------------------------------------------------------- +PostgreSQL 7.4.2 +[postgres@lmnukmis02 data]$ pg_config --configure +'--enable-thread-safety' '--with-perl' +Intel(R) Xeon(TM) MP CPU 2.80GHz +Linux 2.4.24-ck1 #5 SMP Fri Mar 12 23:41:51 GMT 2004 i686 unknown +RAM 4 Gb. +----------------------------------------------------------- + + +Thanks, Guido. + + + + +From pgsql-performance-owner@postgresql.org Wed Sep 1 07:26:00 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id CBC1A5E46C3 + for ; + Wed, 1 Sep 2004 07:25:56 -0300 (ADT) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 01532-03 + for ; + Wed, 1 Sep 2004 10:25:47 +0000 (GMT) +Received: from frodo.hserus.net (frodo.hserus.net [204.74.68.40]) + by svr1.postgresql.org (Postfix) with ESMTP id 092A75E46E9 + for ; + Wed, 1 Sep 2004 07:25:46 -0300 (ADT) +Received: from [203.199.147.2] (port=46706 helo=ps0499.persistent.co.in) + by frodo.hserus.net with esmtpsa + (Cipher TLSv1:RC4-MD5:128) (Exim 4.42 #0) + id 1C2SJF-00082t-RA by authid with plain; + Wed, 01 Sep 2004 15:55:46 +0530 +From: Shridhar Daithankar +To: gbarosio@uolsinectis.com.ar +Subject: Re: slower every day +Date: Wed, 1 Sep 2004 15:55:36 +0530 +User-Agent: KMail/1.7 +Cc: pgsql-performance@postgresql.org +References: <20040901100622.501786C4EA@tino.sinectis.com.ar> +In-Reply-To: <20040901100622.501786C4EA@tino.sinectis.com.ar> +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +Content-Disposition: inline +Message-Id: <200409011555.36879.shridhar@frodo.hserus.net> +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/7 +X-Sequence-Number: 8135 + +On Wednesday 01 Sep 2004 3:36 pm, G u i d o B a r o s i o wrote: +> Dear all, +> +> I am currently experiencing troubles with the performance of my +> critical's database. +> +> The problem is the time that the postgres takes to perform/return a +> query. For example, trying the \d command takes between 4 or 5 +> seconds. This table is very big, but I am not asking for the rows, only +> asking the table schema, so...why is this so slow?!?!? My last +> administrative action into this table was a reindex to all the indexes via +> the BKI in standalone mode. I thought I suceed, but this was las saturday. +> Today I am in the same situation again. + +Is this database vacuumed and analyzed recently? I would suggest database-wide +vacuum full analyze. + +If your queries are getting slower, then checking the explain analyze output +is a good starting point. To see queries issued by psql, start it as psql -E. + +HTH + + Shridhar + +From pgsql-admin-owner@postgresql.org Wed Sep 1 07:29:04 2004 +X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 018A75E46F9; + Wed, 1 Sep 2004 07:29:02 -0300 (ADT) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 01532-07; Wed, 1 Sep 2004 10:28:52 +0000 (GMT) +Received: from curie.credativ.org (credativ.com [217.160.209.18]) + by svr1.postgresql.org (Postfix) with ESMTP id D69EF5E46E9; + Wed, 1 Sep 2004 07:28:50 -0300 (ADT) +Received: from localhost (localhost [127.0.0.1]) + by curie.credativ.org (Postfix) with ESMTP + id E606C55EC2; Wed, 1 Sep 2004 12:28:52 +0200 (CEST) +Received: from www.credativ.de (pD95013E6.dip0.t-ipconnect.de [217.80.19.230]) + (using TLSv1 with cipher EDH-RSA-DES-CBC3-SHA (168/168 bits)) + (No client certificate requested) + by curie.credativ.org (Postfix) with ESMTP + id 7591055EC0; Wed, 1 Sep 2004 12:28:52 +0200 (CEST) +Received: from bell.credativ.de (bell.credativ.de [172.26.14.16]) + by www.credativ.de (Postfix) with ESMTP id 8907D1C0066; + Wed, 1 Sep 2004 12:28:50 +0200 (CEST) +From: Peter Eisentraut +To: gbarosio@uolsinectis.com.ar +Subject: Re: slower every day +Date: Wed, 1 Sep 2004 12:28:48 +0200 +User-Agent: KMail/1.6.2 +Cc: pgsql-performance@postgresql.org, pgsql-admin@postgresql.org +References: <20040901100622.501786C4EA@tino.sinectis.com.ar> +In-Reply-To: <20040901100622.501786C4EA@tino.sinectis.com.ar> +MIME-Version: 1.0 +Content-Disposition: inline +Content-Type: text/plain; + charset="iso-8859-15" +Content-Transfer-Encoding: 7bit +Message-Id: <200409011228.48793.peter_e@gmx.net> +X-Virus-Scanned: by AMaViS at credativ.com +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/2 +X-Sequence-Number: 14705 + +Am Mittwoch, 1. September 2004 12:06 schrieb G u i d o B a r o s i o: +> The problem is the time that the postgres takes to perform/return a +> query. For example, trying the \d command takes between 4 or 5 +> seconds. This table is very big, but I am not asking for the rows, only +> asking the table schema, so...why is this so slow?!?!? My last +> administrative action into this table was a reindex to all the indexes via +> the BKI in standalone mode. I thought I suceed, but this was las saturday. + +Do you regularly vacuum and analyze the database? + +-- +Peter Eisentraut +http://developer.postgresql.org/~petere/ + +From pgsql-admin-owner@postgresql.org Wed Sep 1 07:57:17 2004 +X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id E093C5E4711; + Wed, 1 Sep 2004 07:57:15 -0300 (ADT) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 08420-09; Wed, 1 Sep 2004 10:57:14 +0000 (GMT) +Received: from tino.sinectis.com.ar (tino.sinectis.com.ar [216.244.192.232]) + by svr1.postgresql.org (Postfix) with ESMTP id 205415E46F9; + Wed, 1 Sep 2004 07:57:12 -0300 (ADT) +Received: by tino.sinectis.com.ar (Postfix, from userid 99) + id 1489B6C4FD; Wed, 1 Sep 2004 07:57:15 -0300 (GMT+3) +Content-Type: text/plain +Content-Disposition: inline +Content-Transfer-Encoding: 8bit +MIME-Version: 1.0 +X-Mailer: Sinectis Webmail 5.6.16-1.5.1 +From: G u i d o B a r o s i o +To: pgsql-performance@postgresql.org, pgsql-admin@postgresql.org +Subject: Re: slower every day +Reply-To: gbarosio@uolsinectis.com.ar +Message-Id: <20040901105715.1489B6C4FD@tino.sinectis.com.ar> +Date: Wed, 1 Sep 2004 07:57:15 -0300 (GMT+3) +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/3 +X-Sequence-Number: 14706 + +The solution appeared as something I didn't know + + On the .conf file + +Previous situation: + +#log_something=false +log_something=true + +Worst situation +#log_something=false +#log_something=true + +Nice situation +log_something=false +#log_something=true + + +Ok, the problem was that I assumed that commenting a value on +the conf file will set it up to a default (false?). I was wrong. +My server was writting tons of log's. + +Is this the normal behavior for pg_ctl reload? It seems that looks for new values, remembering the last state on the ones that actually are commented. Although it's my fault to have 2 (tow) lines for the same issue, and that I should realize that this is MY MISTAKE, the log defaults on a reload, if commented, tend to be the last value entered? + +Regards, +Guido + + +> Am Mittwoch, 1. September 2004 12:06 schrieb G u i d o B a r o s i o: +> > The problem is the time that the postgres takes to perform/return a +> > query. For example, trying the \d command takes between 4 or 5 +> > seconds. This table is very big, but I am not asking for the rows, only +> > asking the table schema, so...why is this so slow?!?!? My last +> > administrative action into this table was a reindex to all the indexes via +> > the BKI in standalone mode. I thought I suceed, but this was las saturday. +> +> Do you regularly vacuum and analyze the database? +> +> -- +> Peter Eisentraut +> http://developer.postgresql.org/~petere/ +> +> ---------------------------(end of broadcast)--------------------------- +> TIP 8: explain analyze is your friend + + +From pgsql-admin-owner@postgresql.org Wed Sep 1 08:58:57 2004 +X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 295FC5E4711; + Wed, 1 Sep 2004 08:58:53 -0300 (ADT) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 29670-08; Wed, 1 Sep 2004 11:58:52 +0000 (GMT) +Received: from honorio.sinectis.com.ar (honorio.sinectis.com.ar + [216.244.192.201]) + by svr1.postgresql.org (Postfix) with ESMTP id 0D1635E4713; + Wed, 1 Sep 2004 08:58:49 -0300 (ADT) +Received: by honorio.sinectis.com.ar (Postfix, from userid 99) + id 309FB6C4F2; Wed, 1 Sep 2004 08:58:53 -0300 (GMT+3) +Content-Type: text/plain +Content-Disposition: inline +Content-Transfer-Encoding: 8bit +MIME-Version: 1.0 +X-Mailer: Sinectis Webmail 5.6.16-1.5.1 +From: G u i d o B a r o s i o +To: pgsql-performance@postgresql.org, pgsql-admin@postgresql.org +Subject: Re: slower every day +Cc: pgsql-hackers@postgresql.org +Reply-To: gbarosio@uolsinectis.com.ar +Message-Id: <20040901115853.309FB6C4F2@honorio.sinectis.com.ar> +Date: Wed, 1 Sep 2004 08:58:53 -0300 (GMT+3) +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/5 +X-Sequence-Number: 14708 + +Again me, + + To make it easier. + +Situation A: +log_something = true + +Situation B: +# log_something = + +Situation C: +log_something = false + +After the pg_ctl reload: + +Situation B = Situation A +Situation C <> (Situation A || Situation B) + +Is this the expected behavior? + +Conclusion: + +If you comment a line on the conf file, and reload it, will remain in the last state. (either wast true or false, while I expected a default) + +Regards + +> The solution appeared as something I didn't know +> +> On the .conf file +> +> Previous situation: +> +> #log_something=false +> log_something=true +> +> Worst situation +> #log_something=false +> #log_something=true +> +> Nice situation +> log_something=false +> #log_something=true +> +> +> Ok, the problem was that I assumed that commenting a value on +> the conf file will set it up to a default (false?). I was wrong. +> My server was writting tons of log's. +> +> Is this the normal behavior for pg_ctl reload? It seems that looks for new values, remembering the last state on the ones that actually are commented. Although it's my fault to have 2 (tow) lines for the same issue, and that I should realize that this is MY MISTAKE, the log defaults on a reload, if commented, tend to be the last value entered? +> +> Regards, +> Guido +> +> +> > Am Mittwoch, 1. September 2004 12:06 schrieb G u i d o B a r o s i o: +> > > The problem is the time that the postgres takes to perform/return a +> > > query. For example, trying the \d command takes between 4 or 5 +> > > seconds. This table is very big, but I am not asking for the rows, only +> > > asking the table schema, so...why is this so slow?!?!? My last +> > > administrative action into this table was a reindex to all the indexes via +> > > the BKI in standalone mode. I thought I suceed, but this was las saturday. +> > +> > Do you regularly vacuum and analyze the database? +> > +> > -- +> > Peter Eisentraut +> > http://developer.postgresql.org/~petere/ +> > +> > ---------------------------(end of broadcast)--------------------------- +> > TIP 8: explain analyze is your friend +> +> +> ---------------------------(end of broadcast)--------------------------- +> TIP 4: Don't 'kill -9' the postmaster + + +From pgsql-performance-owner@postgresql.org Wed Sep 1 09:28:00 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 127A75E471F; + Wed, 1 Sep 2004 09:27:58 -0300 (ADT) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 43559-03; Wed, 1 Sep 2004 12:27:57 +0000 (GMT) +Received: from anchor-post-32.mail.demon.net (anchor-post-32.mail.demon.net + [194.217.242.90]) + by svr1.postgresql.org (Postfix) with ESMTP id 82A945E471E; + Wed, 1 Sep 2004 09:27:55 -0300 (ADT) +Received: from mwynhau.demon.co.uk ([193.237.186.96] + helo=mainbox.archonet.com) + by anchor-post-32.mail.demon.net with esmtp (Exim 3.35 #1) + id 1C2UDW-0001ib-0W; Wed, 01 Sep 2004 12:27:58 +0000 +Received: from [192.168.1.17] (client17.archonet.com [192.168.1.17]) + by mainbox.archonet.com (Postfix) with ESMTP + id 4FA6217D6B; Wed, 1 Sep 2004 13:27:55 +0100 (BST) +Message-ID: <4135C04A.5040804@archonet.com> +Date: Wed, 01 Sep 2004 13:27:54 +0100 +From: Richard Huxton +User-Agent: Mozilla Thunderbird 0.7 (X11/20040615) +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: gbarosio@uolsinectis.com.ar +Cc: pgsql-performance@postgresql.org, pgsql-hackers@postgresql.org +Subject: Re: [ADMIN] slower every day +References: <20040901115853.309FB6C4F2@honorio.sinectis.com.ar> +In-Reply-To: <20040901115853.309FB6C4F2@honorio.sinectis.com.ar> +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/10 +X-Sequence-Number: 8138 + +G u i d o B a r o s i o wrote: +> Conclusion: +> +> If you comment a line on the conf file, and reload it, will remain in +> the last state. (either wast true or false, while I expected a +> default) + +Yes, that's correct. No, you're not the only one to have been caught out +by this. + +-- + Richard Huxton + Archonet Ltd + +From pgsql-performance-owner@postgresql.org Wed Sep 1 09:50:06 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 62EC55E471D + for ; + Wed, 1 Sep 2004 09:50:03 -0300 (ADT) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 48824-07 + for ; + Wed, 1 Sep 2004 12:50:01 +0000 (GMT) +Received: from web41102.mail.yahoo.com (web41102.mail.yahoo.com + [66.218.93.18]) + by svr1.postgresql.org (Postfix) with SMTP id E355E5E471A + for ; + Wed, 1 Sep 2004 09:49:58 -0300 (ADT) +Message-ID: <20040901125002.43149.qmail@web41102.mail.yahoo.com> +Received: from [61.25.53.100] by web41102.mail.yahoo.com via HTTP; + Wed, 01 Sep 2004 05:50:02 PDT +Date: Wed, 1 Sep 2004 05:50:02 -0700 (PDT) +From: Mr Pink +Subject: Re: Why does a simple query not use an obvious index? +To: Greg Stark +Cc: Tom Lane , pgsql-performance@postgresql.org +In-Reply-To: <87ekloidls.fsf@stark.xeocode.com> +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/11 +X-Sequence-Number: 8139 + +Hi Greg, Tom, etal + +It's true that oracle only peeks during a hard parse, and this can have good or bad results +depending on the situation. Basically, the first value used in that query will determine the plan +until that query is bumped from the sql cache or the server is restarted. As far as I know, there +is no option to disable that feature in Oracle, I don't know about postgres. + +Overall, I think it's a good feature because it helps us in the goal of reducing hardparsing (that +was it's real purpose in oracle). The trick as with all good features is to use it cleverly. For +example, you could run scripts on server startup that run such queries with optimal values before +any one gets back on. If your application has optimal use of bind variables allowing re-use of +query plan, and the sql cache has enough memory then the query plans you created at server startup +could be expected to be current for the life of that instance. + +I write all this from my knowlegdge of Oracle, but I can't be sure how it applies to postgres. +Come to think about it, I don't think I've seen a good discussion of plan caching, hard parsing +and such like specifically related to pg. I'd really like to know more about how pg treats that +stuff. + +regards +Mr Pink + +--- Greg Stark wrote: + +> +> +> [I'm actually responding to the previous post from Tom Lane, but I've deleted +> it and the archives seem to be down again.] +> +> +> The assumption being made is that the first provided result is representative +> of all future results. I don't see any reason that making this assumption of +> all stable functions should be less scary than making the assumption about +> user provided parameters. +> +> However I have the complementary reaction. I find peeking at the first +> bind parameter to be scary as hell. Functions seem slightly less scary. +> +> On Oracle Peeking at bind parameters is a feature explicitly intended for DSS +> data warehouse type systems. The use of placeholders there was purely for +> security and programming ease, not efficiency, since the queries are only +> planned executed a small number of times per plan. These are systems that +> suffered enormously without the parameter values. They often involved full +> table scans or bitmap index scans and without the statistics produced awful +> plans. +> +> For OLTP systems peeking at placeholders is more a danger than a benefit. The +> query will be executed thousands of times and if it's planned based on a +> single unusual value initially the entire system could fail. +> +> Consider the following scenario which isn't farfetched at all. In fact I think +> it well describes my current project: +> +> I have a table with a few million records. 99% of the time users are working +> with only a few hundred records at most. There's an index on the column +> they're keying off of. 1% of the key values have an unusually large number of +> records. +> +> Without peeking at placeholders the system should see that virtually all the +> key values are well under the threshold for an index scan to be best. So it +> always uses an index scan. 1% of the time it takes longer than that it would +> have with a sequential scan, but only by a small factor. (On the whole we're +> probably still better off avoiding the cache pollution anyways.) +> +> With peeking at placeholders 99% of the backends would perform the same way. +> However 1 backend in 100 sees one of these unusual values for its first query. +> This backend will use a sequential scan for *every* request. Executing a +> sequential table scan of this big table once a second this backend will drive +> the entire system into the ground. +> +> This means every time I start the system up I stand a small but significant +> chance of it just completely failing to perform properly. Worse, apache is +> designed to periodically start new processes, so at any given time the system +> could just randomly fall over and die. +> +> I would rather incur a 10% penalty on every query than have a 1% chance of it +> keeling over and dieing. Given this I would when I upgrade to 8.0 have to +> ensure that my application driver is either not using placeholders at all (at +> the protocol level -- I always prefer them at the api level) or ensure that +> postgres is *not* peeking at the value. +> +> I like the feature but I just want to be sure that it's optional. +> +> -- +> greg +> +> +> ---------------------------(end of broadcast)--------------------------- +> TIP 6: Have you searched our list archives? +> +> http://archives.postgresql.org +> + + + + +__________________________________ +Do you Yahoo!? +Yahoo! Mail - 50x more storage than other providers! +http://promotions.yahoo.com/new_mail + +From pgsql-admin-owner@postgresql.org Wed Sep 1 11:28:19 2004 +X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id DBE655E471A + for ; + Wed, 1 Sep 2004 11:28:15 -0300 (ADT) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 89163-07 + for ; + Wed, 1 Sep 2004 14:28:15 +0000 (GMT) +Received: from mail.gmx.net (pop.gmx.net [213.165.64.20]) + by svr1.postgresql.org (Postfix) with SMTP id 1939D5E4722 + for ; Wed, 1 Sep 2004 11:28:12 -0300 (ADT) +Received: (qmail 8985 invoked by uid 65534); 1 Sep 2004 14:28:18 -0000 +Received: from office01.emerion.com (EHLO zaphod) (83.64.50.26) + by mail.gmx.net (mp017) with SMTP; 01 Sep 2004 16:28:18 +0200 +X-Authenticated: #1946847 +Message-ID: <01ae01c4902f$ed692490$ad01a8c0@zaphod> +From: "Michael Paesold" +To: , + , +References: <20040901105715.1489B6C4FD@tino.sinectis.com.ar> +Subject: Re: slower every day +Date: Wed, 1 Sep 2004 16:28:15 +0200 +MIME-Version: 1.0 +Content-Type: text/plain; + charset="Windows-1252" +Content-Transfer-Encoding: 7bit +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 6.00.2800.1437 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/8 +X-Sequence-Number: 14711 + +This issue was resently discussed on hackers. It is a known issue, not very +convinient for the user. Nevertheless it is not fixed in 8.0, but will +perhaps be addressed in the next major release. +(Remembering, it was a non-trivial thing to change.) + +Best Regards, +Michael Paesold + +G u i d o B a r o s i o wrote: + +> The solution appeared as something I didn't know +> +> On the .conf file +> +> Previous situation: +> +> #log_something=false +> log_something=true +> +> Worst situation +> #log_something=false +> #log_something=true +> +> Nice situation +> log_something=false +> #log_something=true +> +> +> Ok, the problem was that I assumed that commenting a value on +> the conf file will set it up to a default (false?). I was wrong. +> My server was writting tons of log's. +> +> Is this the normal behavior for pg_ctl reload? It seems that looks for new +values, remembering the last state on the ones that actually are commented. +Although it's my fault to have 2 (tow) lines for the same issue, and that I +should realize that this is MY MISTAKE, the log defaults on a reload, if +commented, tend to be the last value entered? + + +From pgsql-admin-owner@postgresql.org Wed Sep 1 12:07:47 2004 +X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 2D51B5E4713; + Wed, 1 Sep 2004 12:07:46 -0300 (ADT) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 06944-09; Wed, 1 Sep 2004 15:07:43 +0000 (GMT) +Received: from honorio.sinectis.com.ar (honorio.sinectis.com.ar + [216.244.192.201]) + by svr1.postgresql.org (Postfix) with ESMTP id 090945E3F15; + Wed, 1 Sep 2004 12:07:34 -0300 (ADT) +Received: by honorio.sinectis.com.ar (Postfix, from userid 99) + id BB5206C4E8; Wed, 1 Sep 2004 12:07:39 -0300 (GMT+3) +Content-Type: text/plain +Content-Disposition: inline +Content-Transfer-Encoding: 8bit +MIME-Version: 1.0 +X-Mailer: Sinectis Webmail 5.6.16-1.5.1 +From: G u i d o B a r o s i o +To: mpaesold@gmx.at, pgsql-performance@postgresql.org, + pgsql-admin@postgresql.org +Subject: Re: slower every day +Cc: pgsql-hackers@postgresql.org +Reply-To: gbarosio@uolsinectis.com.ar +Message-Id: <20040901150739.BB5206C4E8@honorio.sinectis.com.ar> +Date: Wed, 1 Sep 2004 12:07:39 -0300 (GMT+3) +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/9 +X-Sequence-Number: 14712 + +Thanks for the reply, + + Been reading hackers of Aug 2004 and found the threads. It's a common habit to create two lines on the configuration files, in order to maintain the copy of the default conf file. I guess this should be the worst scenery for a freshly incoming DBA trying to put things in order. + + A temporary patch, will be updating documentation, encouraging administrators to use the SHOW ALL; command in the psql env, to confirm that changes where made. + + In my case, a 1.2 gig file was written, performance was on the floor. And my previous situation, a reindex force task last saturday, confused me. This is not a trivial problem, but in conjunction with other small problems could become a big one. + + Good habits when touching conf files & using the SHOW ALL to confirm that changes where made will help until this is patched. + + Thanks for Postgres, + +Regards, Guido. + + +> This issue was resently discussed on hackers. It is a known issue, not very +> convinient for the user. Nevertheless it is not fixed in 8.0, but will +> perhaps be addressed in the next major release. +> (Remembering, it was a non-trivial thing to change.) +> +> Best Regards, +> Michael Paesold +> +> G u i d o B a r o s i o wrote: +> +> > The solution appeared as something I didn't know +> > +> > On the .conf file +> > +> > Previous situation: +> > +> > #log_something=false +> > log_something=true +> > +> > Worst situation +> > #log_something=false +> > #log_something=true +> > +> > Nice situation +> > log_something=false +> > #log_something=true +> > +> > +> > Ok, the problem was that I assumed that commenting a value on +> > the conf file will set it up to a default (false?). I was wrong. +> > My server was writting tons of log's. +> > +> > Is this the normal behavior for pg_ctl reload? It seems that looks for new +> values, remembering the last state on the ones that actually are commented. +> Although it's my fault to have 2 (tow) lines for the same issue, and that I +> should realize that this is MY MISTAKE, the log defaults on a reload, if +> commented, tend to be the last value entered? +> + + +From pgsql-performance-owner@postgresql.org Wed Sep 1 12:47:37 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id A9EFE5E46CD + for ; + Wed, 1 Sep 2004 12:47:36 -0300 (ADT) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 27579-02 + for ; + Wed, 1 Sep 2004 15:47:34 +0000 (GMT) +Received: from arbor.net (division.aa.arbor.net [204.181.64.2]) + by svr1.postgresql.org (Postfix) with ESMTP id 2F6C05E46CC + for ; + Wed, 1 Sep 2004 12:47:26 -0300 (ADT) +Received: by arbor.net (Postfix, from userid 1065) + id 5B1372A894; Wed, 1 Sep 2004 11:47:32 -0400 (EDT) +Received: from localhost (localhost [127.0.0.1]) + by arbor.net (Postfix) with ESMTP + id 58B6C2A88C; Wed, 1 Sep 2004 11:47:32 -0400 (EDT) +Date: Wed, 1 Sep 2004 11:47:32 -0400 (EDT) +From: Chester Kustarz +To: Martin Sarsale +Cc: Bruno Wolff III , + +Subject: Re: seqscan instead of index scan +In-Reply-To: <1093889235.1680.77.camel@kadaif> +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/14 +X-Sequence-Number: 8142 + +On Mon, 30 Aug 2004, Martin Sarsale wrote: +> "Multicolumn indexes can only be used if the clauses involving the +> indexed columns are joined with AND. For instance, +> +> SELECT name FROM test2 WHERE major = constant OR minor = constant; + +You can use DeMorgan's Theorem to transform an OR clause to an AND clause. + +In general: + A OR B <=> NOT ((NOT A) AND (NOT B)) + +So: + +> But I need something like: +> +> select * from t where c<>0 or d<>0; + + select * from t where not (c=0 and d=0); + +I haven't actually tried to see if postgresql would do anything +interesting after such a transformation. + + + + +From pgsql-performance-owner@postgresql.org Wed Sep 1 13:33:36 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id A8AC15E46C3 + for ; + Wed, 1 Sep 2004 13:33:30 -0300 (ADT) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 47227-04 + for ; + Wed, 1 Sep 2004 16:33:36 +0000 (GMT) +Received: from davinci.ethosmedia.com (server226.ethosmedia.com + [209.128.84.226]) + by svr1.postgresql.org (Postfix) with ESMTP id E49725E470A + for ; + Wed, 1 Sep 2004 13:33:28 -0300 (ADT) +Received: from [63.195.55.98] (HELO spooky) + by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.1.8) + with ESMTP id 6244569; Wed, 01 Sep 2004 09:34:54 -0700 +Content-Type: text/plain; + charset="iso-8859-1" +From: Josh Berkus +Organization: Aglio Database Solutions +To: "Michael Ryan S. Puncia" , + +Subject: Re: Changing the column length +Date: Wed, 1 Sep 2004 09:32:24 -0700 +User-Agent: KMail/1.4.3 +References: <200409010641.i816fDkJ025384@mail.census.gov.ph> +In-Reply-To: <200409010641.i816fDkJ025384@mail.census.gov.ph> +MIME-Version: 1.0 +Content-Transfer-Encoding: 8bit +Message-Id: <200409010932.24702.josh@agliodbs.com> +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/15 +X-Sequence-Number: 8143 + +Michael, + +> I am sorry that my question is out of line with this +> group(performance) but I need +> +> an urgent help :-( .pls .. I need to know how to change the length of the +> column. + +In the future, try to provide more detail on your problem. Fortunately, I +think I know what it is. + +PostgreSQL does not support changing the length of VARCHAR columns in-place +until version 8.0 (currently in beta). Instead, you need to: + +1) Add a new column of the correct length; +2) Copy the data in the old column to the new column; +3) Drop the old column; +4) Rename the new column to the same name as the old column. + +I realize that this approach can be quite painful if you have dependant views, +contstraints, etc. It's why we fixed it for 8.0. You can also: + +1) pg_dump the database in text format; +2) edit the table definition in the pg_dump file; +3) re-load the database + +While it *is* possible to change the column size by updating the system +tables, doing so is NOT recommended as it can cause unexpected database +errors. + +-- +Josh Berkus +Aglio Database Solutions +San Francisco + +From pgsql-performance-owner@postgresql.org Wed Sep 1 14:53:32 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 9943C5E46CD + for ; + Wed, 1 Sep 2004 14:53:30 -0300 (ADT) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 53833-01 + for ; + Wed, 1 Sep 2004 17:53:20 +0000 (GMT) +Received: from Herge.rcsinc.local (mail.rcsonline.com [205.217.85.91]) + by svr1.postgresql.org (Postfix) with ESMTP id A9D725E46CE + for ; + Wed, 1 Sep 2004 14:53:19 -0300 (ADT) +Content-class: urn:content-classes:message +MIME-Version: 1.0 +Content-Type: text/plain; + charset="US-ASCII" +Content-Transfer-Encoding: quoted-printable +Subject: Re: seqscan instead of index scan +X-MimeOLE: Produced By Microsoft Exchange V6.5.6944.0 +Date: Wed, 1 Sep 2004 13:53:18 -0400 +Message-ID: <6EE64EF3AB31D5448D0007DD34EEB3412A7496@Herge.rcsinc.local> +X-MS-Has-Attach: +X-MS-TNEF-Correlator: +Thread-Topic: [PERFORM] seqscan instead of index scan +Thread-Index: AcSQOzP43201bHHvQUy5Wjlr4DIZ6gAD5zZw +From: "Merlin Moncure" +To: "Chester Kustarz" +Cc: , + "Martin Sarsale" +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/16 +X-Sequence-Number: 8144 + +> On Mon, 30 Aug 2004, Martin Sarsale wrote: +> > "Multicolumn indexes can only be used if the clauses involving the +> > indexed columns are joined with AND. For instance, +> > +> > SELECT name FROM test2 WHERE major =3D constant OR minor =3D constant; +>=20 +> You can use DeMorgan's Theorem to transform an OR clause to an AND +clause. +>=20 +> In general: +> A OR B <=3D> NOT ((NOT A) AND (NOT B)) +>=20 +> So: +>=20 +> > But I need something like: +> > +> > select * from t where c<>0 or d<>0; +>=20 +> select * from t where not (c=3D0 and d=3D0); +>=20 +> I haven't actually tried to see if postgresql would do anything +> interesting after such a transformation. + +That made me really curious. I ran a quick test and it turns out the +server used dm's theorem to convert the expression back to 'or' case. + +Explain output (see below to set up the test case for this stmnt): +esp=3D# explain analyze select * from millions where not (value1 <> 500000 +and value2 <> 200000); + QUERY +PLAN + +------------------------------------------------------------------------ +---------------------------- +-------------------------------------- + Index Scan using millions_1_idx, millions_2_idx on millions +(cost=3D0.00..12.01 rows=3D2 width=3D8) (act +ual time=3D0.000..0.000 rows=3D2 loops=3D1) + Index Cond: ((value1 =3D 500000) OR (value2 =3D 200000)) + Total runtime: 0.000 ms +(3 rows) + +drop table tens; +drop table millions; + +create table tens(value int); +create table millions(value1 int, value2 int); +insert into tens values (0); +insert into tens values (1); +insert into tens values (2); +insert into tens values (3); +insert into tens values (4); +insert into tens values (5); +insert into tens values (6); +insert into tens values (7); +insert into tens values (8); +insert into tens values (9); + +insert into millions=20 + select ones.value +=20 + (tens.value * 10) + + (hundreds.value * 100) + + (thousands.value * 1000) + + (tenthousands.value * 10000) + + (hundredthousands.value * 100000)=20 + from tens ones,=20 + tens tens, + tens hundreds, + tens thousands, + tens tenthousands, + tens hundredthousands; +=20=20=20=20=20=20=20=20 +update millions set value2 =3D value1; + +create index millions_idx1 on millions(value1); +create index millions_idx2 on millions(value2); +create index millions_idx12 on millions(value1, value2); +vacuum analyze millions; + + +From pgsql-odbc-owner@postgresql.org Thu Sep 2 07:44:47 2004 +X-Original-To: pgsql-odbc-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id B75D55E3632 + for ; + Thu, 2 Sep 2004 07:44:45 -0300 (ADT) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 96045-09 + for ; + Thu, 2 Sep 2004 10:44:42 +0000 (GMT) +Received: from mail2.mail.iol.ie (mail2.mail.iol.ie [193.95.141.54]) + by svr1.postgresql.org (Postfix) with ESMTP id 4CF645E4710 + for ; Thu, 2 Sep 2004 07:44:40 -0300 (ADT) +Received: from dialup0482.ts551.cwt.esat.net ([193.203.141.226] helo=Nimrod) + by mail2.mail.iol.ie with esmtp (Exim 3.36 #9) + id 1C2p58-00032I-00; Thu, 02 Sep 2004 11:44:42 +0100 +From: "Raymond O'Donnell" +To: "=?ISO-8859-1?Q?Kroh_Istv=A0n?=" , + pgsql-odbc@postgresql.org +Date: Thu, 02 Sep 2004 11:46:02 +0100 +MIME-Version: 1.0 +Subject: Re: odbc/ado problems +Message-ID: <413707FA.23200.282B24@localhost> +In-reply-to: <005a01c48f7f$9ff8ae70$0102a8c0@pomme001> +X-mailer: Pegasus Mail for Windows (4.21c) +Content-type: text/plain; charset=ISO-8859-1 +Content-transfer-encoding: Quoted-printable +Content-description: Mail message body +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/3 +X-Sequence-Number: 4378 + +On 31 Aug 2004 at 19:26, Kroh Istv=A0n wrote: + +> This should return a single varchar(20) field. Running this query over +> ADO/ODBC from a Delphi app tooks 50-100 secs. If i run this from +> pgAdmin II. it takes some msecs. + +I have found instantiating and using the ADO objects directly to be +much faster than using the TADOConnection and TADOQuery components +that come with Delphi. - This is in web apps where I'd construct the +SQL and execute it with the Connection object. + +--Ray. + +------------------------------------------------------------- +Raymond O'Donnell http://www.galwaycathedral.org/recitals +rod@iol.ie Galway Cathedral Recitals +------------------------------------------------------------- + + + +From pgsql-performance-owner@postgresql.org Thu Sep 2 10:43:50 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 206025E473C + for ; + Thu, 2 Sep 2004 10:43:47 -0300 (ADT) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 61572-10 + for ; + Thu, 2 Sep 2004 13:43:43 +0000 (GMT) +Received: from mail.logi-track.com (www.logi-track.com [213.239.193.212]) + by svr1.postgresql.org (Postfix) with ESMTP id 984CC5E472F + for ; + Thu, 2 Sep 2004 10:43:40 -0300 (ADT) +Received: from kingfisher.intern.logi-track.com (G7008.g.pppool.de + [80.185.112.8]) + by mail.logi-track.com (Postfix) with ESMTP id 75B1130139; + Thu, 2 Sep 2004 15:43:46 +0200 (CEST) +Received: from kingfisher.intern.logi-track.com (localhost [127.0.0.1]) + by kingfisher.intern.logi-track.com (Postfix) with SMTP id 07286AB2A9; + Thu, 2 Sep 2004 15:43:40 +0200 (CEST) +Date: Thu, 2 Sep 2004 15:43:40 +0200 +From: Markus Schaber +To: PostgreSQL Performance List +Subject: Multiple Uniques +Message-Id: <20040902154340.5b1a669a@kingfisher.intern.logi-track.com> +Organization: logi-track ag, =?ISO-8859-15?Q?z=FCrich?= +X-Mailer: Sylpheed-Claws 0.9.12 (GTK+ 1.2.10; i386-pc-linux-gnu) +X-Face: Nx5T&>Nj$VrVPv}sC3IL&)TqHHOKCz/|)R$i"*r@w0{*I6w; + UNU_hdl1J4NI_m{IMztq=>cmM}1gCLbAF+9\#CGkG8}Y{x%SuQ>1#t:; + Z(|\qdd[i]HStki~#w1$TPF}:0w-7"S\Ev|_a$K Subquery Scan blabb (cost=3D32970061.50..33246085.82 rows=3D200 wid= +th=3D8) + -> Unique (cost=3D32970061.50..33246083.82 rows=3D200 width=3D8) + -> Sort (cost=3D32970061.50..33108072.66 rows=3D55204464 w= +idth=3D8) + Sort Key: id + -> Subquery Scan blubb (cost=3D23697404.79..24525471= +.75 rows=3D55204464 width=3D8) + -> Unique (cost=3D23697404.79..23973427.11 row= +s=3D55204464 width=3D8) + -> Sort (cost=3D23697404.79..23835415.95= + rows=3D55204464 width=3D8) + Sort Key: id + -> Append (cost=3D7212374.04..1525= +2815.03 rows=3D55204464 width=3D8) + -> Subquery Scan "*SELECT* 1"= + (cost=3D7212374.04..7626407.52 rows=3D27602232 width=3D8) + -> Unique (cost=3D7212= +374.04..7350385.20 rows=3D27602232 width=3D8) + -> Sort (cost=3D= +7212374.04..7281379.62 rows=3D27602232 width=3D8) + Sort Key: re= +f_in_id + -> Seq Scan= + on streets (cost=3D0.00..3129090.32 rows=3D27602232 width=3D8) + -> Subquery Scan "*SELECT* 2"= + (cost=3D7212374.04..7626407.52 rows=3D27602232 width=3D8) + -> Unique (cost=3D7212= +374.04..7350385.20 rows=3D27602232 width=3D8) + -> Sort (cost=3D= +7212374.04..7281379.62 rows=3D27602232 width=3D8) + Sort Key: nr= +ef_in_id + -> Seq Scan= + on streets (cost=3D0.00..3129090.32 rows=3D27602232 width=3D8) +(20 rows) + +I might have to add that this query is not an every-day query, it's +merely part of some statistics that a colleague needs for some +estimations as he has to create a tool that works on this data. + +Both ref_in_id and nref_in_id are non-indexed columns with type int8. + +I was somehow irritated by the fact that the Query Plan contains 4 Uniques. + +Then, I tried the following query: + +logigis=3D# explain select count(id) from (select distinct id from (select = + ref_in_id as id from streets union select nref_in_id as id from streets) = +as blubb) as blabb; + QUERY PLAN=20=20=20= +=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= +=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= +=20=20=20=20 +---------------------------------------------------------------------------= +------------------------------------------------ + Aggregate (cost=3D24803496.57..24803496.57 rows=3D1 width=3D8) + -> Subquery Scan blabb (cost=3D24527471.75..24803496.07 rows=3D200 wid= +th=3D8) + -> Unique (cost=3D24527471.75..24803494.07 rows=3D200 width=3D8) + -> Sort (cost=3D24527471.75..24665482.91 rows=3D55204464 w= +idth=3D8) + Sort Key: id + -> Subquery Scan blubb (cost=3D15254815.03..16082881= +.99 rows=3D55204464 width=3D8) + -> Unique (cost=3D15254815.03..15530837.35 row= +s=3D55204464 width=3D8) + -> Sort (cost=3D15254815.03..15392826.19= + rows=3D55204464 width=3D8) + Sort Key: id + -> Append (cost=3D0.00..6810225.28= + rows=3D55204464 width=3D8) + -> Subquery Scan "*SELECT* 1"= + (cost=3D0.00..3405112.64 rows=3D27602232 width=3D8) + -> Seq Scan on streets = + (cost=3D0.00..3129090.32 rows=3D27602232 width=3D8) + -> Subquery Scan "*SELECT* 2"= + (cost=3D0.00..3405112.64 rows=3D27602232 width=3D8) + -> Seq Scan on streets = + (cost=3D0.00..3129090.32 rows=3D27602232 width=3D8) +(14 rows) + +And after re-parsing the documentation about UNION, the following one: + +logigis=3D# explain select count(id) from (select ref_in_id as id from str= +eets union select nref_in_id as id from streets) as blubb; + QUERY PLAN=20=20=20=20=20=20= +=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= +=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 +---------------------------------------------------------------------------= +------------------------------ + Aggregate (cost=3D16220893.16..16220893.16 rows=3D1 width=3D8) + -> Subquery Scan blubb (cost=3D15254815.03..16082881.99 rows=3D5520446= +4 width=3D8) + -> Unique (cost=3D15254815.03..15530837.35 rows=3D55204464 width= +=3D8) + -> Sort (cost=3D15254815.03..15392826.19 rows=3D55204464 w= +idth=3D8) + Sort Key: id + -> Append (cost=3D0.00..6810225.28 rows=3D55204464 w= +idth=3D8) + -> Subquery Scan "*SELECT* 1" (cost=3D0.00..34= +05112.64 rows=3D27602232 width=3D8) + -> Seq Scan on streets (cost=3D0.00..312= +9090.32 rows=3D27602232 width=3D8) + -> Subquery Scan "*SELECT* 2" (cost=3D0.00..34= +05112.64 rows=3D27602232 width=3D8) + -> Seq Scan on streets (cost=3D0.00..312= +9090.32 rows=3D27602232 width=3D8) +(10 rows) + +Those queries should give the same result. + +So, now my question is, why does the query optimizer not recognize that +it can throw away those "non-unique" Sort/Unique passes? + +Is PostGreSQL 8 capable of this optimization? + + +Thanks, +Markus + + +--=20 +markus schaber | dipl. informatiker +logi-track ag | rennweg 14-16 | ch 8001 z=FCrich +phone +41-43-888 62 52 | fax +41-43-888 62 53 +mailto:schabios@logi-track.com | www.logi-track.com + +From pgsql-performance-owner@postgresql.org Thu Sep 2 11:22:38 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 5E19F5E4733 + for ; + Thu, 2 Sep 2004 11:22:37 -0300 (ADT) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 77589-10 + for ; + Thu, 2 Sep 2004 14:22:36 +0000 (GMT) +Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) + by svr1.postgresql.org (Postfix) with ESMTP id 8973F5E4730 + for ; + Thu, 2 Sep 2004 11:22:33 -0300 (ADT) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i82EMcc3019517; + Thu, 2 Sep 2004 10:22:38 -0400 (EDT) +To: Markus Schaber +Cc: PostgreSQL Performance List +Subject: Re: Multiple Uniques +In-reply-to: <20040902154340.5b1a669a@kingfisher.intern.logi-track.com> +References: <20040902154340.5b1a669a@kingfisher.intern.logi-track.com> +Comments: In-reply-to Markus Schaber + message dated "Thu, 02 Sep 2004 15:43:40 +0200" +Date: Thu, 02 Sep 2004 10:22:37 -0400 +Message-ID: <19516.1094134957@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/18 +X-Sequence-Number: 8146 + +Markus Schaber writes: +> Today, we stumbled about the following query plan on PostGreSQL 7.4.1: + +> logigis=# explain select count(id) from (select distinct id from (select distinct ref_in_id as id from streets union select distinct nref_in_id as id from streets) as blubb) as blabb; + +> I was somehow irritated by the fact that the Query Plan contains 4 Uniques. + +Well, if you write a silly query, you can get a silly plan ... + +As you appear to have realized later, given the definition of UNION, +all three of the explicit DISTINCTs are redundant. + +> So, now my question is, why does the query optimizer not recognize that +> it can throw away those "non-unique" Sort/Unique passes? + +Because the issue doesn't come up often enough to justify expending +cycles to check for it. + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Thu Sep 2 16:34:02 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id BE42C5E4733 + for ; + Thu, 2 Sep 2004 16:33:59 -0300 (ADT) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 23602-04 + for ; + Thu, 2 Sep 2004 19:33:56 +0000 (GMT) +Received: from stark.xeocode.com (gsstark.mtl.istop.com [66.11.160.162]) + by svr1.postgresql.org (Postfix) with ESMTP id F236E5E472F + for ; + Thu, 2 Sep 2004 16:33:54 -0300 (ADT) +Received: from localhost ([127.0.0.1] helo=stark.xeocode.com) + by stark.xeocode.com with smtp (Exim 3.36 #1 (Debian)) + id 1C2xL0-0001tt-00; Thu, 02 Sep 2004 15:33:38 -0400 +To: Markus Schaber +Cc: PostgreSQL Performance List +Subject: Re: Multiple Uniques +References: <20040902154340.5b1a669a@kingfisher.intern.logi-track.com> +In-Reply-To: <20040902154340.5b1a669a@kingfisher.intern.logi-track.com> +From: Greg Stark +Organization: The Emacs Conspiracy; member since 1992 +Date: 02 Sep 2004 15:33:38 -0400 +Message-ID: <87isawwjn1.fsf@stark.xeocode.com> +Lines: 27 +User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/19 +X-Sequence-Number: 8147 + + +Markus Schaber writes: + +> logigis=# explain select count(id) from (select ref_in_id as id from streets union select nref_in_id as id from streets) as blubb; +> QUERY PLAN +> --------------------------------------------------------------------------------------------------------- +> Aggregate (cost=16220893.16..16220893.16 rows=1 width=8) +> -> Subquery Scan blubb (cost=15254815.03..16082881.99 rows=55204464 width=8) +> -> Unique (cost=15254815.03..15530837.35 rows=55204464 width=8) +> -> Sort (cost=15254815.03..15392826.19 rows=55204464 width=8) +> Sort Key: id +> -> Append (cost=0.00..6810225.28 rows=55204464 width=8) +> -> Subquery Scan "*SELECT* 1" (cost=0.00..3405112.64 rows=27602232 width=8) +> -> Seq Scan on streets (cost=0.00..3129090.32 rows=27602232 width=8) +> -> Subquery Scan "*SELECT* 2" (cost=0.00..3405112.64 rows=27602232 width=8) +> -> Seq Scan on streets (cost=0.00..3129090.32 rows=27602232 width=8) + +You can actually go one step further and do: + + select count(distinct id) from (select ... union all select ...) as blubb; + +I'm not sure why this is any faster since it still has to do all the same +work, but it's a different code path and it seems to be about 20% faster for +me. + +-- +greg + + +From pgsql-general-owner@postgresql.org Sat Sep 11 05:38:59 2004 +X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 5C91C5E4A54 + for ; + Sat, 4 Sep 2004 04:52:14 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 11750-03 + for ; + Sat, 4 Sep 2004 03:52:10 +0000 (GMT) +Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) + by svr1.postgresql.org (Postfix) with ESMTP id D0B8C5E520A + for ; + Sat, 4 Sep 2004 04:26:08 +0100 (BST) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by svr4.postgresql.org (Postfix) with ESMTP id 88FF85B0908 + for ; + Fri, 3 Sep 2004 17:06:06 +0000 (GMT) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by news.hub.org (8.12.9/8.12.9) with ESMTP id i83H3YLq059999 + for ; Fri, 3 Sep 2004 17:03:34 GMT + (envelope-from news@news.hub.org) +Received: (from news@localhost) + by news.hub.org (8.12.9/8.12.9/Submit) id i83Gia4L039326 + for pgsql-general@postgresql.org; Fri, 3 Sep 2004 16:44:36 GMT +From: "Shane Wright" +X-Newsgroups: comp.databases.postgresql.general +Subject: disk performance benchmarks +Date: 3 Sep 2004 09:44:36 -0700 +Organization: http://groups.google.com +Lines: 43 +Message-ID: +Mime-Version: 1.0 +Content-Type: text/plain; charset="iso-8859-1" +X-Complaints-To: groups-abuse@google.com +User-Agent: G2/0.1 +To: pgsql-general@postgresql.org +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/485 +X-Sequence-Number: 65691 + +Hi, + +I've been trying to spec a new server for my company's database for a +few weeks and one of the biggest problems I've had is trying to find +meaningful performance information about how PostgreSQL will perfom +under various disk configurations. + +But, we have now taken the plunge and I'm in a position to do some +benchmarking to actually get some data. Basically I was wondering if +anyone else had any particular recommendations (or requests) about the +most useful kinds of benchmarks to do. + + +The hardware I'll be benchmarking on is... + +server 1: single 2.8Ghz Xeon, 2Gb RAM. Adaptec 2410SA SATA hardware +RAID, with 4 x 200Gb 7200rpm WD SATA drives. RAID in both RAID5 and +RAID10 (currently RAID5, but want to experiment with write performance +in RAID10). Gentoo Linux + +server 2: single 2.6Ghz Xeon, 2Gb RAM, single 80Gb IDE drive. Redhat +Linux + +server 3: dual 2.6Ghz Xeon, 6Gb RAM, software RAID10 with 4 x 36Gb +10kRPM U320 SCSI drives, RedHat Linux + + +I realise the boxes aren't all identical - but some benchmarks on those +should give some ballpark figures for anyone else speccing out a +low-mid range box and wanting some performance figures on IDE vs IDE +RAID vs SCSI RAID + +I'd be more than happy to post any results back to the list, and if +anyone else can contribute any other data points that'd be great. + +Otherwise, any pointers to a quick/easy setup for some vaguely useful +benchmarks would be great. At the moment I'm thinking just along the +lines of 'pgbench -c 10 -s 100 -v'. + +Cheers + +Shane + + +From pgsql-performance-owner@postgresql.org Sat Sep 4 04:58:10 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 446AF5E4A82 + for ; + Sat, 4 Sep 2004 04:57:10 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 15343-10 + for ; + Sat, 4 Sep 2004 03:57:07 +0000 (GMT) +Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) + by svr1.postgresql.org (Postfix) with ESMTP id 172EF5E4A8D + for ; + Sat, 4 Sep 2004 04:26:59 +0100 (BST) +Received: from Herge.rcsinc.local (mail.rcsonline.com [205.217.85.91]) + by svr4.postgresql.org (Postfix) with ESMTP id A21015B090F + for ; + Fri, 3 Sep 2004 17:09:14 +0000 (GMT) +Content-class: urn:content-classes:message +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: quoted-printable +Subject: Re: fsync vs open_sync +X-MimeOLE: Produced By Microsoft Exchange V6.5.6944.0 +Date: Fri, 3 Sep 2004 13:08:24 -0400 +Message-ID: <6EE64EF3AB31D5448D0007DD34EEB3412A749A@Herge.rcsinc.local> +X-MS-Has-Attach: +X-MS-TNEF-Correlator: +Thread-Topic: [PERFORM] fsync vs open_sync +Thread-Index: AcSBYgClh+KM1mTQRmm9nDeFFsXCqQACwtQQBBq+5tA= +From: "Merlin Moncure" +To: =?iso-8859-1?Q?Pierre-Fr=E9d=E9ric_Caillaud?= + +Cc: +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/21 +X-Sequence-Number: 8149 + +> > There is also the fact that NTFS is a very slow filesystem, and +> > Linux is +> > a lot better than Windows for everything disk, caching and IO related. +> Try +> > to copy some files in NTFS and in ReiserFS... +>=20 +> I'm not so sure I would agree with such a blanket generalization. I find +> NTFS to be very fast, my main complaint is fragmentation issues...I bet +> NTFS is better than ext3 at most things (I do agree with you about the +> cache, thoughO. + +Ok, you were right. I made some tests and NTFS is just not very good in th= +e general case. I've seen some benchmarks for Reiser4 that are just amazin= +g. + +Merlin + +From pgsql-performance-owner@postgresql.org Sat Sep 4 05:03:03 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 574215E4DA0 + for ; + Sat, 4 Sep 2004 05:02:49 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 21862-05 + for ; + Sat, 4 Sep 2004 04:02:45 +0000 (GMT) +Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) + by svr1.postgresql.org (Postfix) with ESMTP id 8FC355E555B + for ; + Sat, 4 Sep 2004 04:28:03 +0100 (BST) +Received: from boutiquenumerique.com (gailleton-2-82-67-9-10.fbx.proxad.net + [82.67.9.10]) + by svr4.postgresql.org (Postfix) with ESMTP id CE75C5B09ED + for ; + Fri, 3 Sep 2004 18:26:18 +0000 (GMT) +Received: (qmail 28261 invoked from network); 3 Sep 2004 20:24:18 +0200 +Received: from unknown (HELO musicbox) (192.168.0.2) + by gailleton-2-82-67-9-10.fbx.proxad.net with SMTP; + 3 Sep 2004 20:24:18 +0200 +Date: Fri, 03 Sep 2004 20:24:27 +0200 +To: "Merlin Moncure" +Subject: Re: fsync vs open_sync +Cc: pgsql-performance@postgresql.org +References: <6EE64EF3AB31D5448D0007DD34EEB3412A749A@Herge.rcsinc.local> +From: =?iso-8859-15?Q?Pierre-Fr=E9d=E9ric_Caillaud?= + +Organization: =?iso-8859-15?Q?La_Boutique_Num=E9rique?= +Content-Type: text/plain; format=flowed; delsp=yes; charset=iso-8859-15 +MIME-Version: 1.0 +Content-Transfer-Encoding: 8bit +Message-ID: +In-Reply-To: <6EE64EF3AB31D5448D0007DD34EEB3412A749A@Herge.rcsinc.local> +User-Agent: Opera M2/7.53 (Linux, build 737) +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/22 +X-Sequence-Number: 8150 + +>> > There is also the fact that NTFS is a very slow filesystem, and +>> > Linux is +>> > a lot better than Windows for everything disk, caching and IO related. +>> Try +>> > to copy some files in NTFS and in ReiserFS... +>> +>> I'm not so sure I would agree with such a blanket generalization. I +>> find +>> NTFS to be very fast, my main complaint is fragmentation issues...I bet +>> NTFS is better than ext3 at most things (I do agree with you about the +>> cache, thoughO. +> +> Ok, you were right. I made some tests and NTFS is just not very good in +> the general case. I've seen some benchmarks for Reiser4 that are just +> amazing. + + As a matter of fact I was again amazed today. + I was looking into a way to cache database queries for a website (not +yet) written in Python. The purpose was to cache long queries like those +used to render forum pages (which is the typical slow query, selecting + from a big table where records are rather random and LIMIT is used to cut +the result in pages). + I wanted to save a serialized (python pickled) representation of the data +to disk to avoid reissuing the query every time. + In the end it took about 1 ms to load or save the data for a page with 40 +posts... then I wondered, how much does it take just to read or write the +file ? + + ReiserFS 3.6, Athlon XP 2.5G+, 512Mb DDR400 + 7200 RPM IDE Drive with 8MB Cache + This would be considered a very underpowered server... + + 22 KB files, 1000 of them : + open(), read(), close() : 10.000 files/s + open(), write(), close() : 4.000 files/s + + This is quite far from database FS activity, but it's still amazing, +although the disk doesn't even get used. Which is what I like in Linux. +You can write 10000 files in one second and the HDD is still idle... then +when it decides to flush it all goes to disk in one burst. + + I did make benchmarks some time ago and found that what sets Linux apart + from Windows in terms of filesystems is : + - very high performance filesystems like ReiserFS + This is the obvious part ; although with a huuuuge amount of data in +small files accessed randomly, ReiserFS is faster but not 10x, maybe +something like 2x NTFS. I trust Reiser4 to offer better performance, but +not right now. Also ReiserFS lacks a defragmenter, and it gets slower +after 1-2 years (compared to 1-2 weeks with NTFS this is still not that +bad, but I'd like to defragment and I cant). Reiser4 will fix that +apparently with background defragger etc. + + - caching. + Linux disk caching is amazing. When copying a large file to the same disk +on Windows, the drive head swaps a lot, like the OS can't decide between +reading and writing. Linux, on the other hand, reads and writes by large +chunks and loses a lot less time seekng. Even when reading two files at +the same time, Linux reads ahead in large chunks (very little performance +loss) whereas Windows seeks a lot. The read-ahead and write-back thus gets +it a lot faster than 2x NTFS for everyday tasks like copying files, +backing up, making archives, grepping, serving files, etc... + My windows box was able to saturate a 100Mbps ethernet while serving one +large FTP file on the LAN (not that impressive, it's only 10 MB/s hey!). +However, when several simultaneous clients were trying to download +different files which were not in the disk cache, all hell broke loose : +lots of seeking, and bandwidth dropped to 30 Mbits/s. Not enough +read-ahead... + The Linux box, serving FTP, with half the RAM (256 Mb), had no problem +pushing the 100 Mbits/s with something like 10 simultaneous connections. +The amusing part is that I could not use the Windows box to test it +because it would choke at such a "high" IO concurrency (writing 10 +MBytes/s to several files at once, my god). + Of course the files which had been downloaded to the Windows box were cut +in as many fragments as the number of disk seeks during the download... +several hundred fragments each... my god... + + What amazes me is that it must just be some parameter somewhere and the +Microsoft guys probably could have easily changed the read-ahead +thresholds and time between seeks when in a multitasking environment, but +they didn't. Why ? + + Thus people are forced to buy 10000RPM SCSI drives for their LAN servers +when an IDE raid, used with Linux, could push nearly a Gigabit... + + For database, this is different, as we're concerned about large files, +and fsync() times... but it seems reiserfs still wins over ext3 so... + + About NTFS vs EXT3 : ext3 dies if you put a lot of files in the same +directory. It's fast but still outperformed by reiser. + + I saw XFS fry eight 7 harddisk RAID bays. The computer was rebooted with +the Reset button a few times because a faulty SCSI cable in the eighth +RAID bay was making it hang. The 7 bays had no problem. When it went back +up, all the bays were in mayhem. XFSrepair just vomited over itself and we +got plenty of files with random data in them. Fortunately there was a +catalog of files with their checksums so at least we could know which +files were okay. Have you tried restoring that amount of data from a +backup ? + + Now maybe this was just bad luck and crap hardware, but I still won't +touch XFS. Amazing performance on large files though... + + I've had my computers shutdown violently by power failures and no +reiserfs problems so far. NTFS is very crash proof too. My windows machine +bluescreens twice a day and still no data loss ;) + + Upside : an junkyard UPS with dead batteries, powered with two brand new +12V car batteries, costs 70 euro and powers a computer for more than 5 +hours... + Downside : + - it's ugly (I hide it under my desk) + - you "borrow" a battery to start your friend's car, and just five +minutes later, the UPS wants to test itself, discovered it has no more +batteries, and switches everything off... argh. + + Good evening... + + + + + + + + + + + + + + + +From pgsql-performance-owner@postgresql.org Sat Sep 4 04:40:40 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 441E25E49E6 + for ; + Sat, 4 Sep 2004 04:40:38 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 97570-09 + for ; + Sat, 4 Sep 2004 03:40:33 +0000 (GMT) +Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) + by svr1.postgresql.org (Postfix) with ESMTP id D77415E4EFA + for ; + Sat, 4 Sep 2004 04:24:38 +0100 (BST) +Received: from lorax.kcilink.com (lorax.kciLink.com [206.112.95.1]) + by svr4.postgresql.org (Postfix) with ESMTP id 5C5795B0ABF + for ; + Fri, 3 Sep 2004 19:43:46 +0000 (GMT) +Received: from localhost (localhost [127.0.0.1]) + by lorax.kcilink.com (Postfix) with ESMTP id 3C2014025 + for ; + Fri, 3 Sep 2004 15:42:45 -0400 (EDT) +Received: from lorax.kcilink.com ([127.0.0.1]) + by localhost (lorax.kcilink.com [127.0.0.1]) (amavisd-new, port 10024) + with LMTP id 91299-02 for ; + Fri, 3 Sep 2004 15:42:44 -0400 (EDT) +Received: by lorax.kcilink.com (Postfix, from userid 8) + id AA86D4003; Fri, 3 Sep 2004 15:42:44 -0400 (EDT) +To: pgsql-performance@postgresql.org +Path: not-for-mail +From: Vivek Khera +Newsgroups: ml.postgres.performance +Subject: restoring to wrong encoding db +Date: Fri, 03 Sep 2004 15:42:44 -0400 +Organization: Khera Communications, Inc., Rockville, MD +Lines: 23 +Message-ID: +NNTP-Posting-Host: yertle.kcilink.com +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Trace: lorax.kcilink.com 1094240564 1474 65.205.34.180 (3 Sep 2004 19:42:44 + GMT) +X-Complaints-To: daemon@kciLink.com +NNTP-Posting-Date: Fri, 3 Sep 2004 19:42:44 +0000 (UTC) +User-Agent: Gnus/5.1002 (Gnus v5.10.2) XEmacs/21.4 (Security Through + Obscurity, berkeley-unix) +Cancel-Lock: sha1:MtgJ+EpPcLNxIP/sKpPQQ977/GA= +X-Virus-Scanned: by amavisd-new at kcilink.com +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/20 +X-Sequence-Number: 8148 + +I was just copying a database that was in UNICODE encoding into a new +db for some testing. I hand't realized it was UNICODE and when it hit +some funky chinese data (from some spam that came in...) it errored +out with a string too long for a varchar(255). + +The dump was created on PG 7.4.3 with "pg_dump -Fc" + +The db was created with "createdb rt3" + +The restore was to PG 7.4.5 with "pg_restore --verbose -d rt3 rt3.dump" + + +Is there some way for the dump to notice that the encoding is wrong in +the db into which it is being restored? Once I created the rt3 db +with encoding='UNICODE' it worked just fine. Should there be some +kind of check like that? + + +-- +=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +Vivek Khera, Ph.D. Khera Communications, Inc. +Internet: khera@kciLink.com Rockville, MD +1-301-869-4449 x806 +AIM: vivekkhera Y!: vivek_khera http://www.khera.org/~vivek/ + +From pgsql-performance-owner@postgresql.org Sat Sep 4 14:07:29 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 96C6A5E4E37 + for ; + Sat, 4 Sep 2004 14:07:26 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 24499-03 + for ; + Sat, 4 Sep 2004 13:06:25 +0000 (GMT) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by svr1.postgresql.org (Postfix) with ESMTP id 48E2B5E4A79 + for ; + Sat, 4 Sep 2004 14:05:58 +0100 (BST) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by news.hub.org (8.12.9/8.12.9) with ESMTP id i84D3fLu025475 + for ; Sat, 4 Sep 2004 13:05:27 GMT + (envelope-from news@news.hub.org) +Received: (from news@localhost) + by news.hub.org (8.12.9/8.12.9/Submit) id i84CbDVV022209 + for pgsql-performance@postgresql.org; Sat, 4 Sep 2004 12:37:13 GMT +From: Gaetano Mendola +X-Newsgroups: comp.databases.postgresql.performance +Subject: Re: fsync vs open_sync +Date: Sat, 04 Sep 2004 12:43:33 +0200 +Organization: PYRENET Midi-pyrenees Provider +Lines: 32 +Message-ID: <41399C55.6050900@bigfoot.com> +References: <6EE64EF3AB31D5448D0007DD34EEB3412A749A@Herge.rcsinc.local> + +Mime-Version: 1.0 +Content-Type: text/plain; charset=ISO-8859-15; format=flowed +Content-Transfer-Encoding: 8bit +X-Complaints-To: abuse@pyrenet.fr +To: =?ISO-8859-15?Q?Pierre-Fr=E9d=E9ric_Caillaud?= + +User-Agent: Mozilla Thunderbird 0.7.3 (Windows/20040803) +X-Accept-Language: en-us, en +In-Reply-To: +X-Enigmail-Version: 0.85.0.0 +X-Enigmail-Supports: pgp-inline, pgp-mime +To: pgsql-performance@postgresql.org +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, + hits=1.1 tagged_above=0.0 required=5.0 tests=NO_DNS_FOR_FROM +X-Spam-Level: * +X-Archive-Number: 200409/23 +X-Sequence-Number: 8151 + +Pierre-Fr�d�ric Caillaud wrote: + +> 22 KB files, 1000 of them : +> open(), read(), close() : 10.000 files/s +> open(), write(), close() : 4.000 files/s +> +> This is quite far from database FS activity, but it's still +> amazing, although the disk doesn't even get used. Which is what I like +> in Linux. You can write 10000 files in one second and the HDD is still +> idle... then when it decides to flush it all goes to disk in one burst. + +You can not trust your data in this. + + +> I've had my computers shutdown violently by power failures and no +> reiserfs problems so far. NTFS is very crash proof too. My windows +> machine bluescreens twice a day and still no data loss ;) + +If you have the BSOD twice a day then you have a broken driver or broken +HW. CPU overclocked ? + + +I understood from your email that you are a Windows haters, try to post +something here: + +http://ihatelinux.blogspot.com/ + +:-) + + +Regards +Gaetano Mendola + +From pgsql-performance-owner@postgresql.org Sun Sep 5 03:46:42 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id C292A5E3F15 + for ; + Sun, 5 Sep 2004 03:46:38 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 81757-09 + for ; + Sun, 5 Sep 2004 02:46:36 +0000 (GMT) +Received: from jinx.internetstaff.com (jinx.internetstaff.com + [63.214.174.240]) + by svr1.postgresql.org (Postfix) with ESMTP id 7BFCE5E3632 + for ; + Sun, 5 Sep 2004 03:46:28 +0100 (BST) +Received: from localhost (localhost [127.0.0.1]) + by jinx.internetstaff.com (Postfix) with ESMTP id 055854BC0A1 + for ; + Sat, 4 Sep 2004 19:46:44 -0700 (MST) +Received: from jinx.internetstaff.com ([127.0.0.1]) + by localhost (jinx [127.0.0.1]) (amavisd-new, port 10024) with LMTP + id 11589-01-3 for ; + Sat, 4 Sep 2004 19:46:43 -0700 (MST) +Subject: Re: fsync vs open_sync +From: Cott Lang +To: pgsql-performance@postgresql.org +In-Reply-To: <41399C55.6050900@bigfoot.com> +References: <6EE64EF3AB31D5448D0007DD34EEB3412A749A@Herge.rcsinc.local> + <41399C55.6050900@bigfoot.com> +Content-Type: text/plain +Message-Id: <1094352401.3553.3.camel@localhost> +Mime-Version: 1.0 +X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) +Date: Sat, 04 Sep 2004 19:46:41 -0700 +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at internetstaff.com +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/24 +X-Sequence-Number: 8152 + +Another possibly useless datapoint on this thread for anyone who's +curious ... open_sync absolutely stinks over NFS at least on Linux. :) + + + + + +From pgsql-performance-owner@postgresql.org Sun Sep 5 05:04:11 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 13E9F5E4728 + for ; + Sun, 5 Sep 2004 05:04:05 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 99335-08 + for ; + Sun, 5 Sep 2004 04:03:55 +0000 (GMT) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by svr1.postgresql.org (Postfix) with ESMTP id 340255E3632 + for ; + Sun, 5 Sep 2004 05:03:54 +0100 (BST) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by news.hub.org (8.12.9/8.12.9) with ESMTP id i8543sLq003039 + for ; Sun, 5 Sep 2004 04:03:54 GMT + (envelope-from news@news.hub.org) +Received: (from news@localhost) + by news.hub.org (8.12.9/8.12.9/Submit) id i853o369000334 + for pgsql-performance@postgresql.org; Sun, 5 Sep 2004 03:50:03 GMT +From: Christopher Browne +X-Newsgroups: comp.databases.postgresql.performance +Subject: Re: fsync vs open_sync +Date: Sat, 04 Sep 2004 23:47:55 -0400 +Organization: cbbrowne Computing Inc +Lines: 37 +Message-ID: +References: <6EE64EF3AB31D5448D0007DD34EEB3412A749A@Herge.rcsinc.local> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Complaints-To: usenet@news.hub.org +X-message-flag: Outlook is rather hackable, isn't it? +X-Home-Page: http://www.cbbrowne.com/info/ +X-Affero: http://svcs.affero.net/rm.php?r=cbbrowne +User-Agent: Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.4 (Security Through + Obscurity, + linux) +Cancel-Lock: sha1:4h0kpnmNHaaKE7Qf1XqY0u7vFAw= +To: pgsql-performance@postgresql.org +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/25 +X-Sequence-Number: 8153 + +The world rejoiced as merlin.moncure@rcsonline.com ("Merlin Moncure") wrote: +> Ok, you were right. I made some tests and NTFS is just not very +> good in the general case. I've seen some benchmarks for Reiser4 +> that are just amazing. + +Reiser4 has been sounding real interesting. + +The killer problem is thus: + + "We must caution that just as Linux 2.6 is not yet as stable as + Linux 2.4, it will also be some substantial time before V4 is as + stable as V3." + +In practice, there's a further problem. + +We have some systems at work we need to connect to EMC disk arrays; +that's something that isn't supported by EMC unless you're using a +whole set of pieces that are "officially supported." + +RHAT doesn't want to talk to you about support for anything other than +ext3. + +I'm not sure what all SuSE supports; they're about the only other Linx +vendor that EMC would support, and I don't expect that Reiser4 yet +fits into the "supportable" category :-(. + +The upshot of that is that this means that we'd only consider using +stuff like Reiser4 on "toy" systems, and, quite frankly, that means +that they'll have "toy" disk as opposed to the good stuff :-(. + +And frankly, we're too busy with issues nearer to our hearts than +testing out ReiserFS. :-( +-- +output = ("cbbrowne" "@" "cbbrowne.com") +http://cbbrowne.com/info/emacs.html +"Linux! Guerrilla Unix Development Venimus, Vidimus, Dolavimus." +-- Mark A. Horton KA4YBR + +From pgsql-performance-owner@postgresql.org Sun Sep 5 05:07:45 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id A89D75E40BA + for ; + Sun, 5 Sep 2004 05:07:44 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 00394-07 + for ; + Sun, 5 Sep 2004 04:07:36 +0000 (GMT) +Received: from internalmx.vasoftware.com (internalmx1.vasoftware.com + [12.152.184.149]) + by svr1.postgresql.org (Postfix) with ESMTP id 8F2D45E3632 + for ; + Sun, 5 Sep 2004 05:07:34 +0100 (BST) +Received: from c-24-6-104-166.client.comcast.net ([24.6.104.166]:52878 + helo=[192.168.1.100]) by internalmx.vasoftware.com with asmtp + (Cipher TLSv1:RC4-SHA:128) (Exim 4.22 #1 (Debian)) + id 1C3oJS-0003dY-T4 by VAauthid with fixed_plain + for ; Sat, 04 Sep 2004 21:07:34 -0700 +Mime-Version: 1.0 (Apple Message framework v619) +Content-Transfer-Encoding: 7bit +Message-Id: <18A61C72-FEF1-11D8-8BA3-000A95C4BD7A@sf.net> +Content-Type: text/plain; charset=US-ASCII; format=flowed +To: pgsql-performance@postgresql.org +From: Adi Alurkar +Subject: Dump/Restore performance improvement +Date: Sat, 4 Sep 2004 21:07:26 -0700 +X-Mailer: Apple Mail (2.619) +X-Spam-Score-Int: -974 +X-EA-Verified: internalmx.vasoftware.com 1C3oJS-0003dY-T4 + 103c031c6c14a74360d95a015ac5fe95 +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/26 +X-Sequence-Number: 8154 + +Greetings, + +I have observed that in a dump/restore scenario the longest time is +spent on index creation for larger tables, I have a suggestion of how +the performance could be improved thus reducing the time to recover +from a crash. Not sure if this is possible but would definitely be a +nice addition to the TODO list. + +1) Add a new config paramter e.g work_maintanence_max_mem this will +the max memory postgresql *can* claim if need be. + +2) During the dump phase of the DB postgresql estimates the +"work_maintenance_mem" that would be required to create the index in +memory(if possible) and add's a +SET work_maintenance_mem="the value calculated" (IF this value is less +than work_maintanence_max_mem. ) + +3) During the restore phase the appropriate memory is allocated in RAM +and the index creation takes less time since PG does not have to sort +on disk. + +-- +Adi Alurkar (DBA sf.NET) +1024D/79730470 A491 5724 74DE 956D 06CB D844 6DF1 B972 7973 0470 + + +From pgsql-performance-owner@postgresql.org Sun Sep 5 06:16:55 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 2ABA55E48F4 + for ; + Sun, 5 Sep 2004 06:16:54 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 13844-01 + for ; + Sun, 5 Sep 2004 05:16:45 +0000 (GMT) +Received: from fed1rmmtao06.cox.net (fed1rmmtao06.cox.net [68.230.241.33]) + by svr1.postgresql.org (Postfix) with ESMTP id 772225E48FB + for ; + Sun, 5 Sep 2004 06:16:43 +0100 (BST) +Received: from [68.12.228.23] by fed1rmmtao06.cox.net + (InterMail vM.6.01.03.02.01 201-2131-111-104-103-20040709) with ESMTP + id <20040905051642.LLXU2550.fed1rmmtao06.cox.net@[68.12.228.23]>; + Sun, 5 Sep 2004 01:16:42 -0400 +Subject: Re: fsync vs open_sync +From: Steve Bergman +To: Christopher Browne +Cc: pgsql-perform +In-Reply-To: +References: <6EE64EF3AB31D5448D0007DD34EEB3412A749A@Herge.rcsinc.local> + +Content-Type: text/plain +Date: Sun, 05 Sep 2004 00:16:42 -0500 +Message-Id: <1094361402.28425.31.camel@voyager.localdomain> +Mime-Version: 1.0 +X-Mailer: Evolution 1.5.94.1 (1.5.94.1-1) +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/27 +X-Sequence-Number: 8155 + +On Sat, 2004-09-04 at 23:47 -0400, Christopher Browne wrote: +> The world rejoiced as merlin.moncure@rcsonline.com ("Merlin Moncure") wrote: +> > Ok, you were right. I made some tests and NTFS is just not very +> > good in the general case. I've seen some benchmarks for Reiser4 +> > that are just amazing. +> +> Reiser4 has been sounding real interesting. +> + +Are these independent benchmarks, or the benchmarketing at namesys.com? +Note that the APPEND, MODIFY, and OVERWRITE phases have been turned off +on the mongo tests and the other tests have been set to a lexical (non +default for mongo) mode. I've done some mongo benchmarking myself and +reiser4 loses to ext3 (data=ordered) in the excluded tests. APPEND +phase performance is absolutely *horrible*. So they just turned off the +phases in which reiser4 lost and published the remaining results as +proof that "resier4 is the fastest filesystem". + +See: http://marc.theaimsgroup.com/?l=reiserfs&m=109363302000856 + + +-Steve Bergman + + + +From pgsql-performance-owner@postgresql.org Sun Sep 5 17:52:39 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id A724E5E4924 + for ; + Sun, 5 Sep 2004 17:52:36 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 06786-05 + for ; + Sun, 5 Sep 2004 16:52:33 +0000 (GMT) +Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) + by svr1.postgresql.org (Postfix) with ESMTP id 8B00D5E4923 + for ; + Sun, 5 Sep 2004 17:52:02 +0100 (BST) +Received: from rhws.home.edu (66-23-211-34.clients.speedfactory.net + [66.23.211.34]) + by svr4.postgresql.org (Postfix) with ESMTP id 4BEA45AF2DC + for ; + Sun, 5 Sep 2004 11:43:31 +0000 (GMT) +Received: from [127.0.0.1] (rhws.home.edu [127.0.0.1]) + by rhws.home.edu (8.12.11/8.12.11) with ESMTP id i85BfTKP014050 + for ; Sun, 5 Sep 2004 07:41:29 -0400 +Message-ID: <413AFB69.2010106@3times25.net> +Date: Sun, 05 Sep 2004 07:41:29 -0400 +From: Geoffrey +User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.2) Gecko/20040803 +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: pgsql-performance@postgresql.org +Subject: Re: fsync vs open_sync +References: <6EE64EF3AB31D5448D0007DD34EEB3412A749A@Herge.rcsinc.local> + +In-Reply-To: +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/28 +X-Sequence-Number: 8156 + +Christopher Browne wrote: + +> I'm not sure what all SuSE supports; they're about the only other Linx +> vendor that EMC would support, and I don't expect that Reiser4 yet +> fits into the "supportable" category :-(. + +I use quite a bit of SuSE, and although I don't know their official +position on Reiser file systems, I do know that it is the default when +installing, so I'd suggest you might check into it. + + +-- +Until later, Geoffrey Registered Linux User #108567 + AT&T Certified UNIX System Programmer - 1995 + +From pgsql-performance-owner@postgresql.org Sun Sep 5 18:07:47 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 1A2C25E48E8 + for ; + Sun, 5 Sep 2004 18:07:46 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 14141-10 + for ; + Sun, 5 Sep 2004 17:07:43 +0000 (GMT) +Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) + by svr1.postgresql.org (Postfix) with ESMTP id 23BA05E48E7 + for ; + Sun, 5 Sep 2004 18:07:43 +0100 (BST) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i85H7iib029497; + Sun, 5 Sep 2004 13:07:44 -0400 (EDT) +To: Adi Alurkar +Cc: pgsql-performance@postgresql.org +Subject: Re: Dump/Restore performance improvement +In-reply-to: <18A61C72-FEF1-11D8-8BA3-000A95C4BD7A@sf.net> +References: <18A61C72-FEF1-11D8-8BA3-000A95C4BD7A@sf.net> +Comments: In-reply-to Adi Alurkar + message dated "Sat, 04 Sep 2004 21:07:26 -0700" +Date: Sun, 05 Sep 2004 13:07:43 -0400 +Message-ID: <29496.1094404063@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/29 +X-Sequence-Number: 8157 + +Adi Alurkar writes: +> 1) Add a new config paramter e.g work_maintanence_max_mem this will +> the max memory postgresql *can* claim if need be. + +> 2) During the dump phase of the DB postgresql estimates the +> "work_maintenance_mem" that would be required to create the index in +> memory(if possible) and add's a +> SET work_maintenance_mem="the value calculated" (IF this value is less +> than work_maintanence_max_mem. ) + +This seems fairly pointless to me. How is this different from just +setting maintenance_work_mem as large as you can stand before importing +the dump? + +Making any decisions at dump time seems wrong to me in the first place; +pg_dump should not be expected to know what conditions the restore will +be run under. I'm not sure that's what you're proposing, but I don't +see what the point is in practice. It's already the case that +maintenance_work_mem is treated as the maximum memory you can use, +rather than what you will use even if you don't need it all. + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Sun Sep 5 19:01:12 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id D029E5E48C1 + for ; + Sun, 5 Sep 2004 19:01:11 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 29412-09 + for ; + Sun, 5 Sep 2004 18:01:09 +0000 (GMT) +Received: from boutiquenumerique.com (gailleton-2-82-67-9-10.fbx.proxad.net + [82.67.9.10]) + by svr1.postgresql.org (Postfix) with ESMTP id 027955E48BE + for ; + Sun, 5 Sep 2004 19:01:08 +0100 (BST) +Received: (qmail 7774 invoked from network); 5 Sep 2004 20:01:12 +0200 +Received: from unknown (HELO musicbox) (192.168.0.2) + by gailleton-2-82-67-9-10.fbx.proxad.net with SMTP; + 5 Sep 2004 20:01:12 +0200 +Date: Sun, 05 Sep 2004 20:01:30 +0200 +To: pgsql-performance@postgresql.org +Subject: Re: fsync vs open_sync +References: <6EE64EF3AB31D5448D0007DD34EEB3412A749A@Herge.rcsinc.local> + <41399C55.6050900@bigfoot.com> +From: =?iso-8859-15?Q?Pierre-Fr=E9d=E9ric_Caillaud?= + +Organization: =?iso-8859-15?Q?La_Boutique_Num=E9rique?= +Content-Type: text/plain; format=flowed; delsp=yes; charset=iso-8859-15 +MIME-Version: 1.0 +Content-Transfer-Encoding: 8bit +Message-ID: +In-Reply-To: <41399C55.6050900@bigfoot.com> +User-Agent: Opera M2/7.53 (Linux, build 737) +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/30 +X-Sequence-Number: 8158 + + + Were you upset by my message ? I'll try to clarify. + +> I understood from your email that you are a Windows haters + + Well, no, not really. I use Windows everyday and it has its strengths. I +still don't think the average (non-geek) person can really use Linux as a +Desktop OS. The problem I have with Windows is that I think it could be +made much faster, without too much effort (mainly some tweaking in the +Disk IO field), but Microsoft doesn't do it. Why ? I can't understand this. + +>> in Linux. You can write 10000 files in one second and the HDD is still +>> idle... then when it decides to flush it all goes to disk in one burst. +> +> You can not trust your data in this. + + That's why I mentioned that it did not relate to database type +performance. If the computer crashes while writing these files, some may +be partially written, some not at all, some okay... the only certainty is +about filesystem integrity. But it's exactly the same on all Journaling +filesystems (including NTFS). Thus, with equal reliability, the faster +wins. Maybe, with Reiser4, we will see real filesystem transactions and +maybe this will translate in higher postgres performance... +> +>> I've had my computers shutdown violently by power failures and no +>> reiserfs problems so far. NTFS is very crash proof too. My windows +>> machine bluescreens twice a day and still no data loss ;) +> +> If you have the BSOD twice a day then you have a broken driver or broken +> HW. CPU overclocked ? + + I think this machine has crap hardware. In fact this example was to +emphasize the reliability of NTFS : it is indeed remarkable that no data +loss occurs even on such a crap machine. I know Windows has got quite +reliable now. + + + + + + +From pgsql-performance-owner@postgresql.org Sun Sep 5 19:02:45 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id D2E735E48BF + for ; + Sun, 5 Sep 2004 19:02:44 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 30603-09 + for ; + Sun, 5 Sep 2004 18:02:42 +0000 (GMT) +Received: from boutiquenumerique.com (gailleton-2-82-67-9-10.fbx.proxad.net + [82.67.9.10]) + by svr1.postgresql.org (Postfix) with ESMTP id 604335E4893 + for ; + Sun, 5 Sep 2004 19:02:42 +0100 (BST) +Received: (qmail 7845 invoked from network); 5 Sep 2004 20:02:46 +0200 +Received: from unknown (HELO musicbox) (192.168.0.2) + by gailleton-2-82-67-9-10.fbx.proxad.net with SMTP; + 5 Sep 2004 20:02:46 +0200 +To: pgsql-performance@postgresql.org +Subject: Re: fsync vs open_sync +References: <6EE64EF3AB31D5448D0007DD34EEB3412A749A@Herge.rcsinc.local> + <413AFB69.2010106@3times25.net> +Message-ID: +From: =?iso-8859-15?Q?Pierre-Fr=E9d=E9ric_Caillaud?= + +Organization: =?iso-8859-15?Q?La_Boutique_Num=E9rique?= +Content-Type: text/plain; format=flowed; delsp=yes; charset=iso-8859-15 +MIME-Version: 1.0 +Content-Transfer-Encoding: 8bit +Date: Sun, 05 Sep 2004 20:03:04 +0200 +In-Reply-To: <413AFB69.2010106@3times25.net> +User-Agent: Opera M2/7.53 (Linux, build 737) +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/31 +X-Sequence-Number: 8159 + + + I trust ReiserFS 3. + I wouldn't trust the 4 before maybe 1-2 years. + +On Sun, 05 Sep 2004 07:41:29 -0400, Geoffrey wrote: + +> Christopher Browne wrote: +> +>> I'm not sure what all SuSE supports; they're about the only other Linx +>> vendor that EMC would support, and I don't expect that Reiser4 yet +>> fits into the "supportable" category :-(. +> +> I use quite a bit of SuSE, and although I don't know their official +> position on Reiser file systems, I do know that it is the default when +> installing, so I'd suggest you might check into it. +> +> + + + +From pgsql-performance-owner@postgresql.org Mon Sep 6 00:28:09 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 812305E46E9 + for ; + Mon, 6 Sep 2004 00:28:08 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 67610-07 + for ; + Sun, 5 Sep 2004 23:28:06 +0000 (GMT) +Received: from morework.geizhals.at (home.geizhals.at [213.229.14.34]) + by svr1.postgresql.org (Postfix) with ESMTP id 6D1435E46F8 + for ; + Mon, 6 Sep 2004 00:28:02 +0100 (BST) +Received: from localhost (morework [127.0.0.1]) + by morework.geizhals.at (Postfix) with ESMTP id 9AD87DED21; + Mon, 6 Sep 2004 01:28:04 +0200 (CEST) +Received: from [192.168.0.3] (chello080110242194.117.11.tuwien.teleweb.at + [80.110.242.194]) by morework.geizhals.at (Postfix) with ESMTP; + Mon, 6 Sep 2004 01:28:04 +0200 (CEST) +Message-ID: <413BA104.1040508@geizhals.at> +Date: Mon, 06 Sep 2004 01:28:04 +0200 +From: "Marinos J. Yannikos" +User-Agent: Mozilla Thunderbird 0.7.3 (Windows/20040803) +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: Ron St-Pierre +Cc: pgsql-performance@postgresql.org +Subject: Re: Table UPDATE is too slow +References: <4134BF36.3000504@syscor.com> +In-Reply-To: <4134BF36.3000504@syscor.com> +Content-Type: text/plain; charset=ISO-8859-1; format=flowed +Content-Transfer-Encoding: 8bit +X-Virus-Scanned: by amavisd-new-20030616-p10 at geizhals.at +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/32 +X-Sequence-Number: 8160 + +Ron St-Pierre wrote: + +> We have a web based application with data that is updated daily. The +> biggest bottleneck occurs when we try to update +> one of the tables. This table contains 58,000 rows and 62 columns, and +> EVERY column is indexed. + +Have you thought of / tried using 2 separate databases or tables and +switching between them? Since you seem to be updating all the values, it +might be a lot faster to re-create the table from scratch without +indexes and add those later (maybe followed by a VACUUM ANALYZE) ... + +That said, I'm not entirely sure how well postgres' client libraries can +deal with tables being renamed while in use, perhaps someone can shed +some light on this. + +Regards, + Marinos +-- +Dipl.-Ing. Marinos Yannikos, CEO +Preisvergleich Internet Services AG +Obere Donaustra�e 63/2, A-1020 Wien +Tel./Fax: (+431) 5811609-52/-55 + +From pgsql-performance-owner@postgresql.org Mon Sep 6 02:35:02 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id C00515E46F8 + for ; + Mon, 6 Sep 2004 02:34:59 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 08544-03 + for ; + Mon, 6 Sep 2004 01:34:58 +0000 (GMT) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by svr1.postgresql.org (Postfix) with ESMTP id E3D395E4885 + for ; + Mon, 6 Sep 2004 02:34:56 +0100 (BST) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by news.hub.org (8.12.9/8.12.9) with ESMTP id i861YtCn009389 + for ; Mon, 6 Sep 2004 01:34:55 GMT + (envelope-from news@news.hub.org) +Received: (from news@localhost) + by news.hub.org (8.12.9/8.12.9/Submit) id i861FIqr004567 + for pgsql-performance@postgresql.org; Mon, 6 Sep 2004 01:15:18 GMT +From: Martin Foster +Organization: Ethereal Realms +User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; + rv:1.7.2) Gecko/20040803 +X-Accept-Language: en-us, en +MIME-Version: 1.0 +X-Newsgroups: comp.databases.postgresql.performance +Subject: Tanking a server with shared memory +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit +Lines: 21 +Message-ID: +Date: Mon, 06 Sep 2004 01:15:24 GMT +To: pgsql-performance@postgresql.org +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/34 +X-Sequence-Number: 8162 + +I have been experimenting with the 'IPC::Shareable' module under the +native implementation of Perl 5 for OpenBSD 3.5. While it is not loaded +by default it is a pure pure implementation. + +I have tested this module under two machines, one which used to run +PostgreSQL and has a higher then normal amount of SYSV semaphores. The +other has a normal amount, when testing under the former database server +things load up fine, clients can connect and all information is as it +should. + +When I test under the normal setup the machine tanks. No core dumps, +no errors produced, just a near instant lock-up of the server itself and +that is with a non-privileged user. + +While I know this is a Perl issue, but figured I might be able to gain +some insight on how a server could drop without at least generating a +panic. Any ideas? + + Martin Foster + Creator/Designer Ethereal Realms + martin@ethereal-realms.org + +From pgsql-performance-owner@postgresql.org Mon Sep 6 02:19:37 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id A6C675E4885 + for ; + Mon, 6 Sep 2004 02:19:35 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 04783-02 + for ; + Mon, 6 Sep 2004 01:19:34 +0000 (GMT) +Received: from mproxy.gmail.com (rproxy.gmail.com [64.233.170.200]) + by svr1.postgresql.org (Postfix) with ESMTP id B37595E48BB + for ; + Mon, 6 Sep 2004 02:19:31 +0100 (BST) +Received: by mproxy.gmail.com with SMTP id 73so144015rnk + for ; + Sun, 05 Sep 2004 18:19:35 -0700 (PDT) +Received: by 10.38.24.70 with SMTP id 70mr1147607rnx; + Sun, 05 Sep 2004 18:19:35 -0700 (PDT) +Received: by 10.38.165.47 with HTTP; Sun, 5 Sep 2004 18:19:35 -0700 (PDT) +Message-ID: +Date: Sun, 5 Sep 2004 20:19:35 -0500 +From: Kevin Barnard +Reply-To: Kevin Barnard +To: pgsql-performance@postgresql.org +Subject: Re: Table UPDATE is too slow +In-Reply-To: <413BA104.1040508@geizhals.at> +Mime-Version: 1.0 +Content-Type: text/plain; charset=ISO-8859-1 +Content-Transfer-Encoding: quoted-printable +References: <4134BF36.3000504@syscor.com> <413BA104.1040508@geizhals.at> +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/33 +X-Sequence-Number: 8161 + +Do all of the commands to swap tables in a transaction. =A0The table +gets locked briefly but should have a lot less impact then the update +command. + + +On Mon, 06 Sep 2004 01:28:04 +0200, Marinos J. Yannikos w= +rote: +>=20 +> That said, I'm not entirely sure how well postgres' client libraries can +> deal with tables being renamed while in use, perhaps someone can shed +> some light on this. +> + +From pgsql-performance-owner@postgresql.org Mon Sep 6 03:18:11 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 9183A5E487A + for ; + Mon, 6 Sep 2004 03:18:08 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 16991-10 + for ; + Mon, 6 Sep 2004 02:18:07 +0000 (GMT) +Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) + by svr1.postgresql.org (Postfix) with ESMTP id 6F0615E47FE + for ; + Mon, 6 Sep 2004 03:18:05 +0100 (BST) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i862I6fP003780; + Sun, 5 Sep 2004 22:18:06 -0400 (EDT) +To: Martin Foster +Cc: pgsql-performance@postgresql.org +Subject: Re: Tanking a server with shared memory +In-reply-to: +References: +Comments: In-reply-to Martin Foster + message dated "Mon, 06 Sep 2004 01:15:24 +0000" +Date: Sun, 05 Sep 2004 22:18:05 -0400 +Message-ID: <3779.1094437085@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/35 +X-Sequence-Number: 8163 + +Martin Foster writes: +> While I know this is a Perl issue, but figured I might be able to gain +> some insight on how a server could drop without at least generating a +> panic. Any ideas? + +The standard spelling for this is "kernel bug". Send a reproducible +example to the OpenBSD kernel maintainers. + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Mon Sep 6 13:16:44 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 7EBAA5E48CB + for ; + Mon, 6 Sep 2004 13:15:22 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 83225-08 + for ; + Mon, 6 Sep 2004 12:15:20 +0000 (GMT) +Received: from boutiquenumerique.com (gailleton-2-82-67-9-10.fbx.proxad.net + [82.67.9.10]) + by svr1.postgresql.org (Postfix) with ESMTP id EF4E85E46F8 + for ; + Mon, 6 Sep 2004 13:15:15 +0100 (BST) +Received: (qmail 29515 invoked from network); 6 Sep 2004 14:15:23 +0200 +Received: from unknown (HELO musicbox) (192.168.0.2) + by gailleton-2-82-67-9-10.fbx.proxad.net with SMTP; + 6 Sep 2004 14:15:23 +0200 +Date: Mon, 06 Sep 2004 14:15:44 +0200 +To: pgsql-performance@postgresql.org +Subject: The usual sequential scan, but with LIMIT ! +References: <4134BF36.3000504@syscor.com> <413BA104.1040508@geizhals.at> + +From: =?iso-8859-15?Q?Pierre-Fr=E9d=E9ric_Caillaud?= + +Organization: =?iso-8859-15?Q?La_Boutique_Num=E9rique?= +Content-Type: text/plain; format=flowed; delsp=yes; charset=iso-8859-15 +MIME-Version: 1.0 +Content-Transfer-Encoding: 8bit +Message-ID: +In-Reply-To: +User-Agent: Opera M2/7.53 (Linux, build 737) +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/36 +X-Sequence-Number: 8164 + + + Hello, + + I have this table : +CREATE TABLE apparts +( + id SERIAL NOT NULL PRIMARY KEY, + + price FLOAT NOT NULL, + surface INTEGER NOT NULL, + price_sq FLOAT NOT NULL, + + rooms INTEGER NULL, + vente BOOL NOT NULL, + category TEXT NOT NULL, + zipcode INTEGER NOT NULL, + departement INTEGER NOT NULL +) WITHOUT OIDS; + +There is a BTREE index on 'departement'. +The table fits in RAM. + +When I want to SELECT according to my indexed field, postgres chooses a +sequential scan unless the number of rows to be returned is very, very +small : + +apparts=> explain analyze select * from apparts where departement=42; + Seq Scan on apparts (cost=0.00..853.12 rows=1403 width=47) (actual +time=5.094..52.026 rows=1516 loops=1) + Filter: (departement = 42) + Total runtime: 52.634 ms + +OK, it returns 1516 rows, so maybe the seq scan is right. + +apparts=> SET enable_seqscan = 0; +apparts=> explain analyze select * from apparts where departement=42; + Index Scan using apparts_dept on apparts (cost=0.00..1514.59 rows=1403 +width=47) (actual time=0.045..2.770 rows=1516 loops=1) + Index Cond: (departement = 42) + Total runtime: 3.404 ms + +Um, 15 times faster... + +Index scan is called only when there are few rows. With other values for +'departement' where there are few rows, the Index is used automatically. +This is logical, even if I should adjust the page costs. I wish I could +tell postgres "this table will fit in RAM and be accessed often, so for +this table, the page seek cost should be very low". + +Everything is vacuum full analyze. + +Now, if I LIMIT the query to 10 rows, the index should be used all the +time, because it will always return few rows... well, it doesn't ! + +apparts=> SET enable_seqscan = 1; +apparts=> explain analyze select * from apparts where departement=42 LIMIT +10; + Limit (cost=0.00..6.08 rows=10 width=47) (actual time=5.003..5.023 +rows=10 loops=1) + -> Seq Scan on apparts (cost=0.00..853.12 rows=1403 width=47) (actual +time=4.998..5.013 rows=10 loops=1) + Filter: (departement = 42) + Total runtime: 5.107 ms + + +Now, let's try : + +apparts=> SET enable_seqscan = 0; +apparts=> explain analyze select * from apparts where departement=42 LIMIT +10; + Limit (cost=0.00..10.80 rows=10 width=47) (actual time=0.047..0.072 +rows=10 loops=1) + -> Index Scan using apparts_dept on apparts (cost=0.00..1514.59 +rows=1403 width=47) (actual time=0.044..0.061 rows=10 loops=1) + Index Cond: (departement = 42) + Total runtime: 0.157 ms + +So, by itself, Postgres will select a very bad query plan (32x slower) on +a query which would be executed very fast using indexes. If I use OFFSET ++ LIMIT, it only gets worse because the seq scan has to scan more rows : + +apparts=> SET enable_seqscan = 1; +apparts=> explain analyze select * from apparts where departement=42 LIMIT +10 OFFSET 85; + QUERY PLAN +--------------------------------------------------------------------------------------------------------------- + Limit (cost=51.69..57.77 rows=10 width=47) (actual time=10.224..10.246 +rows=10 loops=1) + -> Seq Scan on apparts (cost=0.00..853.12 rows=1403 width=47) (actual +time=5.254..10.200 rows=95 loops=1) + Filter: (departement = 42) + Total runtime: 10.326 ms + + +apparts=> SET enable_seqscan = 1; +apparts=> explain analyze select * from apparts where departement=42 LIMIT +10 OFFSET 1000; + Limit (cost=608.07..614.15 rows=10 width=47) (actual time=43.993..44.047 +rows=10 loops=1) + -> Seq Scan on apparts (cost=0.00..853.12 rows=1403 width=47) (actual +time=5.328..43.791 rows=1010 loops=1) + Filter: (departement = 42) + Total runtime: 44.128 ms + +apparts=> SET enable_seqscan = 0; +apparts=> explain analyze select * from apparts where departement=42 LIMIT +10 OFFSET 1000; + Limit (cost=1079.54..1090.33 rows=10 width=47) (actual time=2.147..2.170 +rows=10 loops=1) + -> Index Scan using apparts_dept on apparts (cost=0.00..1514.59 +rows=1403 width=47) (actual time=0.044..1.860 rows=1010 loops=1) + Index Cond: (departement = 42) + Total runtime: 2.259 ms + + + Why is it that way ? The planner should use the LIMIT values when +planning the query, should it not ? + + + + + + + + + + + + +From pgsql-performance-owner@postgresql.org Mon Sep 6 13:27:08 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 77DDE5E48CA + for ; + Mon, 6 Sep 2004 13:26:42 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 90005-01 + for ; + Mon, 6 Sep 2004 12:26:40 +0000 (GMT) +Received: from boutiquenumerique.com (gailleton-2-82-67-9-10.fbx.proxad.net + [82.67.9.10]) + by svr1.postgresql.org (Postfix) with ESMTP id 9C5345E48C1 + for ; + Mon, 6 Sep 2004 13:26:36 +0100 (BST) +Received: (qmail 29972 invoked from network); 6 Sep 2004 14:26:46 +0200 +Received: from unknown (HELO musicbox) (192.168.0.2) + by gailleton-2-82-67-9-10.fbx.proxad.net with SMTP; + 6 Sep 2004 14:26:46 +0200 +To: pgsql-performance@postgresql.org +Subject: Re: The usual sequential scan, but with LIMIT ! +References: <4134BF36.3000504@syscor.com> <413BA104.1040508@geizhals.at> + + +Message-ID: +Date: Mon, 06 Sep 2004 14:27:06 +0200 +From: =?iso-8859-15?Q?Pierre-Fr=E9d=E9ric_Caillaud?= + +Organization: =?iso-8859-15?Q?La_Boutique_Num=E9rique?= +Content-Type: text/plain; format=flowed; delsp=yes; charset=iso-8859-15 +MIME-Version: 1.0 +Content-Transfer-Encoding: 8bit +In-Reply-To: +User-Agent: Opera M2/7.53 (Linux, build 737) +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/37 +X-Sequence-Number: 8165 + + +Update : + +select * from apparts where departement=69 order by departement limit 10; + +does use an index scan (because of the ORDER BY), even with OFFSET, and +it's a lot faster. + + +From pgsql-performance-owner@postgresql.org Mon Sep 6 13:47:05 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 9B8A75E4848 + for ; + Mon, 6 Sep 2004 13:45:34 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 95283-02 + for ; + Mon, 6 Sep 2004 12:45:32 +0000 (GMT) +Received: from zigo.dhs.org (as2-4-3.an.g.bonet.se [194.236.34.191]) + by svr1.postgresql.org (Postfix) with ESMTP id 5CFD55E3632 + for ; + Mon, 6 Sep 2004 13:45:26 +0100 (BST) +Received: from zigo.zigo.dhs.org (zigo.zigo.dhs.org [192.168.0.1]) + by zigo.dhs.org (Postfix) with ESMTP + id D4FE88467; Mon, 6 Sep 2004 14:45:30 +0200 (CEST) +Date: Mon, 6 Sep 2004 14:45:30 +0200 (CEST) +From: Dennis Bjorklund +To: =?iso-8859-15?Q?Pierre-Fr=E9d=E9ric_Caillaud?= + +Cc: pgsql-performance@postgresql.org +Subject: Re: The usual sequential scan, but with LIMIT ! +In-Reply-To: +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=ISO-8859-1 +Content-Transfer-Encoding: 8BIT +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/38 +X-Sequence-Number: 8166 + +On Mon, 6 Sep 2004, [iso-8859-15] Pierre-Fr�d�ric Caillaud wrote: + +> Why is it that way ? The planner should use the LIMIT values when +> planning the query, should it not ? + +And it do use limit values, the estimated cost was lower when you had the +limit, + +What you need to do is to tune pg for your computer. For example the +following settings: + + * effective_cache - this setting tells pg how much the os are caching + (for example use top to find out during a normal work load). You said + that the tables fit in memory and by telling pg how much is cached it + might adjust it's plans accordingly. + +* random_page_cost - how expensive is a random access compared to seq. + access. This is dependent on the computer and disk system you have. + If the setting above does not help, maybe you need to lower this to + variable to 2 or something. + +And don't forget the shared_buffer setting. But most people usually have +it tuned in my experience (but usually too high). Here is an article that +might help you: + + http://www.varlena.com/varlena/GeneralBits/Tidbits/perf.html + +-- +/Dennis Bj�rklund + + +From pgsql-performance-owner@postgresql.org Mon Sep 6 16:57:29 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 799555E47F2 + for ; + Mon, 6 Sep 2004 16:56:34 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 53567-08 + for ; + Mon, 6 Sep 2004 15:56:29 +0000 (GMT) +Received: from mail.logi-track.com (burro.logi-track.com [213.239.193.212]) + by svr1.postgresql.org (Postfix) with ESMTP id 79F5C5E4893 + for ; + Mon, 6 Sep 2004 16:56:27 +0100 (BST) +Received: from kingfisher.intern.logi-track.com (G6e9f.g.pppool.de + [80.185.110.159]) + by mail.logi-track.com (Postfix) with ESMTP id 09874300E8; + Mon, 6 Sep 2004 17:56:27 +0200 (CEST) +Received: from kingfisher.intern.logi-track.com (localhost [127.0.0.1]) + by kingfisher.intern.logi-track.com (Postfix) with SMTP id 23EEDAB2F3; + Mon, 6 Sep 2004 17:56:20 +0200 (CEST) +Date: Mon, 6 Sep 2004 17:56:18 +0200 +From: Markus Schaber +To: PostgreSQL Performance List +Subject: Re: Multiple Uniques +Message-ID: <20040906175618.5497a124@kingfisher.intern.logi-track.com> +In-Reply-To: <87isawwjn1.fsf@stark.xeocode.com> +References: <20040902154340.5b1a669a@kingfisher.intern.logi-track.com> + <87isawwjn1.fsf@stark.xeocode.com> +Organization: logi-track ag, =?ISO-8859-15?Q?z=FCrich?= +X-Mailer: Sylpheed-Claws 0.9.12a (GTK+ 1.2.10; i386-pc-linux-gnu) +X-Face: Nx5T&>Nj$VrVPv}sC3IL&)TqHHOKCz/|)R$i"*r@w0{*I6w; + UNU_hdl1J4NI_m{IMztq=>cmM}1gCLbAF+9\#CGkG8}Y{x%SuQ>1#t:; + Z(|\qdd[i]HStki~#w1$TPF}:0w-7"S\Ev|_a$K wrote: + +> Markus Schaber writes: +>=20 +> > logigis=3D# explain select count(id) from (select ref_in_id as id from= + streets union select nref_in_id as id from streets) as blubb; +> > QUERY PLAN=20=20=20=20= +=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= +=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 +> > -----------------------------------------------------------------------= +---------------------------------- +> > Aggregate (cost=3D16220893.16..16220893.16 rows=3D1 width=3D8) +> > -> Subquery Scan blubb (cost=3D15254815.03..16082881.99 rows=3D552= +04464 width=3D8) +> > -> Unique (cost=3D15254815.03..15530837.35 rows=3D55204464 w= +idth=3D8) +> > -> Sort (cost=3D15254815.03..15392826.19 rows=3D552044= +64 width=3D8) +> > Sort Key: id +> > -> Append (cost=3D0.00..6810225.28 rows=3D552044= +64 width=3D8) +> > -> Subquery Scan "*SELECT* 1" (cost=3D0.00= +..3405112.64 rows=3D27602232 width=3D8) +> > -> Seq Scan on streets (cost=3D0.00.= +.3129090.32 rows=3D27602232 width=3D8) +> > -> Subquery Scan "*SELECT* 2" (cost=3D0.00= +..3405112.64 rows=3D27602232 width=3D8) +> > -> Seq Scan on streets (cost=3D0.00.= +.3129090.32 rows=3D27602232 width=3D8) +>=20 +> You can actually go one step further and do: +>=20 +> select count(distinct id) from (select ... union all select ...) as blub= +b; + +Hmm, as query plan, it gives me: + +> logigis=3D# explain select count(distinct id) from (select ref_in_id as i= +d from streets union all select nref_in_id as id from streets) as blubb; +> QUERY PLAN=20=20=20=20=20=20=20= +=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= +=20=20=20=20=20=20=20=20=20=20 +> -------------------------------------------------------------------------= +-------------------- +> Aggregate (cost=3D7500281.08..7500281.08 rows=3D1 width=3D8) +> -> Subquery Scan blubb (cost=3D0.00..7362269.92 rows=3D55204464 widt= +h=3D8) +> -> Append (cost=3D0.00..6810225.28 rows=3D55204464 width=3D8) +> -> Subquery Scan "*SELECT* 1" (cost=3D0.00..3405112.64 r= +ows=3D27602232 width=3D8) +> -> Seq Scan on streets (cost=3D0.00..3129090.32 ro= +ws=3D27602232 width=3D8) +> -> Subquery Scan "*SELECT* 2" (cost=3D0.00..3405112.64 r= +ows=3D27602232 width=3D8) +> -> Seq Scan on streets (cost=3D0.00..3129090.32 ro= +ws=3D27602232 width=3D8) +> (7 rows) + +This leaves off the sort and unique completely, and leaves all work to +the count aggrecation. Maybe this is implemented by hashing and thus +somehow more efficient... + +> I'm not sure why this is any faster since it still has to do all the same +> work, but it's a different code path and it seems to be about 20% faster = +for +> me. + +When comparing the actual timings, I get: + +> logigis=3D# \timing +> Timing is on. +> logigis=3D# select count(distinct id) from (select ref_in_id as id from s= +treets union all select nref_in_id as id from streets) as blubb; +> count=20=20=20 +> ---------- +> 20225596 +> (1 row) +>=20 +> Time: 1339098.226 ms +> logigis=3D# select count(id) from (select ref_in_id as id from streets u= +nion select nref_in_id as id from streets) as blubb; +> count=20=20=20 +> ---------- +> 20225596 +> (1 row) +>=20 +> Time: 1558920.784 ms +> logigis=3D#=20 + +So you're right, its faster this way. There seems to be some room to +play with optimizer enhancements. + +But simply removing all distincts from subselects would not be the best +way to go, as reducing intermediate datasets can also improve the +performance. + + +Markus + +--=20 +markus schaber | dipl. informatiker +logi-track ag | rennweg 14-16 | ch 8001 z=FCrich +phone +41-43-888 62 52 | fax +41-43-888 62 53 +mailto:schabios@logi-track.com | www.logi-track.com + +From pgsql-performance-owner@postgresql.org Mon Sep 6 17:43:56 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id B9A695E4848 + for ; + Mon, 6 Sep 2004 17:40:48 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 67157-06 + for ; + Mon, 6 Sep 2004 16:40:44 +0000 (GMT) +Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) + by svr1.postgresql.org (Postfix) with ESMTP id 735E45E4893 + for ; + Mon, 6 Sep 2004 17:40:42 +0100 (BST) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i86GefrY014847; + Mon, 6 Sep 2004 12:40:41 -0400 (EDT) +To: =?iso-8859-15?Q?Pierre-Fr=E9d=E9ric_Caillaud?= + +Cc: pgsql-performance@postgresql.org +Subject: Re: The usual sequential scan, but with LIMIT ! +In-reply-to: +References: <4134BF36.3000504@syscor.com> <413BA104.1040508@geizhals.at> + + +Comments: In-reply-to =?iso-8859-15?Q?Pierre-Fr=E9d=E9ric_Caillaud?= + + message dated "Mon, 06 Sep 2004 14:15:44 +0200" +Date: Mon, 06 Sep 2004 12:40:41 -0400 +Message-ID: <14846.1094488841@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/40 +X-Sequence-Number: 8168 + +=?iso-8859-15?Q?Pierre-Fr=E9d=E9ric_Caillaud?= writes: +> Now, if I LIMIT the query to 10 rows, the index should be used all the +> time, because it will always return few rows... well, it doesn't ! + +Not at all. From the planner's point of view, the LIMIT is going to +reduce the cost by about a factor of 10/1403, since the underlying plan +step will only be run partway through. That's not going to change the +decision about which underlying plan step is cheapest: 10/1403 of a +cheaper plan is still always less than 10/1403 of a more expensive plan. + +Later, you note that LIMIT with ORDER BY does affect the plan choice +--- that's because in that situation one plan alternative has a much +higher startup cost than the other (namely the cost of a sort step). +A small LIMIT can allow the fast-startup plan to be chosen even though +it would be estimated to be the loser if run to completion. + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Tue Sep 7 07:51:34 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id C93595E4741 + for ; + Tue, 7 Sep 2004 07:51:31 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 69565-01 + for ; + Tue, 7 Sep 2004 06:51:27 +0000 (GMT) +Received: from boutiquenumerique.com (gailleton-2-82-67-9-10.fbx.proxad.net + [82.67.9.10]) + by svr1.postgresql.org (Postfix) with ESMTP id DC6825E4740 + for ; + Tue, 7 Sep 2004 07:51:24 +0100 (BST) +Received: (qmail 19842 invoked from network); 7 Sep 2004 08:51:30 +0200 +Received: from unknown (HELO musicbox) (192.168.0.2) + by gailleton-2-82-67-9-10.fbx.proxad.net with SMTP; + 7 Sep 2004 08:51:30 +0200 +Date: Tue, 07 Sep 2004 08:51:54 +0200 +To: pgsql-performance@postgresql.org +Subject: Re: The usual sequential scan, but with LIMIT ! +References: <4134BF36.3000504@syscor.com> <413BA104.1040508@geizhals.at> + + <14846.1094488841@sss.pgh.pa.us> +From: =?iso-8859-15?Q?Pierre-Fr=E9d=E9ric_Caillaud?= + +Organization: =?iso-8859-15?Q?La_Boutique_Num=E9rique?= +Content-Type: text/plain; format=flowed; delsp=yes; charset=iso-8859-15 +MIME-Version: 1.0 +Content-Transfer-Encoding: 8bit +Message-ID: +In-Reply-To: <14846.1094488841@sss.pgh.pa.us> +User-Agent: Opera M2/7.53 (Linux, build 737) +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/41 +X-Sequence-Number: 8169 + + + OK, thanks a lot for your explanations. Knowing how the planner "thinks", +makes it pretty logical. Thank you. + + Now another question... + + I have a table of records representing forum posts with a primary key +(id), a topic_id, a timestamp, and other fields which I won't detail. I +want to split them into pages (like forums usually do), with N posts per +page. In that case : + + SELECT * FROM table WHERE topic_id=... ORDER BY post_timestamp asc LIMIT +N OFFSET N*page; + + Also it's almost the same to order by id rather than post_timestamp (id +being a serial). + + SELECT * FROM table WHERE topic_id=... ORDER BY id asc LIMIT N OFFSET +N*page; + + This query runs slower and slower as the OFFSET grows, which is a problem +because the most accessed page in a forum is the last one. + + So, for the last page, I tried : + SELECT * FROM table WHERE topic_id=... ORDER BY id desc LIMIT N; + But this does not use the index at all (seq scan + sort + limit). + + My solution is simple : build an index on (-id), or on (some +date)-post_timestamp, then : + SELECT * FROM table WHERE topic_id=... ORDER BY (-id) desc LIMIT N; + + Then the last page is the fastest one, but it always shows N posts. +That's not a problem, so I guess I'll use that. I don't like forums which +show 1 post on the last page because the number of posts modulo N is 1. + I may store the number of posts in a forum (updated by a trigger) to +avoid costly COUNT queries to count the pages, so I could use ORDER BY id +for the first half of the pages, and ORDER BY (-id) for the rest, so it +will always be fastest. + + I could even create a pages table to store the id of the first post on +that page and then : + SELECT * FROM table WHERE topic_id=... AND id>id_of_first_post_in_page +ORDER BY id asc LIMIT N; + then all pages would be aqually fast. + + Or, I could cache the query results for all pages but the last one. + + Finally, the question : having a multiple field btree, it is not harder +to scan it in "desc order" than in "asc order". So why does not Postgres +do it ? Here is a btree example : + + topic_id id + 1 1 + 1 10 + 2 2 + 2 5 + 2 17 + 3 4 + 3 6 + + suppose I SELECT WHERE topic_id=2 ORDER BY topic_id ASC,id ASC. + Postgres simply finds the first row with topic_id=2 and goes from there. + + suppose I SELECT WHERE topic_id=2 ORDER BY topic_id ASC,id DESC. + Postgres does a seq scan, but it could think a bit more and start at +"first index node which has topic_id>2" (simple to find in a btree) then +go backwards in the index. This can ge beneralized to any combination of +(asc,desc). + + I made some more experiments, and saw Postgres does an 'Index Scan' when +ORDER BY clauses are all ASC, and an 'Index Scan Backwards' when all ORDER +BY are DESC. However, it does not handle a combination of ASC and DESC? + + What do you think of this ? + + +On Mon, 06 Sep 2004 12:40:41 -0400, Tom Lane wrote: + +> =?iso-8859-15?Q?Pierre-Fr=E9d=E9ric_Caillaud?= +> writes: +>> Now, if I LIMIT the query to 10 rows, the index should be used all the +>> time, because it will always return few rows... well, it doesn't ! +> +> Not at all. From the planner's point of view, the LIMIT is going to +> reduce the cost by about a factor of 10/1403, since the underlying plan +> step will only be run partway through. That's not going to change the +> decision about which underlying plan step is cheapest: 10/1403 of a +> cheaper plan is still always less than 10/1403 of a more expensive plan. +> +> Later, you note that LIMIT with ORDER BY does affect the plan choice +> --- that's because in that situation one plan alternative has a much +> higher startup cost than the other (namely the cost of a sort step). +> A small LIMIT can allow the fast-startup plan to be chosen even though +> it would be estimated to be the loser if run to completion. +> +> regards, tom lane +> +> ---------------------------(end of broadcast)--------------------------- +> TIP 6: Have you searched our list archives? +> +> http://archives.postgresql.org +> + + +From pgsql-admin-owner@postgresql.org Tue Sep 7 11:41:16 2004 +X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id B34AC5E4726; + Tue, 7 Sep 2004 11:41:12 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 39931-10; Tue, 7 Sep 2004 10:41:09 +0000 (GMT) +Received: from honorio.sinectis.com.ar (honorio.sinectis.com.ar + [216.244.192.201]) + by svr1.postgresql.org (Postfix) with ESMTP id 575CF5E474A; + Tue, 7 Sep 2004 11:41:05 +0100 (BST) +Received: by honorio.sinectis.com.ar (Postfix, from userid 99) + id DAC576C4F2; Tue, 7 Sep 2004 07:41:07 -0300 (GMT+3) +Content-Type: text/plain +Content-Disposition: inline +Content-Transfer-Encoding: 8bit +MIME-Version: 1.0 +X-Mailer: Sinectis Webmail 5.6.16-1.5.1 +From: G u i d o B a r o s i o +To: pgsql-admin@postgresql.org +Subject: TOAST tables, cannot truncate +Cc: pgsql-performance@postgresql.org +Reply-To: gbarosio@uolsinectis.com.ar +Message-Id: <20040907104107.DAC576C4F2@honorio.sinectis.com.ar> +Date: Tue, 7 Sep 2004 07:41:07 -0300 (GMT+3) +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/62 +X-Sequence-Number: 14765 + +Sorry for crossposting, didn't know where to post. + +Any hint/help on this?! + +db_postgres1=# truncate ref_v2_drs_valid_product ; +ERROR: expected both swapped tables to have TOAST tables + +I need to truncate this table, this is the first time I see this error. + +Regards, +Guido + + +From pgsql-admin-owner@postgresql.org Tue Sep 7 12:14:23 2004 +X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 509B35E472E; + Tue, 7 Sep 2004 12:13:00 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 49755-10; Tue, 7 Sep 2004 11:12:57 +0000 (GMT) +Received: from honorio.sinectis.com.ar (honorio.sinectis.com.ar + [216.244.192.201]) + by svr1.postgresql.org (Postfix) with ESMTP id DDEE45E470B; + Tue, 7 Sep 2004 12:12:53 +0100 (BST) +Received: by honorio.sinectis.com.ar (Postfix, from userid 99) + id 23BA56C4EA; Tue, 7 Sep 2004 08:12:58 -0300 (GMT+3) +Content-Type: text/plain +Content-Disposition: inline +Content-Transfer-Encoding: 8bit +MIME-Version: 1.0 +X-Mailer: Sinectis Webmail 5.6.16-1.5.1 +From: G u i d o B a r o s i o +To: pgsql-admin@postgresql.org, pgsql-performance@postgresql.org +Subject: Re: TOAST tables, cannot truncate +Reply-To: gbarosio@uolsinectis.com.ar +Message-Id: <20040907111258.23BA56C4EA@honorio.sinectis.com.ar> +Date: Tue, 7 Sep 2004 08:12:58 -0300 (GMT+3) +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/63 +X-Sequence-Number: 14766 + +Ok, problem solved. + +A previous ALTER TABLE DROP COLUMN over this table was performed. +By some reason, truncate didn't work then. Would like to know why...it does not seems to be a very frequent problem, due to the fact I only found one chat on the mailing lists talking about this issue, and was hard to find :( ! + +A dump of the table schema, passed to the psql command +(cat table_dump.sql | psql xxx) worked fine. + +TRUNCATE is now available. + +Thanks. + +Guido + +> Sorry for crossposting, didn't know where to post. +> +> Any hint/help on this?! +> +> db_postgres1=# truncate ref_v2_drs_valid_product ; +> ERROR: expected both swapped tables to have TOAST tables +> +> I need to truncate this table, this is the first time I see this error. +> +> Regards, +> Guido +> +> +> ---------------------------(end of broadcast)--------------------------- +> TIP 8: explain analyze is your friend + + +From pgsql-performance-owner@postgresql.org Tue Sep 7 14:51:04 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 291865E40BA + for ; + Tue, 7 Sep 2004 14:47:50 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 01492-06 + for ; + Tue, 7 Sep 2004 13:47:46 +0000 (GMT) +Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) + by svr1.postgresql.org (Postfix) with ESMTP id AC5255E47C4 + for ; + Tue, 7 Sep 2004 14:47:42 +0100 (BST) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i87Dlld3029693; + Tue, 7 Sep 2004 09:47:48 -0400 (EDT) +To: =?iso-8859-15?Q?Pierre-Fr=E9d=E9ric_Caillaud?= + +Cc: pgsql-performance@postgresql.org +Subject: Re: The usual sequential scan, but with LIMIT ! +In-reply-to: +References: <4134BF36.3000504@syscor.com> <413BA104.1040508@geizhals.at> + + <14846.1094488841@sss.pgh.pa.us> + +Comments: In-reply-to =?iso-8859-15?Q?Pierre-Fr=E9d=E9ric_Caillaud?= + + message dated "Tue, 07 Sep 2004 08:51:54 +0200" +Date: Tue, 07 Sep 2004 09:47:47 -0400 +Message-ID: <29692.1094564867@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/44 +X-Sequence-Number: 8172 + +=?iso-8859-15?Q?Pierre-Fr=E9d=E9ric_Caillaud?= writes: +> suppose I SELECT WHERE topic_id=2 ORDER BY topic_id ASC,id DESC. +> Postgres does a seq scan, but it could think a bit more and start at +> "first index node which has topic_id>2" (simple to find in a btree) then +> go backwards in the index. + +If you write it as + SELECT WHERE topic_id=2 ORDER BY topic_id DESC,id DESC. +then an index on (topic_id, id) will work fine. The mixed ASC/DESC +ordering is not compatible with the index. + + regards, tom lane + +From pgsql-admin-owner@postgresql.org Tue Sep 7 15:26:09 2004 +X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 669D95E4735; + Tue, 7 Sep 2004 15:16:27 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 10425-07; Tue, 7 Sep 2004 14:16:25 +0000 (GMT) +Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) + by svr1.postgresql.org (Postfix) with ESMTP id 3718E5E40BA; + Tue, 7 Sep 2004 15:16:22 +0100 (BST) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i87EGTMQ000104; + Tue, 7 Sep 2004 10:16:29 -0400 (EDT) +To: gbarosio@uolsinectis.com.ar +Cc: pgsql-admin@postgresql.org, pgsql-performance@postgresql.org +Subject: Re: [PERFORM] TOAST tables, cannot truncate +In-reply-to: <20040907111258.23BA56C4EA@honorio.sinectis.com.ar> +References: <20040907111258.23BA56C4EA@honorio.sinectis.com.ar> +Comments: In-reply-to G u i d o B a r o s i o + message dated "Tue, 07 Sep 2004 08:12:58 -0300" +Date: Tue, 07 Sep 2004 10:16:28 -0400 +Message-ID: <103.1094566588@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/66 +X-Sequence-Number: 14769 + +G u i d o B a r o s i o writes: +> Ok, problem solved. +> A previous ALTER TABLE DROP COLUMN over this table was performed. +> By some reason, truncate didn't work then. Would like to know why...it does not seems to be a very frequent problem, due to the fact I only found one chat on the mailing lists talking about this issue, and was hard to find :( ! + +http://developer.postgresql.org/cvsweb.cgi/pgsql-server/src/backend/commands/cluster.c + +(note: cvsweb seems mighty slow today, but it is working...) + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Tue Sep 7 15:33:08 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 79C5A5E4828 + for ; + Tue, 7 Sep 2004 15:30:27 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 18906-05 + for ; + Tue, 7 Sep 2004 14:30:25 +0000 (GMT) +Received: from boutiquenumerique.com (gailleton-2-82-67-9-10.fbx.proxad.net + [82.67.9.10]) + by svr1.postgresql.org (Postfix) with ESMTP id 0911F5E472E + for ; + Tue, 7 Sep 2004 15:30:18 +0100 (BST) +Received: (qmail 6073 invoked from network); 7 Sep 2004 16:30:28 +0200 +Received: from unknown (HELO musicbox) (192.168.0.2) + by gailleton-2-82-67-9-10.fbx.proxad.net with SMTP; + 7 Sep 2004 16:30:28 +0200 +To: pgsql-performance@postgresql.org +Subject: Re: The usual sequential scan, but with LIMIT ! +References: <4134BF36.3000504@syscor.com> <413BA104.1040508@geizhals.at> + + <14846.1094488841@sss.pgh.pa.us> + <29692.1094564867@sss.pgh.pa.us> +Message-ID: +From: =?iso-8859-15?Q?Pierre-Fr=E9d=E9ric_Caillaud?= + +Organization: =?iso-8859-15?Q?La_Boutique_Num=E9rique?= +Content-Type: text/plain; format=flowed; delsp=yes; charset=iso-8859-15 +MIME-Version: 1.0 +Content-Transfer-Encoding: 8bit +Date: Tue, 07 Sep 2004 16:30:54 +0200 +In-Reply-To: <29692.1094564867@sss.pgh.pa.us> +User-Agent: Opera M2/7.53 (Linux, build 737) +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/46 +X-Sequence-Number: 8174 + + + Yes, you're right as usual. + I had not thought about playing with ORDER BY on a field which has only +one value in the result set. + + +> If you write it as +> SELECT WHERE topic_id=2 ORDER BY topic_id DESC,id DESC. +> then an index on (topic_id, id) will work fine. The mixed ASC/DESC +> ordering is not compatible with the index. + + +From pgsql-general-owner@postgresql.org Tue Sep 7 17:18:38 2004 +X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 3450E5E4722 + for ; + Tue, 7 Sep 2004 17:18:10 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 58833-03 + for ; + Tue, 7 Sep 2004 16:18:05 +0000 (GMT) +Received: from silmaril.syscor.priv (h24-108-208-253.sbm.shawcable.net + [24.108.208.253]) + by svr1.postgresql.org (Postfix) with ESMTP id B00685E4813 + for ; + Tue, 7 Sep 2004 17:18:01 +0100 (BST) +Received: from syscor.com (strider.syscor.priv [192.168.1.3]) + by silmaril.syscor.priv (8.12.8/8.12.8) with ESMTP id i87GI0Ye010908 + for ; Tue, 7 Sep 2004 09:18:00 -0700 +Message-ID: <413DDFB7.1060006@syscor.com> +Date: Tue, 07 Sep 2004 09:20:07 -0700 +From: Ron St-Pierre +User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; + rv:1.4) Gecko/20030624 +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: pgsql-general +Subject: Re: [PERFORM] Table UPDATE is too slow +References: <4134BF36.3000504@syscor.com> +In-Reply-To: <4134BF36.3000504@syscor.com> +Content-Type: text/plain; charset=ISO-8859-1; format=flowed +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/271 +X-Sequence-Number: 65477 + +Ron St-Pierre wrote: + +> We have a web based application with data that is updated daily. The +> biggest bottleneck occurs when we try to update +> one of the tables. This table contains 58,000 rows and 62 columns, and +> EVERY column is indexed. Every column is +> queryable (?) by the users through the web interface so we are +> reluctant to remove the indexes (recreating them would +> be time consuming too). The primary key is an INT and the rest of the +> columns are a mix of NUMERIC, TEXT, and DATEs. +> A typical update is: +> UPDATE dataTable SET field01=44.5, field02=44.5, field03='Bob', +> field04='foo', ... , field60='2004-08-30', field61='2004-08-29' +> WHERE id = 1234; +> +> Also of note is that the update is run about 10 times per day; we get +> blocks of data from 10 different sources, so we pre-process the +> data and then update the table. We also run VACUUM FULL ANALYZE on a +> nightly basis. + +It now appears that VACUUM wasn't running properly. A manual VACUUM FULL +ANALYZE VEBOSE told us that +approximately 275000 total pages were needed. I increased the +max_fsm_pages to 300000, VACUUMED, renamed the +database and re-created it from backup, vacuumed numerous times, and the +total fsm_pages needed continued to remain in +the 235000 -> 270000 range. This morning I deleted the original +(renamed) database, and a VACUUM FULL ANALYZE +VEBOSE now says that only about 9400 pages are needed. + +One question about redirecting VACUUMs output to file though. When I run: + psql -d imperial -c "vacuum full verbose analyze;" > vac.info +vac.info contains only the following line: + VACUUM +I've been unable to capture the VERBOSE output to file. Any suggestions? + + + +> +Also, thanks for everyone's input about my original posting, I am +investigating some of the options mentioned to further increase +performance. + +Ron + + +From pgsql-performance-owner@postgresql.org Tue Sep 7 18:05:39 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id B023F5E473C + for ; + Tue, 7 Sep 2004 18:05:29 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 74325-02 + for ; + Tue, 7 Sep 2004 17:05:24 +0000 (GMT) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by svr1.postgresql.org (Postfix) with ESMTP id C2DB95E4735 + for ; + Tue, 7 Sep 2004 18:05:22 +0100 (BST) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by news.hub.org (8.12.9/8.12.9) with ESMTP id i87H5LCr075087 + for ; Tue, 7 Sep 2004 17:05:22 GMT + (envelope-from news@news.hub.org) +Received: (from news@localhost) + by news.hub.org (8.12.9/8.12.9/Submit) id i87GsYkH071306 + for pgsql-performance@postgresql.org; Tue, 7 Sep 2004 16:54:34 GMT +From: Gaetano Mendola +X-Newsgroups: comp.databases.postgresql.performance +Subject: Re: The usual sequential scan, but with LIMIT ! +Date: Tue, 07 Sep 2004 18:54:15 +0200 +Organization: PYRENET Midi-pyrenees Provider +Lines: 16 +Message-ID: <413DE7B7.7060807@bigfoot.com> +References: <4134BF36.3000504@syscor.com> <413BA104.1040508@geizhals.at> + + <14846.1094488841@sss.pgh.pa.us> + <29692.1094564867@sss.pgh.pa.us> + +Mime-Version: 1.0 +Content-Type: text/plain; charset=ISO-8859-15; format=flowed +Content-Transfer-Encoding: 8bit +X-Complaints-To: abuse@pyrenet.fr +To: =?ISO-8859-15?Q?Pierre-Fr=E9d=E9ric_Caillaud?= + +User-Agent: Mozilla Thunderbird 0.7.3 (Windows/20040803) +X-Accept-Language: en-us, en +In-Reply-To: +X-Enigmail-Version: 0.85.0.0 +X-Enigmail-Supports: pgp-inline, pgp-mime +To: pgsql-performance@postgresql.org +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/47 +X-Sequence-Number: 8175 + +Pierre-Fr�d�ric Caillaud wrote: + +> +> Yes, you're right as usual. + +As usual ? Do you think your father can be wrong on you ? :-) + + + +Gaetano + + + + + + + +From pgsql-general-owner@postgresql.org Tue Sep 7 19:00:28 2004 +X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 5DADE5E48E5 + for ; + Tue, 7 Sep 2004 19:00:18 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 93070-05 + for ; + Tue, 7 Sep 2004 18:00:13 +0000 (GMT) +Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) + by svr1.postgresql.org (Postfix) with ESMTP id C7AD55E4864 + for ; + Tue, 7 Sep 2004 19:00:12 +0100 (BST) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i87I0EkS002414; + Tue, 7 Sep 2004 14:00:14 -0400 (EDT) +To: Ron St-Pierre +Cc: pgsql-general +Subject: Re: [PERFORM] Table UPDATE is too slow +In-reply-to: <413DDFB7.1060006@syscor.com> +References: <4134BF36.3000504@syscor.com> <413DDFB7.1060006@syscor.com> +Comments: In-reply-to Ron St-Pierre + message dated "Tue, 07 Sep 2004 09:20:07 -0700" +Date: Tue, 07 Sep 2004 14:00:13 -0400 +Message-ID: <2413.1094580013@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/278 +X-Sequence-Number: 65484 + +Ron St-Pierre writes: +> One question about redirecting VACUUMs output to file though. When I run: +> psql -d imperial -c "vacuum full verbose analyze;" > vac.info +> vac.info contains only the following line: +> VACUUM +> I've been unable to capture the VERBOSE output to file. Any suggestions? + +You need to catch stderr not only stdout. + +(I'd be less vague if I knew which shell you were running, but sh- and +csh-derived shells do it differently.) + + regards, tom lane + +From pgsql-general-owner@postgresql.org Tue Sep 7 19:40:30 2004 +X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 32DF25E487C + for ; + Tue, 7 Sep 2004 19:40:09 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 04921-06 + for ; + Tue, 7 Sep 2004 18:40:05 +0000 (GMT) +Received: from silmaril.syscor.priv (h24-108-208-253.sbm.shawcable.net + [24.108.208.253]) + by svr1.postgresql.org (Postfix) with ESMTP id 44BAE5E4840 + for ; + Tue, 7 Sep 2004 19:40:01 +0100 (BST) +Received: from syscor.com (strider.syscor.priv [192.168.1.3]) + by silmaril.syscor.priv (8.12.8/8.12.8) with ESMTP id i87Ie6Ye011285 + for ; Tue, 7 Sep 2004 11:40:06 -0700 +Message-ID: <413E0105.1060306@syscor.com> +Date: Tue, 07 Sep 2004 11:42:13 -0700 +From: Ron St-Pierre +User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; + rv:1.4) Gecko/20030624 +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: pgsql-general +Subject: Re: [PERFORM] Table UPDATE is too slow +References: <4134BF36.3000504@syscor.com> <413DDFB7.1060006@syscor.com> + <6966554.1094579891406.JavaMail.root@hercules.ponder-stibbons.com> +In-Reply-To: + <6966554.1094579891406.JavaMail.root@hercules.ponder-stibbons.com> +Content-Type: text/plain; charset=ISO-8859-1; format=flowed +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/282 +X-Sequence-Number: 65488 + +Tom Lane wrote: + +>Ron St-Pierre writes: +> +> +>>One question about redirecting VACUUMs output to file though. When I run: +>> psql -d imperial -c "vacuum full verbose analyze;" > vac.info +>>vac.info contains only the following line: +>> VACUUM +>>I've been unable to capture the VERBOSE output to file. Any suggestions? +>> +>> +> +>You need to catch stderr not only stdout. +> +>(I'd be less vague if I knew which shell you were running, but sh- and +>csh-derived shells do it differently.) +> +> +> +Oops, I'm running bash. I just redirected stderr to the file + psql -d imperial -c "vacuum full verbose analyze;" 2> +/usr/local/pgsql/vac.info +which gives me exactly what I want. + +Thanks again Tom + +Ron + + +From pgsql-performance-owner@postgresql.org Sat Sep 11 06:06:41 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 93A25329F0D + for ; + Wed, 8 Sep 2004 01:49:09 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 40731-05 + for ; + Wed, 8 Sep 2004 00:49:01 +0000 (GMT) +Received: from www.postgresql.com (www.postgresql.com [200.46.204.209]) + by svr1.postgresql.org (Postfix) with ESMTP id 50AE6329D8A + for ; + Wed, 8 Sep 2004 01:49:02 +0100 (BST) +Received: from ctg-msnexc01.staff.berbee.com (msn-office-flr2.binc.net + [64.73.12.254]) + by www.postgresql.com (Postfix) with ESMTP id 2857C5A1173 + for ; + Tue, 7 Sep 2004 22:32:48 +0100 (BST) +Received: from localhost ([172.30.254.220] RDNS failed) by + ctg-msnexc01.staff.berbee.com with Microsoft SMTPSVC(6.0.3790.0); + Tue, 7 Sep 2004 16:32:31 -0500 +From: "Jeremy M. Guthrie" +Reply-To: jeremy.guthrie@berbee.com +Organization: Berbee Information Networks Inc. +To: pgsql-performance@postgresql.org +Subject: Stuck using Sequential Scan +Date: Tue, 7 Sep 2004 16:32:03 -0500 +User-Agent: KMail/1.6.2 +MIME-Version: 1.0 +Content-Disposition: inline +Content-Type: Text/Plain; + charset="us-ascii" +Content-Transfer-Encoding: quoted-printable +Message-Id: <200409071632.05374.jeremy.guthrie@berbee.com> +X-OriginalArrivalTime: 07 Sep 2004 21:32:31.0575 (UTC) + FILETIME=[2E8EBE70:01C49522] +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/69 +X-Sequence-Number: 8197 + +-----BEGIN PGP SIGNED MESSAGE----- +Hash: SHA1 + +I have a problem where I have the table format listed below. I have the=20 +primary key tsyslog_id and the index built against it. However, when I=20 +select a unique row, it will only ever do a seq scan even after I turn off= +=20 +all other types except indexscan. I understand you cannot fully turn off s= +eq=20 +scan.=20=20 + +Syslog_TArchive size: 1,426,472,960 bytes +syslog_tarchive_pkey size: 132,833,280 bytes +archhost_idx size: 300,802,048 bytes +tarchdatetime_idx size: 159,293,440 bytes +tarchhostid_idx size: 362,323,968 bytes + +I cannot run vacuum more than once a day because of its heavy IO penalty. = +I=20 +run analyze once an hour. However, if I run analyze then explain, I see no= +=20 +difference in the planners decisions. What am I missing? + + +TSyslog=3D# \d syslog_tarchive; + Table "public.syslog_tarchive" + Column | Type |=20=20=20=20=20=20=20=20=20=20=20=20= +=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 +Modifiers +- ------------+------------------------+-----------------------------------= +-------------------------------------- + tsyslog_id | bigint | not null default=20 +nextval('public.syslog_tarchive_tsyslog_id_seq'::text) + facility | integer | + severity | integer | + date | date | + time | time without time zone | + host | character varying(128) | + message | text | +Indexes: + "syslog_tarchive_pkey" primary key, btree (tsyslog_id) + "archhost_idx" btree (host) + "tarchdatetime_idx" btree (date, "time") + "tarchhostid_idx" btree (tsyslog_id, host) + +TSyslog=3D# explain select * from tsyslog where tsyslog_id=3D431650835; + QUERY PLAN +- ------------------------------------------------------------------------- + Seq Scan on tsyslog (cost=3D100000000.00..100000058.20 rows=3D2 width=3D1= +87) + Filter: (tsyslog_id =3D 431650835) +(2 rows) + +- --=20 + +- -------------------------------------------------- +Jeremy M. Guthrie jeremy.guthrie@berbee.com +Senior Network Engineer Phone: 608-298-1061 +Berbee Fax: 608-288-3007 +5520 Research Park Drive NOC: 608-298-1102 +Madison, WI 53711 +-----BEGIN PGP SIGNATURE----- +Version: GnuPG v1.2.4 (GNU/Linux) + +iD8DBQFBPijTqtjaBHGZBeURAndgAJ4rT2NpG9aGAdogoZaV+BvUfF6TjACfaexf +LrBzhDQK72u8dCUuPOSHB+Y=3D +=3DDSxi +-----END PGP SIGNATURE----- + +From pgsql-performance-owner@postgresql.org Wed Sep 8 14:50:05 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 7EB55329EB0 + for ; + Wed, 8 Sep 2004 14:50:01 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 76950-10 + for ; + Wed, 8 Sep 2004 13:49:51 +0000 (GMT) +Received: from mercure.sigma.fr (mercure-1.sigma.fr [195.25.81.8]) + by svr1.postgresql.org (Postfix) with ESMTP id 5DDB2329EA7 + for ; + Wed, 8 Sep 2004 14:49:52 +0100 (BST) +Received: from localhost (localhost [127.0.0.1]) + by mercure.sigma.fr (Postfix) with ESMTP id 96EF679F1 + for ; + Wed, 8 Sep 2004 15:49:50 +0200 (CEST) +Received: from mercure.sigma.fr ([127.0.0.1]) + by localhost (mercure-1 [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id 04615-01 for ; + Wed, 8 Sep 2004 15:49:50 +0200 (CEST) +Received: from marc.sigma.fr (unknown [89.195.0.5]) + by mercure.sigma.fr (Postfix) with ESMTP id 69D3679E5 + for ; + Wed, 8 Sep 2004 15:49:50 +0200 (CEST) +From: Marc Cousin +Organization: Sigma Informatique +Subject: Problem with large query +Date: Wed, 8 Sep 2004 15:49:49 +0200 +User-Agent: KMail/1.7 +MIME-Version: 1.0 +Content-Disposition: inline +To: pgsql-performance@postgresql.org +Content-Type: text/plain; + charset="us-ascii" +Content-Transfer-Encoding: quoted-printable +Message-Id: <200409081549.49537.mcousin@sigma.fr> +X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at sigma.fr +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/48 +X-Sequence-Number: 8176 + +Hi. I hope I'm not asking a too trivial question here... + +I'm having trouble with a (quite big) query, and can't find a way to make i= +t=20 +faster. + +Here is the information : + +Tables : +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= +=3D=3D=3D +sces_vte -> 2753539 rows +sces_art -> 602327 +sces_fsf -> 8126 +sces_frc -> 7763 +sces_tps -> 38 +sces_gtr -> 35 + + +Query : +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= +=3D=3D +SELECT +sces_gtr_art.gtr_cod, +sces_gtr_art.gtr_lib, +sces_frc_art.fou_cod, +sces_frc_art.fou_lib, +sces_tps.tps_annee_mois, +TO_NUMBER('200401','999999'), +TO_NUMBER('200405','999999'), +sces_tps.tps_libc, +sum(sces_vte.vte_mnt), +sum(sces_vte.vte_qte), +sum(sces_vte.vte_ton), +sces_famille.fsf_codfam, +sces_famille.fsf_lib, +sces_s_famille.fsf_codsfm, +sces_s_famille.fsf_lib +FROM +sces_vte, +sces_art, +sces_fsf sces_famille, +sces_fsf sces_s_famille, +sces_frc sces_frc_art, +sces_tps, +sces_gtr sces_gtr_art +WHERE +( sces_famille.fsf_codfam=3Dsces_s_famille.fsf_codfam ) +AND ( sces_famille.fsf_codseg=3D 0 and sces_famille.fsf_codsfm =3D 0 ) +AND ( sces_vte.tps_annee_mois=3Dsces_tps.tps_annee_mois ) +AND ( sces_vte.art_cod=3Dsces_art.art_cod and=20 +sces_vte.dos_cod=3Dsces_art.dos_cod ) +AND ( sces_gtr_art.gtr_cod=3Dsces_frc_art.gtr_cod ) +AND ( sces_frc_art.gtr_cod=3Dsces_art.gtr_cod and=20 +sces_frc_art.fou_cod=3Dsces_art.fou_cod ) +AND ( sces_s_famille.fsf_codfam=3Dsces_art.fsf_codfam and=20 +sces_s_famille.fsf_codsfm=3Dsces_art.fsf_codsfm ) +AND ( sces_s_famille.fsf_codseg =3D 0 ) +AND ( +( ( ( sces_tps.tps_annee_mois ) >=3D ( TO_NUMBER('200401','999999') ) and= +=20 +( sces_tps.tps_annee_mois ) <=3D ( +TO_NUMBER('200405','999999') ) +) +OR +( +( sces_tps.tps_annee_mois ) >=3D ( TO_NUMBER('200401','999999') )-100 and= +=20 +( sces_tps.tps_annee_mois ) <=3D ( +TO_NUMBER('200405','999999') )-100 +) ) +AND ( sces_gtr_art.gtr_cod in (2)) +) +GROUP BY +sces_gtr_art.gtr_cod, +sces_gtr_art.gtr_lib, +sces_frc_art.fou_cod, +sces_frc_art.fou_lib, +sces_tps.tps_annee_mois, +TO_NUMBER('200401','999999'), +TO_NUMBER('200405','999999'), +sces_tps.tps_libc, +sces_famille.fsf_codfam, +sces_famille.fsf_lib, +sces_s_famille.fsf_codsfm, +sces_s_famille.fsf_lib + +Explain Analyze Plan :=20 +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + GroupAggregate (cost=3D27161.91..27938.72 rows=3D16354 width=3D280) (actu= +al time=3D484509.210..544436.148 rows=3D4115 loops=3D1) + -> Sort (cost=3D27161.91..27202.79 rows=3D16354 width=3D280) (actual t= +ime=3D484496.188..485334.151 rows=3D799758 loops=3D1) + Sort Key: sces_gtr_art.gtr_cod, sces_gtr_art.gtr_lib, sces_frc_art= +.fou_cod, sces_frc_art.fou_lib, sces_tps.tps_annee_mois, 200401::numeric, 2= +00405::numeric, sces_tps.tps_libc, sces_famille.fsf_codfam, sces_famille.fs= +f_lib, sces_s_famille.fsf_codsfm, sces_s_famille.fsf_lib + -> Merge Join (cost=3D25727.79..26017.34 rows=3D16354 width=3D28= +0) (actual time=3D58945.821..69321.146 rows=3D799758 loops=3D1) + Merge Cond: (("outer".fsf_codfam =3D "inner".fsf_codfam) AND= + ("outer".fsf_codsfm =3D "inner".fsf_codsfm)) + -> Sort (cost=3D301.36..304.60 rows=3D1298 width=3D83) (ac= +tual time=3D27.926..28.256 rows=3D332 loops=3D1) + Sort Key: sces_s_famille.fsf_codfam, sces_s_famille.fs= +f_codsfm + -> Seq Scan on sces_fsf sces_s_famille (cost=3D0.00.= +.234.24 rows=3D1298 width=3D83) (actual time=3D0.042..19.124 rows=3D1341 lo= +ops=3D1) + Filter: (fsf_codseg =3D 0::numeric) + -> Sort (cost=3D25426.43..25448.05 rows=3D8646 width=3D225= +) (actual time=3D58917.106..59693.810 rows=3D799758 loops=3D1) + Sort Key: sces_art.fsf_codfam, sces_art.fsf_codsfm + -> Merge Join (cost=3D24726.32..24861.08 rows=3D8646= + width=3D225) (actual time=3D19036.709..29404.943 rows=3D799758 loops=3D1) + Merge Cond: ("outer".tps_annee_mois =3D "inner".= +tps_annee_mois) + -> Sort (cost=3D2.49..2.53 rows=3D17 width=3D2= +3) (actual time=3D0.401..0.428 rows=3D20 loops=3D1) + Sort Key: sces_tps.tps_annee_mois + -> Seq Scan on sces_tps (cost=3D0.00..2.= +14 rows=3D17 width=3D23) (actual time=3D0.068..0.333 rows=3D20 loops=3D1) + Filter: (((tps_annee_mois >=3D 20030= +1::numeric) OR (tps_annee_mois >=3D 200401::numeric)) AND ((tps_annee_mois = +<=3D 200305::numeric) OR (tps_annee_mois >=3D 200401::numeric)) AND ((tps_a= +nnee_mois >=3D 200301::numeric) OR (tps_annee_mois <=3D 200405::numeric)) A= +ND ((tps_annee_mois <=3D 200305::numeric) OR (tps_annee_mois <=3D 200405::n= +umeric))) + -> Sort (cost=3D24723.83..24747.97 rows=3D9656= + width=3D214) (actual time=3D19036.223..19917.214 rows=3D799757 loops=3D1) + Sort Key: sces_vte.tps_annee_mois + -> Nested Loop (cost=3D21825.09..24084.7= +4 rows=3D9656 width=3D214) (actual time=3D417.603..8644.294 rows=3D399879 l= +oops=3D1) + -> Nested Loop (cost=3D21825.09..2= +1837.50 rows=3D373 width=3D195) (actual time=3D417.444..672.741 rows=3D1415= +8 loops=3D1) + -> Seq Scan on sces_gtr sces_= +gtr_art (cost=3D0.00..1.44 rows=3D1 width=3D40) (actual time=3D0.026..0.08= +5 rows=3D1 loops=3D1) + Filter: (gtr_cod =3D 2::= +numeric) + -> Merge Join (cost=3D21825.= +09..21832.34 rows=3D373 width=3D165) (actual time=3D417.400..568.247 rows= +=3D14158 loops=3D1) + Merge Cond: ("outer".fsf= +_codfam =3D "inner".fsf_codfam) + -> Sort (cost=3D255.24= +..255.30 rows=3D24 width=3D74) (actual time=3D16.597..16.692 rows=3D106 loo= +ps=3D1) + Sort Key: sces_fam= +ille.fsf_codfam + -> Seq Scan on sc= +es_fsf sces_famille (cost=3D0.00..254.69 rows=3D24 width=3D74) (actual tim= +e=3D0.029..15.971 rows=3D155 loops=3D1) + Filter: ((fs= +f_codseg =3D 0::numeric) AND (fsf_codsfm =3D 0::numeric)) + -> Sort (cost=3D21569.= +85..21571.64 rows=3D715 width=3D91) (actual time=3D400.631..416.871 rows=3D= +14162 loops=3D1) + Sort Key: sces_art= +.fsf_codfam + -> Nested Loop (= +cost=3D0.00..21535.95 rows=3D715 width=3D91) (actual time=3D1.320..230.975 = +rows=3D14162 loops=3D1) + -> Seq Scan= + on sces_frc sces_frc_art (cost=3D0.00..182.75 rows=3D728 width=3D51) (act= +ual time=3D1.195..14.316 rows=3D761 loops=3D1) + Filter= +: (2::numeric =3D gtr_cod) + -> Index Sc= +an using ind_art_02 on sces_art (cost=3D0.00..29.24 rows=3D7 width=3D61) (= +actual time=3D0.040..0.160 rows=3D19 loops=3D761) + Index = +Cond: ((2::numeric =3D sces_art.gtr_cod) AND ("outer".fou_cod =3D sces_art.= +fou_cod)) + -> Index Scan using idx_vte_02 on s= +ces_vte (cost=3D0.00..6.01 rows=3D1 width=3D62) (actual time=3D0.037..0.25= +9 rows=3D28 loops=3D14158) + Index Cond: ((sces_vte.art_cod= + =3D "outer".art_cod) AND (sces_vte.dos_cod =3D "outer".dos_cod)) + Total runtime: 545435.989 ms + + + + From what I understand from the plan, the worst part of it is the sort. Is = +there a way I can improve this query ? +(Obviously, as it has many rows, it will still be a slow query, but here it= +'s too slow for us...). + +I allready extended the sort_mem (up to 500 MB to be sure, the server has p= +lenty of RAM), +the query has become faster, but I don't know what else to do, to speed up = +the sort. + +BTW the query was generated, not written. We allready are trying to write s= +omething better, but we are still facing a +gigantic sort at the end (we need the group by, and there are many lines fr= +om the main table (sces_vte) to be retrieved and aggregated)... + +Thanks in advance... + +From pgsql-performance-owner@postgresql.org Wed Sep 8 15:40:50 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id E132F329C89 + for ; + Wed, 8 Sep 2004 15:40:49 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 98089-08 + for ; + Wed, 8 Sep 2004 14:40:40 +0000 (GMT) +Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) + by svr1.postgresql.org (Postfix) with ESMTP id A99A0329CAE + for ; + Wed, 8 Sep 2004 15:40:42 +0100 (BST) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i88Eeh8N020150; + Wed, 8 Sep 2004 10:40:43 -0400 (EDT) +To: Marc Cousin +Cc: pgsql-performance@postgresql.org +Subject: Re: Problem with large query +In-reply-to: <200409081549.49537.mcousin@sigma.fr> +References: <200409081549.49537.mcousin@sigma.fr> +Comments: In-reply-to Marc Cousin + message dated "Wed, 08 Sep 2004 15:49:49 +0200" +Date: Wed, 08 Sep 2004 10:40:43 -0400 +Message-ID: <20149.1094654443@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/49 +X-Sequence-Number: 8177 + +Marc Cousin writes: +> I'm having trouble with a (quite big) query, and can't find a way to make it +> faster. + +Seems like it might help if the thing could use a HashAggregate instead +of sort/group. Numeric is not hashable, so having those TO_NUMBER +constants in GROUP BY destroys this option instantly ... but why in the +world are you grouping by constants anyway? You didn't say what the +datatypes of the other columns were... + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Sat Sep 11 06:06:41 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id E841F329CA4 + for ; + Wed, 8 Sep 2004 15:47:55 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 04323-02 + for ; + Wed, 8 Sep 2004 14:47:45 +0000 (GMT) +Received: from mail5.speakeasy.net (mail5.speakeasy.net [216.254.0.205]) + by svr1.postgresql.org (Postfix) with ESMTP id 97C36329C89 + for ; + Wed, 8 Sep 2004 15:47:47 +0100 (BST) +Received: (qmail 4026 invoked from network); 8 Sep 2004 14:47:47 -0000 +Received: from dsl092-016-161.sfo4.dsl.speakeasy.net (HELO [10.0.2.103]) + (asah@[66.92.16.161]) (envelope-sender ) + by mail5.speakeasy.net (qmail-ldap-1.03) with AES256-SHA encrypted SMTP + for ; 8 Sep 2004 14:47:47 -0000 +Message-ID: <413F1B85.9040302@speakeasy.net> +Date: Wed, 08 Sep 2004 07:47:33 -0700 +From: Adam Sah +User-Agent: Mozilla Thunderbird 0.7.3 (Windows/20040803) +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: pgsql-performance@postgresql.org +Subject: Re: Problem with large query +References: <200409081549.49537.mcousin@sigma.fr> + <20149.1094654443@sss.pgh.pa.us> +In-Reply-To: <20149.1094654443@sss.pgh.pa.us> +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/70 +X-Sequence-Number: 8198 + +by the way, this reminds me: I just ran a performance study at a company doing + an oracle-to-postgres conversion, and FYI converting from numeric and decimal + to integer/bigint/real saved roughly 3x on space and 2x on performance. + Obviously, YMMV. + +adam + + +Tom Lane wrote: + +> Marc Cousin writes: +> +>>I'm having trouble with a (quite big) query, and can't find a way to make it +>>faster. +> +> +> Seems like it might help if the thing could use a HashAggregate instead +> of sort/group. Numeric is not hashable, so having those TO_NUMBER +> constants in GROUP BY destroys this option instantly ... but why in the +> world are you grouping by constants anyway? You didn't say what the +> datatypes of the other columns were... +> +> regards, tom lane +> +> ---------------------------(end of broadcast)--------------------------- +> TIP 2: you can get off all lists at once with the unregister command +> (send "unregister YourEmailAddressHere" to majordomo@postgresql.org) +> +> + +From pgsql-performance-owner@postgresql.org Wed Sep 8 15:50:23 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 6AC79329D8A + for ; + Wed, 8 Sep 2004 15:50:12 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 00451-08 + for ; + Wed, 8 Sep 2004 14:50:02 +0000 (GMT) +Received: from mercure.sigma.fr (mercure-1.sigma.fr [195.25.81.8]) + by svr1.postgresql.org (Postfix) with ESMTP id 872D0329D87 + for ; + Wed, 8 Sep 2004 15:50:03 +0100 (BST) +Received: from localhost (localhost [127.0.0.1]) + by mercure.sigma.fr (Postfix) with ESMTP id C53B374F6; + Wed, 8 Sep 2004 16:50:02 +0200 (CEST) +Received: from mercure.sigma.fr ([127.0.0.1]) + by localhost (mercure-1 [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id 07651-09; Wed, 8 Sep 2004 16:50:02 +0200 (CEST) +Received: from marc.sigma.fr (unknown [89.195.0.5]) + by mercure.sigma.fr (Postfix) with ESMTP id 92E9E747B; + Wed, 8 Sep 2004 16:50:02 +0200 (CEST) +From: Marc Cousin +Organization: Sigma Informatique +To: Tom Lane +Subject: Re: Problem with large query +Date: Wed, 8 Sep 2004 16:49:59 +0200 +User-Agent: KMail/1.7 +References: <200409081549.49537.mcousin@sigma.fr> + <20149.1094654443@sss.pgh.pa.us> +In-Reply-To: <20149.1094654443@sss.pgh.pa.us> +Cc: pgsql-performance@postgresql.org +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-15" +Content-Transfer-Encoding: 7bit +Content-Disposition: inline +Message-Id: <200409081650.00228.mcousin@sigma.fr> +X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at sigma.fr +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/50 +X-Sequence-Number: 8178 + +The query has been generated by business objects ... i'ill try to suggest to the developpers to remove this constant (if they can)... +The fields used by the sort are of type numeric(6,0) or (10,0) ... +Could it be better if the fields were integer or anything else ? + + +On Wednesday 08 September 2004 16:40, you wrote: +> Marc Cousin writes: +> > I'm having trouble with a (quite big) query, and can't find a way to make it +> > faster. +> +> Seems like it might help if the thing could use a HashAggregate instead +> of sort/group. Numeric is not hashable, so having those TO_NUMBER +> constants in GROUP BY destroys this option instantly ... but why in the +> world are you grouping by constants anyway? You didn't say what the +> datatypes of the other columns were... +> +> regards, tom lane +> + +From pgsql-performance-owner@postgresql.org Wed Sep 8 15:56:30 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 41905329C89 + for ; + Wed, 8 Sep 2004 15:56:29 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 05153-09 + for ; + Wed, 8 Sep 2004 14:56:14 +0000 (GMT) +Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) + by svr1.postgresql.org (Postfix) with ESMTP id 45C20329CBC + for ; + Wed, 8 Sep 2004 15:56:17 +0100 (BST) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i88EuI6b020326; + Wed, 8 Sep 2004 10:56:18 -0400 (EDT) +To: Marc Cousin +Cc: pgsql-performance@postgresql.org +Subject: Re: Problem with large query +In-reply-to: <200409081650.00228.mcousin@sigma.fr> +References: <200409081549.49537.mcousin@sigma.fr> + <20149.1094654443@sss.pgh.pa.us> + <200409081650.00228.mcousin@sigma.fr> +Comments: In-reply-to Marc Cousin + message dated "Wed, 08 Sep 2004 16:49:59 +0200" +Date: Wed, 08 Sep 2004 10:56:17 -0400 +Message-ID: <20325.1094655377@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/51 +X-Sequence-Number: 8179 + +Marc Cousin writes: +> The query has been generated by business objects ... i'ill try to suggest to the developpers to remove this constant (if they can)... +> The fields used by the sort are of type numeric(6,0) or (10,0) ... +> Could it be better if the fields were integer or anything else ? + +integer or bigint would be a WHOLE lot faster. I'd venture that +comparing two numerics is order of a hundred times slower than +comparing two integers. + +Even if you don't want to change the fields on-disk, you might think +about casting them all to int/bigint in the query. + +Another thing that might or might not be easy is to change the order of +the GROUP BY items so that the fields with the largest number of +distinct values are listed first. If two rows are distinct at the first +column, the sorting comparison doesn't even have to look at the +remaining columns ... + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Wed Sep 8 16:17:56 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id A3CCB329CB0 + for ; + Wed, 8 Sep 2004 16:17:53 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 14228-09 + for ; + Wed, 8 Sep 2004 15:17:50 +0000 (GMT) +Received: from mercure.sigma.fr (mercure-1.sigma.fr [195.25.81.8]) + by svr1.postgresql.org (Postfix) with ESMTP id 4710D329CA4 + for ; + Wed, 8 Sep 2004 16:17:49 +0100 (BST) +Received: from localhost (localhost [127.0.0.1]) + by mercure.sigma.fr (Postfix) with ESMTP id D6D587A4E; + Wed, 8 Sep 2004 17:17:48 +0200 (CEST) +Received: from mercure.sigma.fr ([127.0.0.1]) + by localhost (mercure-1 [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id 09373-05; Wed, 8 Sep 2004 17:17:48 +0200 (CEST) +Received: from marc.sigma.fr (unknown [89.195.0.5]) + by mercure.sigma.fr (Postfix) with ESMTP id BB91B79E5; + Wed, 8 Sep 2004 17:17:48 +0200 (CEST) +From: Marc Cousin +Organization: Sigma Informatique +To: Tom Lane +Subject: Re: Problem with large query +Date: Wed, 8 Sep 2004 17:17:47 +0200 +User-Agent: KMail/1.7 +References: <200409081549.49537.mcousin@sigma.fr> + <200409081650.00228.mcousin@sigma.fr> + <20325.1094655377@sss.pgh.pa.us> +In-Reply-To: <20325.1094655377@sss.pgh.pa.us> +Cc: pgsql-performance@postgresql.org +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-15" +Content-Transfer-Encoding: 7bit +Content-Disposition: inline +Message-Id: <200409081717.47514.mcousin@sigma.fr> +X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at sigma.fr +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/52 +X-Sequence-Number: 8180 + +On Wednesday 08 September 2004 16:56, you wrote: +> Marc Cousin writes: +> > The query has been generated by business objects ... i'ill try to suggest to the developpers to remove this constant (if they can)... +> > The fields used by the sort are of type numeric(6,0) or (10,0) ... +> > Could it be better if the fields were integer or anything else ? +> +> integer or bigint would be a WHOLE lot faster. I'd venture that +> comparing two numerics is order of a hundred times slower than +> comparing two integers. +> +> Even if you don't want to change the fields on-disk, you might think +> about casting them all to int/bigint in the query. +> +> Another thing that might or might not be easy is to change the order of +> the GROUP BY items so that the fields with the largest number of +> distinct values are listed first. If two rows are distinct at the first +> column, the sorting comparison doesn't even have to look at the +> remaining columns ... +> +> regards, tom lane +> +Thanks. I've just had confirmation that they can remove the two constants (allready won 100 seconds thanks to that) +I've tried the cast, and got down to 72 seconds. +So now we're going to try to convert the fields to int or bigint. + +Thanks a lot for your help and time. + +From pgsql-performance-owner@postgresql.org Sat Sep 11 06:07:36 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 3A19F329CF7 + for ; + Wed, 8 Sep 2004 17:06:05 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 34140-04 + for ; + Wed, 8 Sep 2004 16:05:51 +0000 (GMT) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by svr1.postgresql.org (Postfix) with ESMTP id 0C111329CB7 + for ; + Wed, 8 Sep 2004 17:05:35 +0100 (BST) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by news.hub.org (8.12.9/8.12.9) with ESMTP id i88G5YCn035941 + for ; Wed, 8 Sep 2004 16:05:34 GMT + (envelope-from news@news.hub.org) +Received: (from news@localhost) + by news.hub.org (8.12.9/8.12.9/Submit) id i88FcqGd026260 + for pgsql-performance@postgresql.org; Wed, 8 Sep 2004 15:38:52 GMT +From: Mischa Sandberg +Reply-To: ischamay.andbergsay@activestateway.com +User-Agent: Mozilla Thunderbird 0.7.3 (X11/20040803) +X-Accept-Language: en-us, en +MIME-Version: 1.0 +X-Newsgroups: comp.databases.postgresql.performance +Subject: Re: Equivalent praxis to CLUSTERED INDEX? +References: +In-Reply-To: +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit +Lines: 36 +Message-ID: +Date: Wed, 08 Sep 2004 15:38:51 GMT +To: pgsql-performance@postgresql.org +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, + hits=1.1 tagged_above=0.0 required=5.0 tests=NO_DNS_FOR_FROM +X-Spam-Level: * +X-Archive-Number: 200409/71 +X-Sequence-Number: 8199 + +Mischa Sandberg wrote: +> Coming from the MSSQL world, I'm used to the first step in optimization +> to be, choose your clustered index and choose it well. +> I see that PG has a one-shot CLUSTER command, but doesn't support +> continuously-updated clustered indexes. +> What I infer from newsgroup browsing is, such an index is impossible, +> given the MVCC versioning of records (happy to learn I'm wrong). +> I'd be curious to know what other people, who've crossed this same +> bridge from MSSQL or Oracle or Sybase to PG, have devised, +> faced with the same kind of desired performance gain for retrieving +> blocks of rows with the same partial key. + +Just to let people know, after trying various options, this looks the +most promising: + +- segment the original table into four tables (call them A,B,C,D) + +- all insertions go into A. +- longterm data lives in B. + +- primary keys of all requests to delete rows from (B) go into D -- no +actual deletions are done against B. Deletions against A happen as normal. + +- all queries are made against a view: a union of A and B and (not +exists) D. + +- daily merge A,B and (where not exists...) D, into C +- run cluster on C, then swap names on B and C, truncate A and D. + +Not rocket science, but it seems to give the payback of normal +clustering without locking the table for long periods of time. It also +saves on VACUUM FULL time. + +At present, we're only at 1M rows in B on this. More when I know it. +Advance warning on any gotchas with this approach would be much +appreciated. Making a complete copy of (B) is a bit of an ouch. + +From pgsql-general-owner@postgresql.org Thu Sep 9 13:56:33 2004 +X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id ADB3A329DCD + for ; + Thu, 9 Sep 2004 13:56:31 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 13447-10 + for ; + Thu, 9 Sep 2004 12:56:25 +0000 (GMT) +Received: from mail.mailsnare.net (v187.mailsnare.net [206.246.200.187]) + by svr1.postgresql.org (Postfix) with ESMTP id D7D46329CF7 + for ; + Thu, 9 Sep 2004 13:56:25 +0100 (BST) +Received: from [172.16.1.33] (adsl-70-241-42-93.dsl.rcsntx.swbell.net + [70.241.42.93]) + by mail.mailsnare.net (Postfix) with ESMTP id BF0E1971E9 + for ; + Thu, 9 Sep 2004 12:56:24 +0000 (UTC) +Message-ID: <414052F4.5050000@portalvu.com> +Date: Thu, 09 Sep 2004 07:56:20 -0500 +From: Vic Cekvenich +Reply-To: vic.cekvenich@portalvu.com +User-Agent: Mozilla Thunderbird 0.7.3 (Windows/20040803) +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: pgsql-general@postgresql.org +Subject: Text Search vs MYSQL vs Lucene +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by ClamAV at mailsnare.net +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/386 +X-Sequence-Number: 65592 + +What would be performance of pgSQL text search vs MySQL vs Lucene (flat +file) for a 2 terabyte db? +thanks for any comments. +.V +-- +Please post on Rich Internet Applications User Interface (RiA/SoA) + + +From pgsql-general-owner@postgresql.org Thu Sep 9 14:39:55 2004 +X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id C677B329E8C; + Thu, 9 Sep 2004 14:39:53 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 33753-08; Thu, 9 Sep 2004 13:39:42 +0000 (GMT) +Received: from frodo.hserus.net (frodo.hserus.net [204.74.68.40]) + by svr1.postgresql.org (Postfix) with ESMTP id EB906329E8A; + Thu, 9 Sep 2004 14:39:45 +0100 (BST) +Received: from [203.199.147.2] (port=34854 helo=ps0499.persistent.co.in) + by frodo.hserus.net with esmtpsa + (Cipher TLSv1:RC4-MD5:128) (Exim 4.42 #0) + id 1C5P9N-000NLB-59 by authid with plain; + Thu, 09 Sep 2004 19:09:45 +0530 +From: Shridhar Daithankar +To: vic.cekvenich@portalvu.com +Subject: Re: Text Search vs MYSQL vs Lucene +Date: Thu, 9 Sep 2004 19:09:33 +0530 +User-Agent: KMail/1.7 +Cc: pgsql-general@postgresql.org, pgsql-performance@postgresql.org +References: <414052F4.5050000@portalvu.com> +In-Reply-To: <414052F4.5050000@portalvu.com> +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +Content-Disposition: inline +Message-Id: <200409091909.33934.shridhar@frodo.hserus.net> +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/391 +X-Sequence-Number: 65597 + +On Thursday 09 Sep 2004 6:26 pm, Vic Cekvenich wrote: +> What would be performance of pgSQL text search vs MySQL vs Lucene (flat +> file) for a 2 terabyte db? + +Well, it depends upon lot of factors. There are few questions to be asked +here.. +- What is your hardware and OS configuration? +- What type of data you are dealing with? Mostly static or frequently updated? +- What type of query you are doing. Aggregates or table scan or selective +retreival etc. + +Unfortunately there is no one good answer. If you could provide details, it +would help a lot.. + + Shridhar + +From pgsql-general-owner@postgresql.org Thu Sep 9 15:14:56 2004 +X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 01B52329D27 + for ; + Thu, 9 Sep 2004 15:14:53 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 49686-07 + for ; + Thu, 9 Sep 2004 14:14:47 +0000 (GMT) +Received: from mail.mailsnare.net (v187.mailsnare.net [206.246.200.187]) + by svr1.postgresql.org (Postfix) with ESMTP id E8568329CE3 + for ; + Thu, 9 Sep 2004 15:14:49 +0100 (BST) +Received: from [172.16.1.33] (adsl-70-241-42-93.dsl.rcsntx.swbell.net + [70.241.42.93]) + by mail.mailsnare.net (Postfix) with ESMTP id E3C1F971F2 + for ; + Thu, 9 Sep 2004 14:14:39 +0000 (UTC) +Message-ID: <4140654A.1000407@portalvu.com> +Date: Thu, 09 Sep 2004 09:14:34 -0500 +From: Vic Cekvenich +Reply-To: vic.cekvenich@portalvu.com +User-Agent: Mozilla Thunderbird 0.7.3 (Windows/20040803) +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: pgsql-general@postgresql.org +Subject: Re: Text Search vs MYSQL vs Lucene +References: <414052F4.5050000@portalvu.com> + <200409091909.33934.shridhar@frodo.hserus.net> +In-Reply-To: <200409091909.33934.shridhar@frodo.hserus.net> +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by ClamAV at mailsnare.net +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/395 +X-Sequence-Number: 65601 + +It be at least dual opteron 64 w 4 gigs of ram runing fedora with a huge +raid striped drives as single volume. +A similar system and types of querries would be this: +http://marc.theaimsgroup.com + +So I guess a table scan. + + +.V + +Shridhar Daithankar wrote: + +>On Thursday 09 Sep 2004 6:26 pm, Vic Cekvenich wrote: +> +> +>>What would be performance of pgSQL text search vs MySQL vs Lucene (flat +>>file) for a 2 terabyte db? +>> +>> +> +>Well, it depends upon lot of factors. There are few questions to be asked +>here.. +>- What is your hardware and OS configuration? +>- What type of data you are dealing with? Mostly static or frequently updated? +>- What type of query you are doing. Aggregates or table scan or selective +>retreival etc. +> +>Unfortunately there is no one good answer. If you could provide details, it +>would help a lot.. +> +> Shridhar +> +>---------------------------(end of broadcast)--------------------------- +>TIP 2: you can get off all lists at once with the unregister command +> (send "unregister YourEmailAddressHere" to majordomo@postgresql.org) +> +> +> +> + + +-- +Please post on Rich Internet Applications User Interface (RiA/SoA) + + +From pgsql-general-owner@postgresql.org Thu Sep 9 15:12:46 2004 +X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 9670E329C70 + for ; + Thu, 9 Sep 2004 15:12:44 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 50738-04 + for ; + Thu, 9 Sep 2004 14:12:31 +0000 (GMT) +Received: from gp.word-to-the-wise.com (gp.word-to-the-wise.com + [64.71.176.18]) + by svr1.postgresql.org (Postfix) with ESMTP id 45201329C67 + for ; + Thu, 9 Sep 2004 15:12:33 +0100 (BST) +Received: by gp.word-to-the-wise.com (Postfix, from userid 500) + id D3507900018; Thu, 9 Sep 2004 07:20:06 -0700 (PDT) +Date: Thu, 9 Sep 2004 07:20:06 -0700 +From: Steve Atkins +To: pgsql-general@postgresql.org +Subject: Re: Text Search vs MYSQL vs Lucene +Message-ID: <20040909142006.GA24396@gp.word-to-the-wise.com> +References: <414052F4.5050000@portalvu.com> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <414052F4.5050000@portalvu.com> +User-Agent: Mutt/1.4.1i +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/394 +X-Sequence-Number: 65600 + +On Thu, Sep 09, 2004 at 07:56:20AM -0500, Vic Cekvenich wrote: + +> What would be performance of pgSQL text search vs MySQL vs Lucene (flat +> file) for a 2 terabyte db? +> thanks for any comments. + +My experience with tsearch2 has been that indexing even moderately +large chunks of data is too slow to be feasible. Moderately large +meaning tens of megabytes. + +Your milage might well vary, but I wouldn't rely on postgresql full +text search of that much data being functional, let alone fast enough +to be useful. Test before making any decisions. + +If it's a static or moderately static text corpus you're probably +better using a traditional FTS system anyway (tsearch2 has two +advantages - tight integration with pgsql and good support for +incremental indexing). + +Two terabytes is a lot of data. I'd suggest you do some research on +FTS algorithms rather than just picking one of the off-the-shelf FTS +systems without understanding what they actually do. "Managing +Gigabytes" ISBN 1-55860-570-3 covers some approaches. + +Cheers, + Steve + +From pgsql-performance-owner@postgresql.org Thu Sep 9 15:56:16 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 3048A329C6B + for ; + Thu, 9 Sep 2004 15:56:15 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 64297-09 + for ; + Thu, 9 Sep 2004 14:56:07 +0000 (GMT) +Received: from mailer.elma.loc (mail.elma.fr [213.41.14.138]) + by svr1.postgresql.org (Postfix) with ESMTP id 1DA87329C67 + for ; + Thu, 9 Sep 2004 15:56:09 +0100 (BST) +Received: from mailer.elma.loc (localhost [127.0.0.1]) + by localhost (Postfix) with ESMTP + id 640EDEC16C; Thu, 9 Sep 2004 15:57:10 +0200 (CEST) +Received: from zoot.elma.fr (herve.elma.fr [10.0.1.2]) + by mailer.elma.loc (Postfix) with ESMTP + id BC7B1EC267; Thu, 9 Sep 2004 15:57:05 +0200 (CEST) +From: =?iso-8859-15?q?Herv=E9_Piedvache?= +Organization: Elma =?iso-8859-15?q?Ing=E9nierie?= Informatique +To: George Essig +Subject: Re: TSearch2 and optimisation ... +Date: Thu, 9 Sep 2004 16:56:01 +0200 +User-Agent: KMail/1.7 +Cc: pgsql-performance@postgresql.org, footcow@noos.fr +References: <20040826175833.32182.qmail@web53703.mail.yahoo.com> +In-Reply-To: <20040826175833.32182.qmail@web53703.mail.yahoo.com> +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-15" +Content-Transfer-Encoding: 8bit +Content-Disposition: inline +Message-Id: <200409091656.02006.herve@elma.fr> +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/54 +X-Sequence-Number: 8182 + +George, + +Le Jeudi 26 Ao�t 2004 19:58, George Essig a �crit : +> Bill Footcow wrote: +> +> ... +> +> > I have done a simple request, looking for title or description having +> > Postgres inside order by rank and date, like this : +> > SELECT a.title, a.id, a.url, to_char(a.r_date, 'DD/MM/YYYY HH24:MI:SS') +> > as dt, s.site_name, s.id_site, case when exists (select id_user from +> > user_choice u where u.id_site=s.id_site and u.id_user = 1) then 1 else 0 +> > end as bookmarked FROM article a, site s +> > WHERE s.id_site = a.id_site +> > AND idxfti @@ to_tsquery('postgresql') +> > ORDER BY rank(idxfti, to_tsquery('postgresql')) DESC, a.r_date DESC; +> > +> > The request takes about 4 seconds ... I have about 1 400 000 records in +> > article and 36 000 records in site table ... it's a Bi-Pentium III 933 +> > MHz server with 1 Gb memory ... I'm using Postgresql 7.4.5 +> > For me this result is very very slow I really need a quicker result with +> > less than 1 second ... +> > The next time I call the same request I have got the result in 439 ms ... +> > but +> +> ... +> +> The first query is slow because the relevant index pages are not cached in +> memory. Everyone experiences this. GiST indexes on tsvector columns can +> get really big. You have done nothing wrong. When you have a lot of +> records, tsearch2 will not run fast without extensive performance tuning. +> +> Read the following: +> +> Optimization +> http://www.sai.msu.su/~megera/postgres/gist/tsearch/V2/docs/oscon_tsearch2/ +>optimization.html +> +> ... + +I have well read many pages about this subject ... but I have not found any +thing for the moment to really help me ... +What can I do to optimize my PostgreSQL configuration for a special use of +Tsearch2 ... +I'm a little dispointed looking the Postgresql Russian search engine using +Tsearch2 is really quick ... why I can't haev the same result with a +bi-pentium III 933 and 1Gb of RAM with the text indexation of 1 500 000 +records ? + +Regards, +-- +Herv� Piedvache + +Elma Ing�nierie Informatique +6 rue du Faubourg Saint-Honor� +F-75008 - Paris - France +Pho. 33-144949901 +Fax. 33-144949902 + +From pgsql-general-owner@postgresql.org Thu Sep 9 16:33:43 2004 +X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id CCA0D329C70 + for ; + Thu, 9 Sep 2004 16:33:25 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 78989-06 + for ; + Thu, 9 Sep 2004 15:33:22 +0000 (GMT) +Received: from 10.hostcorporate.com (unknown [69.41.231.186]) + by svr1.postgresql.org (Postfix) with SMTP id E8C0D329C6B + for ; + Thu, 9 Sep 2004 16:33:18 +0100 (BST) +Received: (qmail 20935 invoked from network); 9 Sep 2004 15:21:53 -0000 +Received: from localhost (HELO localhost.localdomain) (127.0.0.1) + by localhost.10.hostcorporate.com with SMTP; 9 Sep 2004 15:21:53 -0000 +Message-ID: <414077B7.5080808@zara.6.isreserved.com> +Date: Thu, 09 Sep 2004 22:33:11 +0700 +From: David Garamond +User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7b) Gecko/20040421 +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: Steve Atkins +Cc: pgsql-general@postgresql.org +Subject: Re: Text Search vs MYSQL vs Lucene +References: <414052F4.5050000@portalvu.com> + <20040909142006.GA24396@gp.word-to-the-wise.com> +In-Reply-To: <20040909142006.GA24396@gp.word-to-the-wise.com> +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/397 +X-Sequence-Number: 65603 + +Steve Atkins wrote: +>>What would be performance of pgSQL text search vs MySQL vs Lucene (flat +>>file) for a 2 terabyte db? +>>thanks for any comments. +> +> My experience with tsearch2 has been that indexing even moderately +> large chunks of data is too slow to be feasible. Moderately large +> meaning tens of megabytes. + +My experience with MySQL's full text search as well as the various +MySQL-based text indexing programs (forgot the names, it's been a while) +for some 10-20GB of mail archives has been pretty disappointing too. My +biggest gripe is with the indexing speed. It literally takes days to +index less than a million documents. + +I ended up using Swish++. Microsoft's CHM compiler also has pretty +amazing indexing speed (though it crashes quite often when encountering +bad HTML). + +-- +dave + +From pgsql-performance-owner@postgresql.org Thu Sep 9 18:13:11 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 55374329CDB + for ; + Thu, 9 Sep 2004 18:13:06 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 17535-03 + for ; + Thu, 9 Sep 2004 17:13:02 +0000 (GMT) +Received: from mail.osdl.org (fw.osdl.org [65.172.181.6]) + by svr1.postgresql.org (Postfix) with ESMTP id 98BA9329CBC + for ; + Thu, 9 Sep 2004 18:13:01 +0100 (BST) +Received: (from markw@localhost) + by mail.osdl.org (8.11.6/8.11.6) id i89HCt207129; + Thu, 9 Sep 2004 10:12:55 -0700 +Date: Thu, 9 Sep 2004 10:12:55 -0700 +From: Mark Wong +To: Steve Bergman +Cc: Christopher Browne , + pgsql-perform +Subject: Re: fsync vs open_sync +Message-ID: <20040909101255.A3273@osdl.org> +References: <6EE64EF3AB31D5448D0007DD34EEB3412A749A@Herge.rcsinc.local> + + <1094361402.28425.31.camel@voyager.localdomain> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +User-Agent: Mutt/1.2.5i +In-Reply-To: <1094361402.28425.31.camel@voyager.localdomain>; + from steve@rueb.com on Sun, Sep 05, 2004 at 12:16:42AM -0500 +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/55 +X-Sequence-Number: 8183 + +On Sun, Sep 05, 2004 at 12:16:42AM -0500, Steve Bergman wrote: +> On Sat, 2004-09-04 at 23:47 -0400, Christopher Browne wrote: +> > The world rejoiced as merlin.moncure@rcsonline.com ("Merlin Moncure") wrote: +> > > Ok, you were right. I made some tests and NTFS is just not very +> > > good in the general case. I've seen some benchmarks for Reiser4 +> > > that are just amazing. +> > +> > Reiser4 has been sounding real interesting. +> > +> +> Are these independent benchmarks, or the benchmarketing at namesys.com? +> Note that the APPEND, MODIFY, and OVERWRITE phases have been turned off +> on the mongo tests and the other tests have been set to a lexical (non +> default for mongo) mode. I've done some mongo benchmarking myself and +> reiser4 loses to ext3 (data=ordered) in the excluded tests. APPEND +> phase performance is absolutely *horrible*. So they just turned off the +> phases in which reiser4 lost and published the remaining results as +> proof that "resier4 is the fastest filesystem". +> +> See: http://marc.theaimsgroup.com/?l=reiserfs&m=109363302000856 +> +> +> -Steve Bergman +> +> +> + +Reiser4 also isn't optmized for lots of fsyncs (unless it's been done +recently.) I believe the mention fsync performance in their release +notes. I've seen this dramatically hurt performance with our OLTP +workload. + +-- +Mark Wong - - markw@osdl.org +Open Source Development Lab Inc - A non-profit corporation +12725 SW Millikan Way - Suite 400 - Beaverton, OR 97005 +(503) 626-2455 x 32 (office) +(503) 626-2436 (fax) +http://developer.osdl.org/markw/ + +From pgsql-general-owner@postgresql.org Thu Sep 9 18:57:32 2004 +X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 39D45329D9C + for ; + Thu, 9 Sep 2004 18:57:29 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 29607-10 + for ; + Thu, 9 Sep 2004 17:57:24 +0000 (GMT) +Received: from ra.sai.msu.su (ra.sai.msu.su [158.250.29.2]) + by svr1.postgresql.org (Postfix) with ESMTP id 81F58329D8C + for ; + Thu, 9 Sep 2004 18:57:17 +0100 (BST) +Received: from ra (ra [158.250.29.2]) + by ra.sai.msu.su (8.12.10/8.12.10) with ESMTP id i89Hv0QT022860; + Thu, 9 Sep 2004 21:57:00 +0400 (MSD) +Date: Thu, 9 Sep 2004 21:56:59 +0400 (MSD) +From: Oleg Bartunov +X-X-Sender: megera@ra.sai.msu.su +To: Steve Atkins +Cc: pgsql-general@postgresql.org +Subject: Re: Text Search vs MYSQL vs Lucene +In-Reply-To: <20040909142006.GA24396@gp.word-to-the-wise.com> +Message-ID: +References: <414052F4.5050000@portalvu.com> + <20040909142006.GA24396@gp.word-to-the-wise.com> +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/407 +X-Sequence-Number: 65613 + +I'd say indexing of 2 TB of data would be a very costly even for +standalone solution ( no relational database ). +Ideal solution would be to have tsearch2 for current documents and +standalone solution for archive documents. If these solutions share +common parsers,dictionaries and ranking schemes it would be easy to +combine results from two queries. We have prototype for standalone +solution - it's based on OpenFTS, which is already tsearch2 compatible. + + + Oleg +On Thu, 9 Sep 2004, Steve Atkins wrote: + +> On Thu, Sep 09, 2004 at 07:56:20AM -0500, Vic Cekvenich wrote: +> +> > What would be performance of pgSQL text search vs MySQL vs Lucene (flat +> > file) for a 2 terabyte db? +> > thanks for any comments. +> +> My experience with tsearch2 has been that indexing even moderately +> large chunks of data is too slow to be feasible. Moderately large +> meaning tens of megabytes. +> +> Your milage might well vary, but I wouldn't rely on postgresql full +> text search of that much data being functional, let alone fast enough +> to be useful. Test before making any decisions. +> +> If it's a static or moderately static text corpus you're probably +> better using a traditional FTS system anyway (tsearch2 has two +> advantages - tight integration with pgsql and good support for +> incremental indexing). +> +> Two terabytes is a lot of data. I'd suggest you do some research on +> FTS algorithms rather than just picking one of the off-the-shelf FTS +> systems without understanding what they actually do. "Managing +> Gigabytes" ISBN 1-55860-570-3 covers some approaches. +> +> Cheers, +> Steve +> +> ---------------------------(end of broadcast)--------------------------- +> TIP 5: Have you checked our extensive FAQ? +> +> http://www.postgresql.org/docs/faqs/FAQ.html +> + + Regards, + Oleg +_____________________________________________________________ +Oleg Bartunov, sci.researcher, hostmaster of AstroNet, +Sternberg Astronomical Institute, Moscow University (Russia) +Internet: oleg@sai.msu.su, http://www.sai.msu.su/~megera/ +phone: +007(095)939-16-83, +007(095)939-23-83 + +From pgsql-performance-owner@postgresql.org Thu Sep 9 23:52:57 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 85316329E3F + for ; + Thu, 9 Sep 2004 23:51:45 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 25937-07 + for ; + Thu, 9 Sep 2004 22:51:38 +0000 (GMT) +Received: from web12701.mail.yahoo.com (web12701.mail.yahoo.com + [216.136.173.238]) + by svr1.postgresql.org (Postfix) with SMTP id E6B85329E3E + for ; + Thu, 9 Sep 2004 23:51:40 +0100 (BST) +Message-ID: <20040909225137.77822.qmail@web12701.mail.yahoo.com> +Received: from [195.29.104.120] by web12701.mail.yahoo.com via HTTP; + Thu, 09 Sep 2004 15:51:37 PDT +Date: Thu, 9 Sep 2004 15:51:37 -0700 (PDT) +From: +Reply-To: ogjunk-pgjedan@yahoo.com +Subject: Costly "Sort Key" on indexed timestamp column +To: pgsql-performance@postgresql.org +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=1.3 tagged_above=0.0 required=5.0 tests=NO_COST, + NO_REAL_NAME +X-Spam-Level: * +X-Archive-Number: 200409/56 +X-Sequence-Number: 8184 + +Hello, + +I'm tuning my PostgreSQL DB (7.3.4) and have come across a query that +doesn't use an index I created specially for it, and consequently takes +circa 2 seconds to run. :( + +The ugly query looks like this (the important part is really at the +very end - order by piece): + +select userinfo1_.id as id0_, servicepla3_.id as id1_, account2_.id as +id2_, passwordhi4_.id as id3_, userdemogr5_.id as id4_, +userinfo1_.first_name as first_name0_, userinfo1_.last_name as +last_name0_, userinfo1_.email as email0_, userinfo1_.href as href0_, +userinfo1_.last_login_date as last_log6_0_, userinfo1_.login_count as +login_co7_0_, userinfo1_.password_hint_answer as password8_0_, +userinfo1_.create_date as create_d9_0_, userinfo1_.exp_date as +exp_date0_, userinfo1_.type as type0_, userinfo1_.account_id as +account_id0_, userinfo1_.plan_id as plan_id0_, +userinfo1_.password_hint_id as passwor14_0_, +userinfo1_.user_demographic_id as user_de15_0_, servicepla3_.name as +name1_, servicepla3_.max_links as max_links1_, account2_.username as +username2_, account2_.password as password2_, account2_.status as +status2_, passwordhi4_.question as question3_, userdemogr5_.city as +city4_, userdemogr5_.postal_code as postal_c3_4_, +userdemogr5_.country_id as country_id4_, +userdemogr5_.state_id as state_id4_, userdemogr5_.gender_id as +gender_id4_ from user_preference userprefer0_ inner join user_info +userinfo1_ on userprefer0_.user_id=userinfo1_.id inner join account +account2_ on userinfo1_.account_id=account2_.id inner join service_plan +servicepla3_ on userinfo1_.plan_id=servicepla3_.id left outer join +password_hint passwordhi4_ on +userinfo1_.password_hint_id=passwordhi4_.id inner join user_demographic +userdemogr5_ on userinfo1_.user_demographic_id=userdemogr5_.id, +preference preference6_, preference_value preference7_ where +(preference6_.name='allow_subscribe' and +userprefer0_.preference_id=preference6_.id)AND(preference7_.value=1 +and userprefer0_.preference_value_id=preference7_.id) order by +userinfo1_.create_date desc limit 10; + + +The output of EXPLAIN ANALYZE follows. Note how 99% of the total cost +comes from "Sort Key: userinfo1_.create_date". When I saw this, I +created an index for this: + +CREATE INDEX ix_user_info_create_date ON user_info(create_date); + +But that didn't seem to make much of a difference. The total cost did +go down from about 1250 to 1099, but that's still too high. + +--------------------------------------------------------- + Limit (cost=1099.35..1099.38 rows=10 width=222) (actual +time=1914.13..1914.17 rows=10 loops=1) + -> Sort (cost=1099.35..1099.43 rows=31 width=222) (actual +time=1914.12..1914.14 rows=11 loops=1) + Sort Key: userinfo1_.create_date + -> Hash Join (cost=90.71..1098.60 rows=31 width=222) (actual +time=20.34..1908.41 rows=767 loops=1) + Hash Cond: ("outer".preference_value_id = "inner".id) + -> Hash Join (cost=89.28..1092.58 rows=561 width=218) +(actual time=19.92..1886.59 rows=768 loops=1) + Hash Cond: ("outer".preference_id = "inner".id) + -> Hash Join (cost=88.10..1045.14 rows=7850 +width=214) (actual time=19.44..1783.47 rows=9984 loops=1) + Hash Cond: ("outer".user_demographic_id = +"inner".id) + -> Hash Join (cost=72.59..864.51 rows=8933 +width=190) (actual time=14.83..1338.15 rows=9984 loops=1) + Hash Cond: ("outer".password_hint_id = +"inner".id) + -> Hash Join (cost=71.50..726.87 +rows=8933 width=161) (actual time=14.53..1039.69 rows=9984 loops=1) + Hash Cond: ("outer".plan_id = +"inner".id) + -> Hash Join +(cost=70.42..569.46 rows=8933 width=144) (actual time=14.26..700.80 +rows=9984 loops=1) + Hash Cond: +("outer".account_id = "inner".id) + -> Hash Join +(cost=53.83..390.83 rows=10073 width=116) (actual time=9.67..373.71 +rows=9984 loops=1) + Hash Cond: +("outer".user_id = "inner".id) + -> Seq Scan on +user_preference userprefer0_ (cost=0.00..160.73 rows=10073 width=12) +(actual time=0.09..127.64 rows=9984 loops=1) + -> Hash +(cost=51.66..51.66 rows=866 width=104) (actual time=9.40..9.40 rows=0 +loops=1) + -> Seq Scan +on user_info userinfo1_ (cost=0.00..51.66 rows=866 width=104) (actual +time=0.12..7.15 rows=768 loops=1) + -> Hash +(cost=14.68..14.68 rows=768 width=28) (actual time=4.45..4.45 rows=0 +loops=1) + -> Seq Scan on +account account2_ (cost=0.00..14.68 rows=768 width=28) (actual +time=0.10..2.56 rows=768 loops=1) + -> Hash (cost=1.06..1.06 +rows=6 width=17) (actual time=0.13..0.13 rows=0 loops=1) + -> Seq Scan on +service_plan servicepla3_ (cost=0.00..1.06 rows=6 width=17) (actual +time=0.10..0.11 rows=6 loops=1) + -> Hash (cost=1.07..1.07 rows=7 +width=29) (actual time=0.15..0.15 rows=0 loops=1) + -> Seq Scan on password_hint +passwordhi4_ (cost=0.00..1.07 rows=7 width=29) (actual +time=0.11..0.13 rows=7 loops=1) + -> Hash (cost=13.61..13.61 rows=761 +width=24) (actual time=4.46..4.46 rows=0 loops=1) + -> Seq Scan on user_demographic +userdemogr5_ (cost=0.00..13.61 rows=761 width=24) (actual +time=0.10..2.73 rows=769 loops=1) + -> Hash (cost=1.18..1.18 rows=1 width=4) (actual +time=0.16..0.16 rows=0 loops=1) + -> Seq Scan on preference preference6_ +(cost=0.00..1.18 rows=1 width=4) (actual time=0.14..0.15 +rows=1 loops=1) + Filter: (name = +'allow_subscribe'::character varying) + -> Hash (cost=1.43..1.43 rows=2 width=4) (actual +time=0.23..0.23 rows=0 loops=1) + -> Seq Scan on preference_value preference7_ +(cost=0.00..1.43 rows=2 width=4) (actual time=0.17..0.21 +rows=3 loops=1) + Filter: ((value)::text = '1'::text) + Total runtime: 1914.91 msec +(35 rows) + + + +There are a few Seq Scan's, but they are benign, as their low/no cost +shows - they are very small, 'static' tables (e.g. country list, state +list, preference names list). + +Does anyone have any ideas how I could speed up this query? + +Thanks, +Otis + + +From pgsql-performance-owner@postgresql.org Fri Sep 10 00:06:46 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id DADFD329E40 + for ; + Fri, 10 Sep 2004 00:06:24 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 32770-03 + for ; + Thu, 9 Sep 2004 23:06:18 +0000 (GMT) +Received: from sue.samurai.com (sue.samurai.com [205.207.28.74]) + by svr1.postgresql.org (Postfix) with ESMTP id E316A329E3A + for ; + Fri, 10 Sep 2004 00:06:19 +0100 (BST) +Received: from localhost (localhost [127.0.0.1]) + by sue.samurai.com (Postfix) with ESMTP id 6F3A93F14; + Thu, 9 Sep 2004 19:06:19 -0400 (EDT) +Received: from sue.samurai.com ([127.0.0.1]) + by localhost (sue.samurai.com [127.0.0.1]) (amavisd-new, port 10024) + with LMTP id 57340-01; Thu, 9 Sep 2004 19:06:18 -0400 (EDT) +Received: from [127.0.0.1] (unknown [61.88.101.19]) + by sue.samurai.com (Postfix) with ESMTP id 8E4073E73; + Thu, 9 Sep 2004 19:06:17 -0400 (EDT) +Message-ID: <4140E1EF.1040303@samurai.com> +Date: Fri, 10 Sep 2004 09:06:23 +1000 +From: Neil Conway +User-Agent: Mozilla Thunderbird 0.7 (Macintosh/20040616) +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: Tom Lane +Cc: Markus Schaber , + PostgreSQL Performance List +Subject: Re: Multiple Uniques +References: <20040902154340.5b1a669a@kingfisher.intern.logi-track.com> + <19516.1094134957@sss.pgh.pa.us> +In-Reply-To: <19516.1094134957@sss.pgh.pa.us> +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at mailbox.samurai.com +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/57 +X-Sequence-Number: 8185 + +Tom Lane wrote: +> Markus Schaber writes: +>>So, now my question is, why does the query optimizer not recognize that +>>it can throw away those "non-unique" Sort/Unique passes? +> +> Because the issue doesn't come up often enough to justify expending +> cycles to check for it. + +How many cycles are we really talking about, though? I have a patch +which I'll send along in a few days which implements a similar +optimization: if a subselect is referenced by EXISTS or IN, we can +discard DISTINCT and ORDER BY clauses in the subquery (actually, we +can't discard ORDER BY in the case of IN if LIMIT is also specified, but +the point remains). It's very cheap computationally for the planner to +do this simplification, and I'd imagine doing the equivalent +simplifications for UNION is similarly cheap. + +While I understand what you're saying WRT to it being a silly query, in +the real world people make mistakes... + +-Neil + +From pgsql-performance-owner@postgresql.org Fri Sep 10 04:07:29 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 049A4329E12 + for ; + Fri, 10 Sep 2004 04:07:20 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 86915-09 + for ; + Fri, 10 Sep 2004 03:07:16 +0000 (GMT) +Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) + by svr1.postgresql.org (Postfix) with ESMTP id D79EA329D15 + for ; + Fri, 10 Sep 2004 04:07:14 +0100 (BST) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i8A37BT3013335; + Thu, 9 Sep 2004 23:07:11 -0400 (EDT) +To: Neil Conway +Cc: Markus Schaber , + PostgreSQL Performance List +Subject: Re: Multiple Uniques +In-reply-to: <4140E1EF.1040303@samurai.com> +References: <20040902154340.5b1a669a@kingfisher.intern.logi-track.com> + <19516.1094134957@sss.pgh.pa.us> <4140E1EF.1040303@samurai.com> +Comments: In-reply-to Neil Conway + message dated "Fri, 10 Sep 2004 09:06:23 +1000" +Date: Thu, 09 Sep 2004 23:07:11 -0400 +Message-ID: <13334.1094785631@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/58 +X-Sequence-Number: 8186 + +Neil Conway writes: +> Tom Lane wrote: +>> Because the issue doesn't come up often enough to justify expending +>> cycles to check for it. + +> How many cycles are we really talking about, though? I have a patch +> which I'll send along in a few days which implements a similar +> optimization: if a subselect is referenced by EXISTS or IN, we can +> discard DISTINCT and ORDER BY clauses in the subquery + +I don't think either of those is worth doing. ORDER BY in a sub-select +isn't even legal SQL, much less probable, so why should we expend even +a nanosecond to optimize it? The DISTINCT is more of a judgment call, +but my thought when I looked at it originally is that it would give +people a possible optimization knob. If you write DISTINCT in an IN +clause then you can get a different plan (the IN reduces to an ordinary +join) that might or might not be better than without it. We shouldn't +take away that possibility just on the grounds of nanny-ism. + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Fri Sep 10 05:17:19 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 7C963329E47 + for ; + Fri, 10 Sep 2004 05:17:17 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 06599-06 + for ; + Fri, 10 Sep 2004 04:17:12 +0000 (GMT) +Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) + by svr1.postgresql.org (Postfix) with ESMTP id 07A90329E46 + for ; + Fri, 10 Sep 2004 05:17:12 +0100 (BST) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i8A4HBU5014021; + Fri, 10 Sep 2004 00:17:12 -0400 (EDT) +To: ogjunk-pgjedan@yahoo.com +Cc: pgsql-performance@postgresql.org +Subject: Re: Costly "Sort Key" on indexed timestamp column +In-reply-to: <20040909225137.77822.qmail@web12701.mail.yahoo.com> +References: <20040909225137.77822.qmail@web12701.mail.yahoo.com> +Comments: In-reply-to + message dated "Thu, 09 Sep 2004 15:51:37 -0700" +Date: Fri, 10 Sep 2004 00:17:11 -0400 +Message-ID: <14020.1094789831@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/59 +X-Sequence-Number: 8187 + + writes: +> I'm tuning my PostgreSQL DB (7.3.4) and have come across a query that +> doesn't use an index I created specially for it, and consequently takes +> circa 2 seconds to run. :( +> ... +> The output of EXPLAIN ANALYZE follows. Note how 99% of the total cost +> comes from "Sort Key: userinfo1_.create_date". + +No, you are misreading the output. 99% of the cost comes from the join +steps. + +I think the problem is that you have forced a not-very-appropriate join +order by use of INNER JOIN syntax, and so the plan is creating +intermediate join outputs that are larger than they need be. See +http://www.postgresql.org/docs/7.3/static/explicit-joins.html + +7.4 is a bit more forgiving about this; compare +http://www.postgresql.org/docs/7.4/static/explicit-joins.html + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Fri Sep 10 07:34:42 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id B90EB329CAE + for ; + Fri, 10 Sep 2004 07:34:41 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 37847-10 + for ; + Fri, 10 Sep 2004 06:34:35 +0000 (GMT) +Received: from stark.xeocode.com (gsstark.mtl.istop.com [66.11.160.162]) + by svr1.postgresql.org (Postfix) with ESMTP id 5BEE0329C7B + for ; + Fri, 10 Sep 2004 07:34:35 +0100 (BST) +Received: from localhost ([127.0.0.1] helo=stark.xeocode.com) + by stark.xeocode.com with smtp (Exim 3.36 #1 (Debian)) + id 1C5ezM-0006jY-00; Fri, 10 Sep 2004 02:34:28 -0400 +To: Tom Lane +Cc: Neil Conway , Markus Schaber , + PostgreSQL Performance List +Subject: Re: Multiple Uniques +References: <20040902154340.5b1a669a@kingfisher.intern.logi-track.com> + <19516.1094134957@sss.pgh.pa.us> <4140E1EF.1040303@samurai.com> + <13334.1094785631@sss.pgh.pa.us> +In-Reply-To: <13334.1094785631@sss.pgh.pa.us> +From: Greg Stark +Organization: The Emacs Conspiracy; member since 1992 +Date: 10 Sep 2004 02:34:28 -0400 +Message-ID: <877jr2tyx7.fsf@stark.xeocode.com> +Lines: 37 +User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/60 +X-Sequence-Number: 8188 + + +Tom Lane writes: + +> Neil Conway writes: +> +> > How many cycles are we really talking about, though? I have a patch +> > which I'll send along in a few days which implements a similar +> > optimization: if a subselect is referenced by EXISTS or IN, we can +> > discard DISTINCT and ORDER BY clauses in the subquery +> +> I don't think either of those is worth doing. ORDER BY in a sub-select +> isn't even legal SQL, much less probable, so why should we expend even +> a nanosecond to optimize it? The DISTINCT is more of a judgement call, +> but my thought when I looked at it originally is that it would give +> people a possible optimization knob. If you write DISTINCT in an IN +> clause then you can get a different plan (the IN reduces to an ordinary +> join) that might or might not be better than without it. We shouldn't +> take away that possibility just on the grounds of nanny-ism. + +Just one user's 2c: Consider the plight of dynamically constructed queries. +The queries within "IN" clauses are particularly likely to be constructed this +way. The query in the IN clause could be a constructed in an entirely separate +function without any idea that it will be used within an IN clause. + +E.g. something like: + +$accessible_ids = $security_manager->get_accessible_ids_query($this->userid); +$selected_columns = $this->selected_columns_parameters(); +$query = "select $selected_columns where id IN ($accessible_ids)" + +In an ideal world functionally equivalent queries should always generate +identical plans. Of course there are limitations, it's not an ideal world, but +as much as possible it should be possible to write code without having to +worry whether the optimizer will be able to figure it out. + +-- +greg + + +From pgsql-performance-owner@postgresql.org Fri Sep 10 14:22:42 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 1147C329DD0 + for ; + Fri, 10 Sep 2004 14:22:41 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 64521-04 + for ; + Fri, 10 Sep 2004 13:22:32 +0000 (GMT) +Received: from ganymede.hub.org (blk-222-46-91.eastlink.ca [24.222.46.91]) + by svr1.postgresql.org (Postfix) with ESMTP id 537BB329DBF + for ; + Fri, 10 Sep 2004 14:22:34 +0100 (BST) +Received: by ganymede.hub.org (Postfix, from userid 1000) + id CC0DF36D4D; Fri, 10 Sep 2004 10:22:36 -0300 (ADT) +Received: from localhost (localhost [127.0.0.1]) + by ganymede.hub.org (Postfix) with ESMTP id CB14435325 + for ; + Fri, 10 Sep 2004 10:22:36 -0300 (ADT) +X-Return-Path: +X-Received: from localhost ([unix socket]) + by ganymede.hub.org (Cyrus v2.2.8) with LMTPA; + Fri, 10 Sep 2004 03:36:11 -0300 +X-Sieve: CMU Sieve 2.2 +X-Received: from localhost (localhost.hub.org [127.0.0.1]) + by ganymede.hub.org (Postfix) with ESMTP id 357513A362 + for ; Fri, 10 Sep 2004 03:35:47 -0300 (ADT) +X-Received: from mail.postgresql.org [200.46.204.71] + by localhost with IMAP (fetchmail-6.2.5) + for scrappy@localhost (single-drop); + Fri, 10 Sep 2004 03:35:47 -0300 (ADT) +X-Received: from svr1.postgresql.org ([unix socket]) + by svr1.postgresql.org (Cyrus v2.2.8) with LMTPA; + Fri, 10 Sep 2004 07:35:42 +0100 +X-Sieve: CMU Sieve 2.2 +X-Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 31507329D18 + for ; Fri, 10 Sep 2004 07:35:42 +0100 (BST) +X-Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 39156-08 for ; + Fri, 10 Sep 2004 06:35:36 +0000 (GMT) +X-Received: from boutiquenumerique.com (gailleton-2-82-67-9-10.fbx.proxad.net + [82.67.9.10]) + by svr1.postgresql.org (Postfix) with ESMTP id 853AE329D03 + for ; Fri, 10 Sep 2004 07:35:34 +0100 (BST) +X-Received: (qmail 8234 invoked from network); 10 Sep 2004 08:35:39 +0200 +X-Received: from unknown (HELO musicbox) (192.168.0.2) + by gailleton-2-82-67-9-10.fbx.proxad.net with SMTP; + 10 Sep 2004 08:35:39 +0200 +To: performance@postgresql.org +Subject: Question on Byte Sizes +References: <20040902154340.5b1a669a@kingfisher.intern.logi-track.com> + <19516.1094134957@sss.pgh.pa.us> <4140E1EF.1040303@samurai.com> + <13334.1094785631@sss.pgh.pa.us> +Message-ID: +Date: Fri, 10 Sep 2004 08:36:16 +0200 +From: =?iso-8859-15?Q?Pierre-Fr=E9d=E9ric_Caillaud?= + +Organization: =?iso-8859-15?Q?La_Boutique_Num=E9rique?= +Content-Type: text/plain; format=flowed; delsp=yes; charset=iso-8859-15 +MIME-Version: 1.0 +Content-Transfer-Encoding: 8bit +In-Reply-To: <13334.1094785631@sss.pgh.pa.us> +User-Agent: Opera M2/7.53 (Linux, build 737) +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-DCC: : +X-Spam-Pyzor: +ReSent-Date: Fri, 10 Sep 2004 10:22:32 -0300 (ADT) +Resent-From: "Marc G. Fournier" +Resent-To: pgsql-performance@postgresql.org +ReSent-Subject: Question on Byte Sizes +ReSent-Message-ID: <20040910102232.T47328@ganymede.hub.org> +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/61 +X-Sequence-Number: 8189 + +Hello, + +* I need information on the size of pg ARRAY[]'s : + +I did not find any info in the Docs on this. +How many bytes does an array take on disk ? + +Is there a difference between an array of fixed size elements like +integers, and an array of variable length elements like text ? is there a +pointer table ? Or are the elements packed together ? + +Is there any advantage in using a smallint[] over an integer[] regarding +size ? + +Does a smallint[] with 2 elements really take 12 bytes ? + +* On Alignment : + +The docs say fields are aligned on 4-bytes boundaries. +Does this mean that several consecutive smallint fields will take 4 bytes +each ? +What about seleral consecutive "char" fields ? 4 bytes each too ? + +I ask this because I'll have a lot of columns with small values to store +in a table, and +would like it to be small and to fit in the cache. + + +Thanks for any info. + +From pgsql-performance-owner@postgresql.org Fri Sep 10 22:02:46 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 1F5B8329E50 + for ; + Fri, 10 Sep 2004 22:02:03 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 15421-02 + for ; + Fri, 10 Sep 2004 21:01:55 +0000 (GMT) +Received: from mproxy.gmail.com (rproxy.gmail.com [64.233.170.203]) + by svr1.postgresql.org (Postfix) with ESMTP id 583E3329E58 + for ; + Fri, 10 Sep 2004 22:01:54 +0100 (BST) +Received: by mproxy.gmail.com with SMTP id 73so547622rnk + for ; + Fri, 10 Sep 2004 14:01:42 -0700 (PDT) +Received: by 10.38.59.62 with SMTP id h62mr2185128rna; + Fri, 10 Sep 2004 14:01:42 -0700 (PDT) +Received: by 10.38.181.20 with HTTP; Fri, 10 Sep 2004 14:01:42 -0700 (PDT) +Message-ID: +Date: Fri, 10 Sep 2004 15:01:42 -0600 +From: Joey Smith +Reply-To: Joey Smith +To: pgsql-performance@postgresql.org +Subject: Interesting performance behaviour +Mime-Version: 1.0 +Content-Type: text/plain; charset=US-ASCII +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/62 +X-Sequence-Number: 8190 + +#postgresql on Freenode recommended I post this here. + +I'm seeing some odd behaviour with LIMIT. The query plans are included +here, as are the applicable table and index definitions. All table, +index, and query information can be found in a standard dbmail 1.2.6 +install, if anyone wants to try setting up an exactly similar system. + +Version: PostgreSQL 7.4.3 on i386-pc-linux-gnu, compiled by GCC +i386-linux-gcc (GCC) 3.3.4 (Debian 1:3.3.4-3) +OS: Debian Linux, "unstable" tree + +Some settings that I was told to include (as far as I am aware, these +are debian default values): +shared_buffers = 1000 +sort_mem = 1024 +effective_cache_size = 1000 + + +Table/index definitions: + + Table "public.messages" + Column | Type | Modifiers +---------------+--------------------------------+---------------------------------------------------- + message_idnr | bigint | not null default +nextval('message_idnr_seq'::text) + mailbox_idnr | bigint | not null default 0 + messagesize | bigint | not null default 0 + seen_flag | smallint | not null default 0 + answered_flag | smallint | not null default 0 + deleted_flag | smallint | not null default 0 + flagged_flag | smallint | not null default 0 + recent_flag | smallint | not null default 0 + draft_flag | smallint | not null default 0 + unique_id | character varying(70) | not null + internal_date | timestamp(6) without time zone | + status | smallint | not null default 0 + rfcsize | bigint | not null default 0 + queue_id | character varying(40) | not null default +''::character varying +Indexes: + "messages_pkey" primary key, btree (message_idnr) + "idx_mailbox_idnr_queue_id" btree (mailbox_idnr, queue_id) +Foreign-key constraints: + "ref141" FOREIGN KEY (mailbox_idnr) REFERENCES +mailboxes(mailbox_idnr) ON UPDATE CASCADE ON DELETE CASCADE + + + + +EXPLAIN ANALYZE results: + + + EXPLAIN ANALYZE SELECT message_idnr FROM messages WHERE mailbox_idnr += 1746::bigint AND status<2::smallint AND seen_flag = 0 AND unique_id +!= '' ORDER BY message_idnr ASC LIMIT 1; + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------------------------- + Limit (cost=0.00..848.36 rows=1 width=8) (actual +time=1173.949..1173.953 rows=1 loops=1) + -> Index Scan using messages_pkey on messages +(cost=0.00..367338.15 rows=433 width=8) (actual +time=1173.939..1173.939 rows=1 loops=1) + Filter: ((mailbox_idnr = 1746::bigint) AND (status < +2::smallint) AND (seen_flag = 0) AND ((unique_id)::text <> ''::text)) + Total runtime: 1174.012 ms + + +EXPLAIN ANALYZE SELECT message_idnr FROM messages WHERE mailbox_idnr = +1746::bigint AND status<2::smallint AND seen_flag = 0 AND unique_id != +'' ORDER BY message_idnr ASC ; + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------------------------------ + Sort (cost=2975.42..2976.50 rows=433 width=8) (actual +time=2.357..2.545 rows=56 loops=1) + Sort Key: message_idnr + -> Index Scan using idx_mailbox_idnr_queue_id on messages +(cost=0.00..2956.46 rows=433 width=8) (actual time=0.212..2.124 +rows=56 loops=1) + Index Cond: (mailbox_idnr = 1746::bigint) + Filter: ((status < 2::smallint) AND (seen_flag = 0) AND +((unique_id)::text <> ''::text)) + Total runtime: 2.798 ms + + +I see a similar speedup (and change in query plan) using "LIMIT 1 +OFFSET ". + +From pgsql-performance-owner@postgresql.org Fri Sep 10 22:46:07 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 053FF329E5D + for ; + Fri, 10 Sep 2004 22:45:59 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 24581-08 + for ; + Fri, 10 Sep 2004 21:45:51 +0000 (GMT) +Received: from davinci.ethosmedia.com (server226.ethosmedia.com + [209.128.84.226]) + by svr1.postgresql.org (Postfix) with ESMTP id 736C9329E51 + for ; + Fri, 10 Sep 2004 22:45:52 +0100 (BST) +Received: from [64.81.245.111] (account josh@agliodbs.com HELO + temoku.sf.agliodbs.com) + by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.1.8) + with ESMTP id 6327157; Fri, 10 Sep 2004 14:47:10 -0700 +From: Josh Berkus +Reply-To: josh@agliodbs.com +Organization: Aglio Database Solutions +To: Joey Smith +Subject: Re: Interesting performance behaviour +Date: Fri, 10 Sep 2004 14:46:53 -0700 +User-Agent: KMail/1.6.2 +Cc: pgsql-performance@postgresql.org +References: +In-Reply-To: +MIME-Version: 1.0 +Content-Disposition: inline +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +Message-Id: <200409101446.53309.josh@agliodbs.com> +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/63 +X-Sequence-Number: 8191 + +Joey, + +> shared_buffers = 1000 +> sort_mem = 1024 +> effective_cache_size = 1000 + +effective_cache_size should be much higher, like 3/4 of your available RAM. +This is probably the essence of your planner problem; the planner thinks you +have no RAM. + +> I see a similar speedup (and change in query plan) using "LIMIT 1 +> OFFSET ". + +So what's your problem? + +-- +--Josh + +Josh Berkus +Aglio Database Solutions +San Francisco + +From pgsql-performance-owner@postgresql.org Fri Sep 10 23:00:26 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 79356329E5C + for ; + Fri, 10 Sep 2004 23:00:21 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 31391-01 + for ; + Fri, 10 Sep 2004 22:00:07 +0000 (GMT) +Received: from web12707.mail.yahoo.com (web12707.mail.yahoo.com + [216.136.173.244]) + by svr1.postgresql.org (Postfix) with SMTP id 35A37329E64 + for ; + Fri, 10 Sep 2004 23:00:08 +0100 (BST) +Message-ID: <20040910220007.62759.qmail@web12707.mail.yahoo.com> +Received: from [195.29.103.60] by web12707.mail.yahoo.com via HTTP; + Fri, 10 Sep 2004 15:00:07 PDT +Date: Fri, 10 Sep 2004 15:00:07 -0700 (PDT) +From: +Reply-To: ogjunk-pgjedan@yahoo.com +Subject: effective_cache_size in 7.3.4? +To: pgsql-performance@postgresql.org +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.3 tagged_above=0.0 required=5.0 tests=NO_REAL_NAME +X-Spam-Level: +X-Archive-Number: 200409/64 +X-Sequence-Number: 8192 + +Hello, + +I saw a few mentions of 'effective_cache_size' parameter. Is this a +new PG 7.4 option? I have PG 7.3.4 and didn't see that parameter in my +postgresql.conf. + +Thanks, +Otis + + +From pgsql-performance-owner@postgresql.org Fri Sep 10 23:01:30 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id CE2F3329E64 + for ; + Fri, 10 Sep 2004 23:01:27 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 28917-06 + for ; + Fri, 10 Sep 2004 22:01:20 +0000 (GMT) +Received: from mproxy.gmail.com (rproxy.gmail.com [64.233.170.197]) + by svr1.postgresql.org (Postfix) with ESMTP id 4F86D329E58 + for ; + Fri, 10 Sep 2004 23:01:21 +0100 (BST) +Received: by mproxy.gmail.com with SMTP id 73so553013rnk + for ; + Fri, 10 Sep 2004 15:01:21 -0700 (PDT) +Received: by 10.38.102.34 with SMTP id z34mr86115rnb; + Fri, 10 Sep 2004 15:01:21 -0700 (PDT) +Received: by 10.38.181.20 with HTTP; Fri, 10 Sep 2004 15:01:21 -0700 (PDT) +Message-ID: +Date: Fri, 10 Sep 2004 16:01:21 -0600 +From: Joey Smith +Reply-To: Joey Smith +To: josh@agliodbs.com +Subject: Re: Interesting performance behaviour +Cc: pgsql-performance@postgresql.org +In-Reply-To: <200409101446.53309.josh@agliodbs.com> +Mime-Version: 1.0 +Content-Type: text/plain; charset=US-ASCII +Content-Transfer-Encoding: 7bit +References: + <200409101446.53309.josh@agliodbs.com> +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/65 +X-Sequence-Number: 8193 + +> > shared_buffers = 1000 +> > sort_mem = 1024 +> > effective_cache_size = 1000 +> +> effective_cache_size should be much higher, like 3/4 of your available RAM. +> This is probably the essence of your planner problem; the planner thinks you +> have no RAM. + +I set effective_cache_size to 64000 on a machine with 2GB of physical +RAM, and the behaviour is exactly the same. + +From pgsql-performance-owner@postgresql.org Fri Sep 10 23:02:17 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 5A4DA329E6A + for ; + Fri, 10 Sep 2004 23:02:15 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 30541-05 + for ; + Fri, 10 Sep 2004 22:02:07 +0000 (GMT) +Received: from mproxy.gmail.com (rproxy.gmail.com [64.233.170.204]) + by svr1.postgresql.org (Postfix) with ESMTP id 0FA64329E6C + for ; + Fri, 10 Sep 2004 23:02:05 +0100 (BST) +Received: by mproxy.gmail.com with SMTP id 73so553067rnk + for ; + Fri, 10 Sep 2004 15:02:05 -0700 (PDT) +Received: by 10.38.22.67 with SMTP id 67mr2240688rnv; + Fri, 10 Sep 2004 15:02:05 -0700 (PDT) +Received: by 10.38.181.20 with HTTP; Fri, 10 Sep 2004 15:02:05 -0700 (PDT) +Message-ID: +Date: Fri, 10 Sep 2004 16:02:05 -0600 +From: Joey Smith +Reply-To: Joey Smith +To: pgsql-performance@postgresql.org +Subject: Fwd: Interesting performance behaviour +In-Reply-To: +Mime-Version: 1.0 +Content-Type: text/plain; charset=US-ASCII +Content-Transfer-Encoding: 7bit +References: + <200409101446.53309.josh@agliodbs.com> + +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/66 +X-Sequence-Number: 8194 + +Accidentally sent directly to Josh. + + +---------- Forwarded message ---------- +From: Joey Smith +Date: Fri, 10 Sep 2004 15:57:49 -0600 +Subject: Re: [PERFORM] Interesting performance behaviour +To: josh@agliodbs.com + +> > I see a similar speedup (and change in query plan) using "LIMIT 1 +> > OFFSET ". +> +> So what's your problem? + +The problem is that "LIMIT 1 OFFSET 0" has such poor performance. I'm +not so much worried about the query time (it's still low enough to be +acceptable), but the fact that it behaves oddly raised the question of +whether this was correct behaviour or not. I'll try it with a saner +value for effective_cache_size. + +From pgsql-performance-owner@postgresql.org Fri Sep 10 23:03:16 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 42B7A329E6C + for ; + Fri, 10 Sep 2004 23:03:14 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 28065-09 + for ; + Fri, 10 Sep 2004 22:03:06 +0000 (GMT) +Received: from davinci.ethosmedia.com (server226.ethosmedia.com + [209.128.84.226]) + by svr1.postgresql.org (Postfix) with ESMTP id D0412329CFD + for ; + Fri, 10 Sep 2004 23:03:08 +0100 (BST) +Received: from [64.81.245.111] (account josh@agliodbs.com HELO + temoku.sf.agliodbs.com) + by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.1.8) + with ESMTP id 6327399; Fri, 10 Sep 2004 15:04:26 -0700 +From: Josh Berkus +Reply-To: josh@agliodbs.com +Organization: Aglio Database Solutions +To: ogjunk-pgjedan@yahoo.com +Subject: Re: effective_cache_size in 7.3.4? +Date: Fri, 10 Sep 2004 15:04:09 -0700 +User-Agent: KMail/1.6.2 +Cc: pgsql-performance@postgresql.org +References: <20040910220007.62759.qmail@web12707.mail.yahoo.com> +In-Reply-To: <20040910220007.62759.qmail@web12707.mail.yahoo.com> +MIME-Version: 1.0 +Content-Disposition: inline +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +Message-Id: <200409101504.09537.josh@agliodbs.com> +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/67 +X-Sequence-Number: 8195 + +Otis, + +> I saw a few mentions of 'effective_cache_size' parameter. Is this a +> new PG 7.4 option? I have PG 7.3.4 and didn't see that parameter in my +> postgresql.conf. + +Nope. AFAIK, it's been around since 7.0. Maybe you accidentally cut it out +of your postgresql.conf? + +-- +--Josh + +Josh Berkus +Aglio Database Solutions +San Francisco + +From pgsql-performance-owner@postgresql.org Fri Sep 10 23:10:12 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id BADB6329E64 + for ; + Fri, 10 Sep 2004 23:10:04 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 30541-10 + for ; + Fri, 10 Sep 2004 22:09:57 +0000 (GMT) +Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) + by svr1.postgresql.org (Postfix) with ESMTP id 30AF8329D28 + for ; + Fri, 10 Sep 2004 23:09:58 +0100 (BST) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i8AM9wUh003313; + Fri, 10 Sep 2004 18:09:58 -0400 (EDT) +To: Joey Smith +Cc: pgsql-performance@postgresql.org +Subject: Re: Interesting performance behaviour +In-reply-to: +References: +Comments: In-reply-to Joey Smith + message dated "Fri, 10 Sep 2004 15:01:42 -0600" +Date: Fri, 10 Sep 2004 18:09:57 -0400 +Message-ID: <3312.1094854197@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/68 +X-Sequence-Number: 8196 + +Joey Smith writes: +> EXPLAIN ANALYZE SELECT message_idnr FROM messages WHERE mailbox_idnr +> = 1746::bigint AND status<2::smallint AND seen_flag = 0 AND unique_id +> != '' ORDER BY message_idnr ASC LIMIT 1; +> QUERY PLAN +> ------------------------------------------------------------------------------------------------------------------------------------------- +> Limit (cost=0.00..848.36 rows=1 width=8) (actual +> time=1173.949..1173.953 rows=1 loops=1) +> -> Index Scan using messages_pkey on messages +> (cost=0.00..367338.15 rows=433 width=8) (actual +> time=1173.939..1173.939 rows=1 loops=1) +> Filter: ((mailbox_idnr = 1746::bigint) AND (status < +> 2::smallint) AND (seen_flag = 0) AND ((unique_id)::text <> ''::text)) +> Total runtime: 1174.012 ms + +The planner is correctly estimating that this plan is very expensive +overall --- but it is guessing that the indexscan will only need to be +run 1/433'd of the way to completion before the single required row is +found. So that makes it look like a slightly better bet than the more +conventional indexscan-on-mailbox_idnr-and-then-sort plan. If you ask +for a few more than one row, though, it stops looking like a good bet, +since each additional row is estimated to cost another 1/433'd of the +total cost. + +Part of the estimation error is that there are only 56 matching rows +not 433, so the real cost-per-row ought to be 1/56'th of the total +indexscan cost. I suspect also that there is some correlation between +message_idnr and mailbox_idnr, which results in having to scan much +more than the expected 1/56'th of the index before finding a matching +row. + +The planner has no stats about intercolumn correlation so it's not going +to be able to recognize the correlation risk, but if you could get the +rowcount estimate closer to reality that would be enough to tilt the +scales to the better plan. Increasing ANALYZE's stats target for +mailbox_idnr would be worth trying. Also, I suspect that there is a +strong correlation between seen_flag and status, no? This again is +something you can't expect the planner to realize directly, but you +might be able to finesse the problem (and save some storage as well) +if you could merge the seen_flag into the status column and do just one +comparison to cover both conditions. + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Sat Sep 11 07:07:58 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 4FFDF329E5D + for ; + Sat, 11 Sep 2004 07:07:56 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 03361-08 + for ; + Sat, 11 Sep 2004 06:07:50 +0000 (GMT) +Received: from anchor-post-33.mail.demon.net (anchor-post-33.mail.demon.net + [194.217.242.91]) + by svr1.postgresql.org (Postfix) with ESMTP id 9199C329E5A + for ; + Sat, 11 Sep 2004 07:07:49 +0100 (BST) +Received: from lfix.demon.co.uk ([80.177.205.209] helo=cerberus.lfix.co.uk) + by anchor-post-33.mail.demon.net with esmtp (Exim 3.35 #1) + id 1C6134-000PKW-0X; Sat, 11 Sep 2004 06:07:46 +0000 +Received: from linda.lfix.co.uk ([192.168.1.1]) + by cerberus.lfix.co.uk with esmtp (Exim 4.34) + id 1C6130-0008H8-Bg; Sat, 11 Sep 2004 07:07:42 +0100 +Subject: Re: Stuck using Sequential Scan +From: Oliver Elphick +Reply-To: olly@lfix.co.uk +To: jeremy.guthrie@berbee.com +Cc: pgsql-performance@postgresql.org +In-Reply-To: <200409071632.05374.jeremy.guthrie@berbee.com> +References: <200409071632.05374.jeremy.guthrie@berbee.com> +Content-Type: text/plain +Organization: LFIX Limited +Message-Id: <1094882862.14510.982.camel@linda> +Mime-Version: 1.0 +X-Mailer: Ximian Evolution 1.4.6 +Date: Sat, 11 Sep 2004 07:07:42 +0100 +Content-Transfer-Encoding: 7bit +X-LFIX-MailScanner: Found to be clean +X-MailScanner-From: olly@lfix.co.uk +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/72 +X-Sequence-Number: 8200 + +On Tue, 2004-09-07 at 22:32, Jeremy M. Guthrie wrote: +> -----BEGIN PGP SIGNED MESSAGE----- +> Hash: SHA1 +> +> I have a problem where I have the table format listed below. I have the +> primary key tsyslog_id and the index built against it. However, when I +> select a unique row, it will only ever do a seq scan even after I turn off +> all other types except indexscan. I understand you cannot fully turn off seq +> scan. +... +> I cannot run vacuum more than once a day because of its heavy IO penalty. I +> run analyze once an hour. However, if I run analyze then explain, I see no +> difference in the planners decisions. What am I missing? +> +> +> TSyslog=# \d syslog_tarchive; +> Table "public.syslog_tarchive" +> Column | Type | +> Modifiers +> - ------------+------------------------+------------------------------------------------------------------------- +> tsyslog_id | bigint | not null default +... +> +> TSyslog=# explain select * from tsyslog where tsyslog_id=431650835; + +That constant is INTEGER, whereas the column is BIGINT; there is no +automatic conversion in this case, so the planner does not realise the +index is usable for this query (I think 8.0 solves this). + +Try: select * from tsyslog where tsyslog_id=431650835::BIGINT; + +-- +Oliver Elphick olly@lfix.co.uk +Isle of Wight http://www.lfix.co.uk/oliver +GPG: 1024D/A54310EA 92C8 39E7 280E 3631 3F0E 1EC0 5664 7A2F A543 10EA + ======================================== + "I am crucified with Christ; nevertheless I live; yet + not I, but Christ liveth in me; and the life which I + now live in the flesh I live by the faith of the Son + of God, who loved me, and gave himself for me." + Galatians 2:20 + + +From pgsql-performance-owner@postgresql.org Sat Sep 11 13:45:53 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id C212B329E7B + for ; + Sat, 11 Sep 2004 13:45:51 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 11189-08 + for ; + Sat, 11 Sep 2004 12:45:47 +0000 (GMT) +Received: from mproxy.gmail.com (rproxy.gmail.com [64.233.170.198]) + by svr1.postgresql.org (Postfix) with ESMTP id 4AF91329E6D + for ; + Sat, 11 Sep 2004 13:45:48 +0100 (BST) +Received: by mproxy.gmail.com with SMTP id 79so37375rnk + for ; + Sat, 11 Sep 2004 05:45:42 -0700 (PDT) +Received: by 10.38.14.33 with SMTP id 33mr148753rnn; + Sat, 11 Sep 2004 05:45:42 -0700 (PDT) +Received: by 10.38.78.36 with HTTP; Sat, 11 Sep 2004 05:45:42 -0700 (PDT) +Message-ID: +Date: Sat, 11 Sep 2004 15:45:42 +0300 +From: Vitaly Belman +Reply-To: Vitaly Belman +To: Postgresql Performance +Subject: Bad performance with hashjoin +Mime-Version: 1.0 +Content-Type: text/plain; charset=US-ASCII +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/73 +X-Sequence-Number: 8201 + +Here's the query: + +--------------------------------------------------------------------------- +SELECT * FROM bv_reviews r, bv_votes v +WHERE r.vote_id = v.vote_id +AND v.book_id = 113 +--------------------------------------------------------------------------- + +bv_votes has around 7000 rows with the given book_id and bv_reviews +has 10 reviews. Thus the resulting table consists of only 10 rows. + +That's the regular EXPLAIN of the query: + +--------------------------------------------------------------------------- +QUERY PLAN +Hash Join (cost=169.36..49635.37 rows=2117 width=897) (actual +time=13533.550..15107.987 rows=10 loops=1) + Hash Cond: ("outer".vote_id = "inner".vote_id) + -> Seq Scan on bv_reviews r (cost=0.00..45477.42 rows=396742 +width=881) (actual time=12.020..13305.055 rows=396742 loops=1) + -> Hash (cost=151.96..151.96 rows=6960 width=16) (actual +time=24.673..24.673 rows=0 loops=1) + -> Index Scan using i_votes_book_id on bv_votes v +(cost=0.00..151.96 rows=6960 width=16) (actual time=0.035..14.970 +rows=7828 loops=1) + Index Cond: (book_id = 113) +Total runtime: 15109.126 ms +--------------------------------------------------------------------------- + +And here is what happens when I turn the hashjoin to off: + +--------------------------------------------------------------------------- +QUERY PLAN +Nested Loop (cost=0.00..53799.79 rows=2117 width=897) (actual +time=4.260..79.721 rows=10 loops=1) + -> Index Scan using i_votes_book_id on bv_votes v +(cost=0.00..151.96 rows=6960 width=16) (actual time=0.071..14.100 +rows=7828 loops=1) + Index Cond: (book_id = 113) + -> Index Scan using i_bv_reviews_vote_id on bv_reviews r +(cost=0.00..7.70 rows=1 width=881) (actual time=0.007..0.007 rows=0 +loops=7828) + Index Cond: (r.vote_id = "outer".vote_id) +Total runtime: 79.830 ms +--------------------------------------------------------------------------- + +What am I to do? Are there hints (like in Oracle) in PostgreSQL to +force it to use the i_bv_reviews_vote_id index instead of doing a +seq.scan? Or is something wrong with my Postgresql settings? + +-- + ICQ: 1912453 + AIM: VitalyB1984 + MSN: tmdagent@hotmail.com + Yahoo!: VitalyBe + +From pgsql-performance-owner@postgresql.org Sat Sep 11 16:28:48 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 1AFBA329E56 + for ; + Sat, 11 Sep 2004 16:28:47 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 48957-05 + for ; + Sat, 11 Sep 2004 15:28:45 +0000 (GMT) +Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) + by svr1.postgresql.org (Postfix) with ESMTP id A9D77329E55 + for ; + Sat, 11 Sep 2004 16:28:45 +0100 (BST) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i8BFSiQi010707; + Sat, 11 Sep 2004 11:28:44 -0400 (EDT) +To: Vitaly Belman +Cc: Postgresql Performance +Subject: Re: Bad performance with hashjoin +In-reply-to: +References: +Comments: In-reply-to Vitaly Belman + message dated "Sat, 11 Sep 2004 15:45:42 +0300" +Date: Sat, 11 Sep 2004 11:28:44 -0400 +Message-ID: <10706.1094916524@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/74 +X-Sequence-Number: 8202 + +Vitaly Belman writes: +> What am I to do? + +Reduce random_page_cost and/or increase effective_cache_size. + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Sun Sep 12 05:24:56 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id EFE67329E7A + for ; + Sun, 12 Sep 2004 05:24:53 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 11329-03 + for ; + Sun, 12 Sep 2004 04:24:44 +0000 (GMT) +Received: from web41508.mail.yahoo.com (web41508.mail.yahoo.com + [66.218.93.91]) + by svr1.postgresql.org (Postfix) with SMTP id 64FE4329E75 + for ; + Sun, 12 Sep 2004 05:24:43 +0100 (BST) +Message-ID: <20040912042442.49915.qmail@web41508.mail.yahoo.com> +Received: from [67.33.169.246] by web41508.mail.yahoo.com via HTTP; + Sat, 11 Sep 2004 21:24:42 PDT +Date: Sat, 11 Sep 2004 21:24:42 -0700 (PDT) +From: Mark Cotner +Subject: Data Warehouse Reevaluation - MySQL vs Postgres +To: pgsql-performance@postgresql.org +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/75 +X-Sequence-Number: 8203 + +Hi all, +I had a difficult time deciding which list to post +this to, so please forgive me if this list doesn't +perfectly match my questions. My decision will not +solely be based on performance, but it is the primary +concern. I would be very appreciative if you all +could comment on my test plan. Real world examples of +a Postgres implementation of >=600G with a web +front-end would be great, or any data warehouse with +some size to it. + +The dilemma: +The time has come to reevaluate/rearchitect an +application which I built about 3 years ago. There +are no performance concerns with MySQL, but it would +benefit greatly from stored procedures, views, etc. +It is a very large rolling data warehouse that inserts +about 4.5 million rows every 2 hours and subsequently +rolls this data off the back end of a 90 day window. +A web interface has been designed for querying the +data warehouse. + +Migration planning is much easier with views and +stored procedures and this is my primary reason for +evaluating Postgres once again. As the application +grows I want to have the ability to provide backward +compatible views for those who are accustomed to the +current structure. This is not possible in MySQL. + +Some of the mining that we do could benefit from +stored procedures as well. MySQL may have these in +the works, but we won't be able to move to a version +of MySQL that supports stored procs for another year +or two. + +Requirements: +Merge table definition equivalent. We use these +extensively. + +Merge table equivalent with all tables containing over +100M rows(and about 40 columns, some quite wide) will +need to do index scans in at least 5 seconds(MySQL +currently does 2, but we can live with 5) and return +~200 rows. + +Um, gonna sound silly, but the web interface has to +remain "snappy" under load. I don't see this as a +major concern since you don't require table locking. + +If business logic is moved to the database(likely with +Postgres) performance for inserting with light logic +on each insert has to keep up with the 4.5M inserts +per 2 hours(which MySQL completes in ~35min +currently). Acceptable numbers for this aggregation +would be 45-55min using stored procedures. + +About 3 years ago I did some performance +characterizations of Postgres vs. MySQL and didn't +feel Postgres was the best solution. 3 years later +we've won runner-up for MySQL application of the +year(behind Saabre). Oddly enough this reevaluting +database strategy is right on the coattails of this +award. I'll begin writing my business logic within +the next week and start migrating test data shortly +thereafter. Case studies would be very beneficial as +I put together my analysis. + +Also, this is for a Fortune 500 company that uses this +data warehouse extensively. It is an internal +application that is widely used and gets about 4 hits +per employee per day. Much of customer care, data +engineering, plant engineering(it's a cable company), +and marketing use the interface. I've done a great +deal of press for MySQL and would be equally willing +to tout the benefits of Postgres to trade rags, +magazines, etc provided the results are favorable. + +Here's our case study if you're interested . . . +http://www.mysql.com/customers/customer.php?id=16 + +Thoughts, suggestions? + +'njoy, +Mark + +From pgsql-performance-owner@postgresql.org Sun Sep 12 06:23:04 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 7D21A329C6B + for ; + Sun, 12 Sep 2004 06:23:03 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 39981-03 + for ; + Sun, 12 Sep 2004 05:22:53 +0000 (GMT) +Received: from zigo.dhs.org (as2-4-3.an.g.bonet.se [194.236.34.191]) + by svr1.postgresql.org (Postfix) with ESMTP id E7583329C67 + for ; + Sun, 12 Sep 2004 06:22:50 +0100 (BST) +Received: from zigo.zigo.dhs.org (zigo.zigo.dhs.org [192.168.0.1]) + by zigo.dhs.org (Postfix) with ESMTP + id 8D9338467; Sun, 12 Sep 2004 07:22:48 +0200 (CEST) +Date: Sun, 12 Sep 2004 07:22:48 +0200 (CEST) +From: Dennis Bjorklund +To: Mark Cotner +Cc: pgsql-performance@postgresql.org +Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres +In-Reply-To: <20040912042442.49915.qmail@web41508.mail.yahoo.com> +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=ISO-8859-1 +Content-Transfer-Encoding: 8BIT +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/76 +X-Sequence-Number: 8204 + +On Sat, 11 Sep 2004, Mark Cotner wrote: + +> There are no performance concerns with MySQL, but it would benefit +> greatly from stored procedures, views, etc. It is a very large rolling +> data warehouse that inserts about 4.5 million rows every 2 hours and +> subsequently rolls this data off the back end of a 90 day window. + +While it is impossible to know without testing, postgresql has the benefit +of readers and writers that does not block each other. So in situations +where you do lots of concurrent inserts and selects postgresql should +behave well. + +> Merge table definition equivalent. We use these extensively. + +As far as I can tell a merge table in mysql is the same as a view over a +number of unions of other tables. And possibly a rule that defines how +inserts will be done if you do inserts in the merged table. + +> Merge table equivalent with all tables containing over 100M rows(and +> about 40 columns, some quite wide) will need to do index scans in at +> least 5 seconds(MySQL currently does 2, but we can live with 5) and +> return ~200 rows. + +Since each table that are merged will have it's own index the speed should +be proportional to the number of tables. Index scans in them self are very +fast, and of you have 30 tables you need 30 index scans. + +Also, are you sure you really need merge tables? With pg having row locks +and mvcc, maybe you could go for a simpler model with just one big table. +Often you can also combine that with partial indexes to get a smaller +index to use for lots of your queries. + +> Thoughts, suggestions? + +I see nothing in what you have written that indicates that pg can not do +the job, and do it well. It's however very hard to know exactly what is +the bottleneck before one tries. There are lots of cases where people have +converted mysql applications to postgresql and have gotten a massive +speedup. You could be lucky and have such a case, who knows.. + +I spend some time each day supporting people using postgresql in the +#postgresql irc channel (on the freenode.net network). There I talk to +people doing both small and big conversions and the majority is very happy +with the postgresql performance. Postgresql have gotten faster and faster +with each release and while speed was a fair argument a number of years +ago it's not like that today. + +That said, in the end it depends on the application. + +We are all interested in how it goes (well, at least me :-), so feel free +to send more mails keeping us posted. Good luck. + +-- +/Dennis Bj�rklund + + +From pgsql-performance-owner@postgresql.org Sun Sep 12 10:36:38 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id A1A9A329C6B + for ; + Sun, 12 Sep 2004 10:36:33 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 86735-07 + for ; + Sun, 12 Sep 2004 09:36:22 +0000 (GMT) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by svr1.postgresql.org (Postfix) with ESMTP id B228A329C63 + for ; + Sun, 12 Sep 2004 10:36:23 +0100 (BST) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by news.hub.org (8.12.9/8.12.9) with ESMTP id i8C9aKCn089212 + for ; Sun, 12 Sep 2004 09:36:20 GMT + (envelope-from news@news.hub.org) +Received: (from news@localhost) + by news.hub.org (8.12.9/8.12.9/Submit) id i8C97Y99084176 + for pgsql-performance@postgresql.org; Sun, 12 Sep 2004 09:07:34 GMT +From: Gaetano Mendola +X-Newsgroups: comp.databases.postgresql.performance +Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres +Date: Sun, 12 Sep 2004 11:07:34 +0200 +Organization: PYRENET Midi-pyrenees Provider +Lines: 18 +Message-ID: <414411D6.2070208@bigfoot.com> +References: <20040912042442.49915.qmail@web41508.mail.yahoo.com> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit +X-Complaints-To: abuse@pyrenet.fr +To: Mark Cotner +User-Agent: Mozilla Thunderbird 0.7.3 (Windows/20040803) +X-Accept-Language: en-us, en +In-Reply-To: <20040912042442.49915.qmail@web41508.mail.yahoo.com> +X-Enigmail-Version: 0.85.0.0 +X-Enigmail-Supports: pgp-inline, pgp-mime +To: pgsql-performance@postgresql.org +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/77 +X-Sequence-Number: 8205 + +Mark Cotner wrote: + +> Requirements: +> Merge table definition equivalent. We use these +> extensively. + +What do you mean with "merge table definition equivalent"? + + + +Regards +Gaetano Mendola + + + + + + + +From pgsql-performance-owner@postgresql.org Tue Sep 14 05:22:05 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 21024329E56 + for ; + Sun, 12 Sep 2004 22:06:38 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 26348-06 + for ; + Sun, 12 Sep 2004 21:06:28 +0000 (GMT) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by svr1.postgresql.org (Postfix) with ESMTP id 61B85329D87 + for ; + Sun, 12 Sep 2004 22:06:29 +0100 (BST) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by news.hub.org (8.12.9/8.12.9) with ESMTP id i8CL6RCn028550 + for ; Sun, 12 Sep 2004 21:06:27 GMT + (envelope-from news@news.hub.org) +Received: (from news@localhost) + by news.hub.org (8.12.9/8.12.9/Submit) id i8CKlGkU024342 + for pgsql-performance@postgresql.org; Sun, 12 Sep 2004 20:47:16 GMT +From: Mischa Sandberg +Reply-To: ischamay.andbergsay@activestateway.com +User-Agent: Mozilla Thunderbird 0.7.3 (X11/20040803) +X-Accept-Language: en-us, en +MIME-Version: 1.0 +X-Newsgroups: comp.databases.postgresql.performance +Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres -- merge tables +References: <20040912042442.49915.qmail@web41508.mail.yahoo.com> +In-Reply-To: <20040912042442.49915.qmail@web41508.mail.yahoo.com> +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit +Lines: 100 +Message-ID: +Date: Sun, 12 Sep 2004 20:47:17 GMT +To: pgsql-performance@postgresql.org +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, + hits=1.1 tagged_above=0.0 required=5.0 tests=NO_DNS_FOR_FROM +X-Spam-Level: * +X-Archive-Number: 200409/103 +X-Sequence-Number: 8231 + + +Mark Cotner wrote: +> Hi all, +> I had a difficult time deciding which list to post +> this to, so please forgive me if this list doesn't +> perfectly match my questions. My decision will not +> solely be based on performance, but it is the primary +> concern. I would be very appreciative if you all +> could comment on my test plan. Real world examples of +> a Postgres implementation of >=600G with a web +> front-end would be great, or any data warehouse with +> some size to it. + +I'm only in the 30GB range of database, in case that's a consideration +for my comments that follow. + +At this time, I'm working out the best ROLAP options for our PG +transaction store. The transaction store is highly volatile -- longest a +txn stays in it is 15 days ... so you imagine the need for historic +summaries :-) + +I've also implemented multiple data servers, including +a federated server that had to make the best of existing engines +(like MySQL, PG and everything from MSJet to RedBrick in the commercial +world). + +> The time has come to reevaluate/rearchitect an +> application which I built about 3 years ago. There +> are no performance concerns with MySQL, but it would +> benefit greatly from stored procedures, views, etc. + +If your company is currently happy with MySQL, there probably are other +(nontechnical) reasons to stick with it. I'm impressed that you'd +consider reconsidering PG. + +> Some of the mining that we do could benefit from +> stored procedures as well. MySQL may have these in +> the works, but we won't be able to move to a version +> of MySQL that supports stored procs for another year +> or two. + +And PG lets you back-end with some powerful pattern- and +aggregate-handling languages, like Perl. This was definitely a plus for +data mining of web traffic, for example. The power of server-side +extensibility for bailing you out of a design dead-end is not +inconsequential. + +PG doesn't have PIVOT operators (qv Oracle and MSSQL), but it makes the +translation from data to column fairly painless otherwise. + +> Requirements: +> Merge table definition equivalent. We use these +> extensively. + +Looked all over mysql.com etc, and afaics merge table +is indeed exactly a view of a union-all. Is that right? + +PG supports views, of course, as well (now) as tablespaces, allowing you +to split tables/tablesets across multiple disk systems. +PG is also pretty efficient in query plans on such views, where (say) +you make one column a constant (identifier, sort of) per input table. + +> Merge table equivalent with all tables containing over +> 100M rows(and about 40 columns, some quite wide) will +> need to do index scans in at least 5 seconds(MySQL +> currently does 2, but we can live with 5) and return +> ~200 rows. + +PG has TOAST for handling REALLY BIG columns, and the generic TEXT type +is as efficient as any size-specific VARCHAR() type ... should make +things easier for you. + +> Um, gonna sound silly, but the web interface has to +> remain "snappy" under load. I don't see this as a +> major concern since you don't require table locking. + +Agreed. It's more in your warehouse design, and intelligent bounding of +queries. I'd say PG's query analyzer is a few years ahead of MySQL for +large and complex queries. + +> If business logic is moved to the database(likely with +> Postgres) performance for inserting with light logic +> on each insert has to keep up with the 4.5M inserts +> per 2 hours(which MySQL completes in ~35min +> currently). Acceptable numbers for this aggregation +> would be 45-55min using stored procedures. + +Again, it's a matter of pipeline design. The tools for creating an +efficient pipeline are at least as good in PG as MySQL. + +If you try to insert and postprocess information one row at a time, +procedures or no, there's no offhand way to guarantee your performance +without a test/prototype. + +On the other hand, if you do warehouse-style loading (Insert, or PG +COPY, into a temp table; and then 'upsert' into the perm table), I can +guarantee 2500 inserts/sec is no problem. + +> Here's our case study if you're interested . . . +> http://www.mysql.com/customers/customer.php?id=16 + +From pgsql-performance-owner@postgresql.org Tue Sep 14 05:22:05 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 47C3E329D87 + for ; + Mon, 13 Sep 2004 02:35:11 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 80736-02 + for ; + Mon, 13 Sep 2004 01:35:04 +0000 (GMT) +Received: from maladroit.uchicago.edu (maladroit.uchicago.edu [128.135.72.43]) + by svr1.postgresql.org (Postfix) with ESMTP id 532BB329E23 + for ; + Mon, 13 Sep 2004 02:35:06 +0100 (BST) +Received: from maladroit.uchicago.edu (localhost [127.0.0.1]) + by maladroit.uchicago.edu (8.12.8/8.12.8) with SMTP id i8D1Z6of022033 + for ; Sun, 12 Sep 2004 20:35:06 -0500 +Received: from 64.81.139.18 (SquirrelMail authenticated user bill) + by maladroit.uchicago.edu with HTTP; + Sun, 12 Sep 2004 20:35:06 -0500 (CDT) +Message-ID: <3129.64.81.139.18.1095039306.squirrel@maladroit.uchicago.edu> +Date: Sun, 12 Sep 2004 20:35:06 -0500 (CDT) +Subject: tblspaces integrated in new postgresql (version 8.0) +From: bill@uchicago.edu +To: pgsql-performance@postgresql.org +User-Agent: SquirrelMail/1.4.2 +MIME-Version: 1.0 +Content-Type: text/plain;charset=iso-8859-1 +Content-Transfer-Encoding: 8bit +X-Priority: 3 +Importance: Normal +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=1.1 tagged_above=0.0 required=5.0 tests=NO_REAL_NAME, + PRIORITY_NO_NAME +X-Spam-Level: * +X-Archive-Number: 200409/104 +X-Sequence-Number: 8232 + +Hi, I have downloaded the new postgresql (version 8.0 beta2) and I was +wondering what performance features I can take advantage of before I start +to dump my 3/4 terrabyte database into the new format. More specifically +I am interested in tablespaces--what exactly is this feature, some sort of +organizational addition (?) and howcan I best take advantage of this....? +Anything else? + +Thanks. + +From pgsql-performance-owner@postgresql.org Mon Sep 13 04:06:41 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 9695E329C7B + for ; + Mon, 13 Sep 2004 04:06:37 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 05214-04 + for ; + Mon, 13 Sep 2004 03:06:34 +0000 (GMT) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by svr1.postgresql.org (Postfix) with ESMTP id 80684329C65 + for ; + Mon, 13 Sep 2004 04:06:33 +0100 (BST) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by news.hub.org (8.12.9/8.12.9) with ESMTP id i8D36XCn005687 + for ; Mon, 13 Sep 2004 03:06:33 GMT + (envelope-from news@news.hub.org) +Received: (from news@localhost) + by news.hub.org (8.12.9/8.12.9/Submit) id i8D2nwaX000675 + for pgsql-performance@postgresql.org; Mon, 13 Sep 2004 02:49:58 GMT +From: Christopher Browne +X-Newsgroups: comp.databases.postgresql.performance +Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres -- merge tables +Date: Sun, 12 Sep 2004 22:29:00 -0400 +Organization: cbbrowne Computing Inc +Lines: 60 +Message-ID: +References: <20040912042442.49915.qmail@web41508.mail.yahoo.com> + +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Complaints-To: usenet@news.hub.org +X-message-flag: Outlook is rather hackable, isn't it? +X-Home-Page: http://www.cbbrowne.com/info/ +X-Affero: http://svcs.affero.net/rm.php?r=cbbrowne +User-Agent: Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.4 (Security Through + Obscurity, + linux) +Cancel-Lock: sha1:1tNkl+MxSM4LYBX90B0ESic8DNQ= +To: pgsql-performance@postgresql.org +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/79 +X-Sequence-Number: 8207 + +The world rejoiced as Mischa Sandberg wrote: +> Mark Cotner wrote: +>> Requirements: +>> Merge table definition equivalent. We use these +>> extensively. + +> Looked all over mysql.com etc, and afaics merge table is indeed +> exactly a view of a union-all. Is that right? + +> PG supports views, of course, as well (now) as tablespaces, allowing +> you to split tables/tablesets across multiple disk systems. PG is +> also pretty efficient in query plans on such views, where (say) you +> make one column a constant (identifier, sort of) per input table. + +The thing that _doesn't_ work well with these sorts of UNION views are +when you do self-joins. Supposing you have 10 members, a self-join +leads to a 100-way join, which is not particularly pretty. + +I'm quite curious as to how MySQL(tm) copes with this, although it may +not be able to take place; they may not support that... + +>> Um, gonna sound silly, but the web interface has to remain "snappy" +>> under load. I don't see this as a major concern since you don't +>> require table locking. + +> Agreed. It's more in your warehouse design, and intelligent bounding +> of queries. I'd say PG's query analyzer is a few years ahead of +> MySQL for large and complex queries. + +The challenge comes in if the application has had enormous amounts of +effort put into it to attune it exactly to MySQL(tm)'s feature set. + +The guys working on RT/3 have found this a challenge; they had rather +a lot of dependancies on its case-insensitive string comparisons, +causing considerable grief. + +> On the other hand, if you do warehouse-style loading (Insert, or PG +> COPY, into a temp table; and then 'upsert' into the perm table), I +> can guarantee 2500 inserts/sec is no problem. + +The big wins are thus: + + 1. Group plenty of INSERTs into a single transaction. + + 2. Better still, use COPY to cut parsing costs plenty more. + + 3. Adding indexes _after_ the COPY are a further win. + +Another possibility is to do clever things with stored procs; load +incoming data using the above optimizations, and then run stored +procedures to use some more or less fancy logic to put the data where +it's ultimately supposed to be. Having the logic running inside the +engine is the big optimization. +-- +wm(X,Y):-write(X),write('@'),write(Y). wm('cbbrowne','linuxfinances.info'). +http://linuxfinances.info/info/spreadsheets.html +Rules of the Evil Overlord #198. "I will remember that any +vulnerabilities I have are to be revealed strictly on a need-to-know +basis. I will also remember that no one needs to know." + + +From pgsql-performance-owner@postgresql.org Mon Sep 13 04:04:08 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 51EAC329D9E + for ; + Mon, 13 Sep 2004 04:04:06 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 00950-10 + for ; + Mon, 13 Sep 2004 03:04:03 +0000 (GMT) +Received: from web53701.mail.yahoo.com (web53701.mail.yahoo.com + [206.190.37.22]) + by svr1.postgresql.org (Postfix) with SMTP id 32F4B329D7C + for ; + Mon, 13 Sep 2004 04:03:59 +0100 (BST) +Message-ID: <20040913030357.66842.qmail@web53701.mail.yahoo.com> +Received: from [65.69.59.19] by web53701.mail.yahoo.com via HTTP; + Sun, 12 Sep 2004 20:03:57 PDT +Date: Sun, 12 Sep 2004 20:03:57 -0700 (PDT) +From: George Essig +Subject: Re: TSearch2 and optimisation ... +To: pgsql-performance@postgresql.org +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests=HTML_MESSAGE +X-Spam-Level: +X-Archive-Number: 200409/78 +X-Sequence-Number: 8206 + +--- Herv� wrote: + +> George, +> +> I have well read many pages about this subject ... but I have not found any +> thing for the moment to really help me ... +> What can I do to optimize my PostgreSQL configuration for a special use of +> Tsearch2 ... +> I'm a little dispointed looking the Postgresql Russian search engine using +> Tsearch2 is really quick ... why I can't haev the same result with a +> bi-pentium III 933 and 1Gb of RAM with the text indexation of 1 500 000 +> records ? +> +> Regards, +> -- +> Herv� +> Elma Ing� 6 rue du Faubourg Saint-Honor� F-75008 - Paris - France +> Pho. 33-144949901 +> Fax. 33-144949902 +> + +Tsearch does not scale indefinitely. It was designed for fast online updates and to be integrated +into PostgreSQL. My understanding is that it uses a bloom filter together with bit string +signatures. Typically, full text searches use inverted indexes, scale better, but are slower to +update. + +My understanding is that tsearch has a practical limit of 100,000 distinct word stems or lexemes. +Note that word stems are not words. Word stems are what are actually stored in a tsvector after +parsing and dictionary processing. + +The key to making tsearch fast is to keep the number of word stems low. You decrease the number +of word stems by using stop words, various dictionaries, synonyms, and preprocessing text before +it gets to tsearch. You can find what word stems are stored in a tsvector column by using the +stat function. For examples of how to use the stat function, see: + +http://www.sai.msu.su/~megera/oddmuse/index.cgi/Tsearch_V2_Notes +http://www.sai.msu.su/~megera/postgres/gist/tsearch/V2/docs/oscon_tsearch2/stat.html + +Note that the stat function will take a long time to run on large tables. + +Performance tuning must be done on a case by case basis. It can take some time to try different +things and see the change in performance. Each time you try something new, use the stat function +to see how the number of word stems has changed. + +The largest project I used tsearch2 on contained 900,000 records. Without performance tuning, +there were 275,000 distinct word stems. After performance tuning, I got it down to 14,000 +distinct word stems. + +By using the stat function, I noticed some obvious stop words that were very frequent that nobody +would ever search for. For how to use stop words, see: + +http://www.sai.msu.su/~megera/postgres/gist/tsearch/V2/docs/oscon_tsearch2/stop_words.html + +Also I noticed some strange patterns by looking through all of the word stems. + +In one case, strings of 3 to 7 words were joined together with hyphens to indicate category +nesting. Tsearch would store these long hyphenated words intact and also store the stem of each +individual word. I made a judgment call that no one would ever search for the long hyphenated +words, so I preprocessed the text to remove the hyphens. + +I also noticed that many of the word stems were alphanumeric IDs that were designed to be unique. +There were many of these IDs in the tsvector column although each ID would occur only once or +twice. I again preprocessed the text to remove these IDs, but created a btree index on a varchar +column representing the IDs. My search form allows users to either search full text using +tsearch2 or search IDs using 'LIKE' queries which use a btree index. For 'LIKE' queries, it was +another matter to get postgres to use the btree index and not use a sequential scan. For this, +see: + +http://www.postgresql.org/docs/7.4/static/indexes-opclass.html + +Last, I noticed that most users wanted to restrict the full text search to a subset determined by +another column in the table. As a result, I created a multicolumn gist index on an integer column +and a tsvector column. For how to setup a multicolumn gist index, see: + +http://www.sai.msu.su/~megera/postgres/gist/tsearch/V2/docs/oscon_tsearch2/multi_column_index.html + +There are no easy answers. Like I said, performance tuning must be done on a case by case basis. + +Hope this helps, + +George Essig + +From pgsql-performance-owner@postgresql.org Tue Sep 14 05:24:43 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id B62FF329E12 + for ; + Mon, 13 Sep 2004 05:30:50 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 24520-04 + for ; + Mon, 13 Sep 2004 04:30:46 +0000 (GMT) +Received: from mproxy.gmail.com (rproxy.gmail.com [64.233.170.198]) + by svr1.postgresql.org (Postfix) with ESMTP id 184BF329DBF + for ; + Mon, 13 Sep 2004 05:30:46 +0100 (BST) +Received: by mproxy.gmail.com with SMTP id 79so1111163rnk + for ; + Sun, 12 Sep 2004 21:30:42 -0700 (PDT) +Received: by 10.38.171.26 with SMTP id t26mr1076029rne; + Sun, 12 Sep 2004 21:30:41 -0700 (PDT) +Received: by 10.38.70.43 with HTTP; Sun, 12 Sep 2004 21:30:41 -0700 (PDT) +Message-ID: <17b0d951040912213055195d56@mail.gmail.com> +Date: Mon, 13 Sep 2004 10:00:41 +0530 +From: Vijay Moses +Reply-To: Vijay Moses +To: pgsql-performance@postgresql.org +Subject: Four table join with million records - performance improvement? +Mime-Version: 1.0 +Content-Type: text/plain; charset=US-ASCII +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 + tests=LINES_OF_YELLING +X-Spam-Level: +X-Archive-Number: 200409/105 +X-Sequence-Number: 8233 + +Hi i have four sample tables ename, esal, edoj and esum +All of them have 1000000 records. Im running the following +query : select ename.eid, name, sal, doj, summary from +ename,esal,edoj,esum where ename.eid=esal.eid and ename.eid=edoj.eid +and ename.eid=esum.eid. Its a join of all four tables which returns +all 1 million records. The eid field in ename is a Primary Key and the +eid in all other tables are Foreign Keys. I have created an index for +all Foreign Keys. This query takes around 16 MINUTES to complete. Can +this time be reduced? +Thanks +Vijay + +---------------------------------------------------------------- + +EXPLAIN OUTPUT + +QUERY PLAN +Merge Join (cost=647497.97..163152572.97 rows=25000025000000 width=80) + Merge Cond: ("outer".eid = "inner".eid) + -> Merge Join (cost=356059.69..75361059.69 rows=5000000000 width=44) + Merge Cond: ("outer".eid = "inner".eid) + -> Sort (cost=150295.84..152795.84 rows=1000000 width=8) + Sort Key: edoj.eid + -> Seq Scan on edoj (cost=0.00..15568.00 rows=1000000 width=8) + -> Sort (cost=205763.84..208263.84 rows=1000000 width=36) + Sort Key: esum.eid + -> Seq Scan on esum (cost=0.00..31976.00 rows=1000000 width=36) + -> Sort (cost=291438.28..293938.29 rows=1000002 width=48) + Sort Key: ename.eid + -> Hash Join (cost=26683.01..107880.23 rows=1000002 width=48) + Hash Cond: ("outer".eid = "inner".eid) + -> Seq Scan on esal (cost=0.00..21613.01 rows=1000001 width=12) + -> Hash (cost=16370.01..16370.01 rows=1000001 width=36) + -> Seq Scan on ename (cost=0.00..16370.01 +rows=1000001 width=36) + +17 row(s) + +Total runtime: 181.021 ms + +---------------------------------------------------------------- + +EXPLAIN ANALYZE OUTPUT + +QUERY PLAN + +Merge Join (cost=647497.97..163152572.97 rows=25000025000000 +width=80) (actual time=505418.965..584981.013 rows=1000000 loops=1) + Merge Cond: ("outer".eid = "inner".eid) + -> Merge Join (cost=356059.69..75361059.69 rows=5000000000 +width=44) (actual time=110394.376..138177.569 rows=1000000 loops=1) + Merge Cond: ("outer".eid = "inner".eid) + -> Sort (cost=150295.84..152795.84 rows=1000000 width=8) +(actual time=27587.622..31077.077 rows=1000000 loops=1) + Sort Key: edoj.eid + -> Seq Scan on edoj (cost=0.00..15568.00 rows=1000000 +width=8) (actual time=144.000..10445.145 rows=1000000 loops=1) + -> Sort (cost=205763.84..208263.84 rows=1000000 width=36) +(actual time=82806.646..90322.943 rows=1000000 loops=1) + Sort Key: esum.eid + -> Seq Scan on esum (cost=0.00..31976.00 rows=1000000 +width=36) (actual time=20.312..29030.247 rows=1000000 loops=1) + -> Sort (cost=291438.28..293938.29 rows=1000002 width=48) (actual +time=395024.482..426870.491 rows=1000001 loops=1) + Sort Key: ename.eid + -> Hash Join (cost=26683.01..107880.23 rows=1000002 +width=48) (actual time=29234.472..198064.105 rows=1000001 loops=1) + Hash Cond: ("outer".eid = "inner".eid) + -> Seq Scan on esal (cost=0.00..21613.01 rows=1000001 +width=12) (actual time=32.257..23999.163 rows=1000001 loops=1) + -> Hash (cost=16370.01..16370.01 rows=1000001 +width=36) (actual time=19362.095..19362.095 rows=0 loops=1) + -> Seq Scan on ename (cost=0.00..16370.01 +rows=1000001 width=36) (actual time=26.744..13878.410 rows=1000001 +loops=1) + +Total runtime: 586226.831 ms + +18 row(s) + +Total runtime: 586,435.978 ms + +---------------------------------------------------------------- + +From pgsql-performance-owner@postgresql.org Mon Sep 13 07:11:16 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id ABFFB329E3D + for ; + Mon, 13 Sep 2004 07:11:13 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 55564-04 + for ; + Mon, 13 Sep 2004 06:11:08 +0000 (GMT) +Received: from mail0.rawbw.com (mail0.rawbw.com [198.144.192.41]) + by svr1.postgresql.org (Postfix) with ESMTP id 0A8FB329E45 + for ; + Mon, 13 Sep 2004 07:11:07 +0100 (BST) +Received: (from www@localhost) + by mail0.rawbw.com (8.11.6p2/8.11.6) id i8D6B6g81218 + for pgsql-performance@postgresql.org; + Sun, 12 Sep 2004 23:11:06 -0700 (PDT) +Received: from 198.144.203.171 ([198.144.203.171]) + by webmail.rawbw.com (IMP) with HTTP + for ; Sun, 12 Sep 2004 23:11:06 -0700 +Message-ID: <1095055866.414539fadb90d@webmail.rawbw.com> +Date: Sun, 12 Sep 2004 23:11:06 -0700 +From: mudfoot@rawbw.com +To: pgsql-performance@postgresql.org +Subject: Determine optimal fdatasync/fsync, O_SYNC/O_DSYNC options +MIME-Version: 1.0 +Content-Type: multipart/mixed; + boundary="-MOQ1095055866e1dd2dbc1ed81c0f7e60b7cb17d6f7b3" +User-Agent: Internet Messaging Program (IMP) 3.2.1 +X-Originating-IP: 198.144.203.171 +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.3 tagged_above=0.0 required=5.0 + tests=LINES_OF_YELLING, NO_REAL_NAME +X-Spam-Level: +X-Archive-Number: 200409/80 +X-Sequence-Number: 8208 + +This message is in MIME format. + +---MOQ1095055866e1dd2dbc1ed81c0f7e60b7cb17d6f7b3 +Content-Type: text/plain; charset=iso-8859-1 +Content-Transfer-Encoding: 8bit + +Hi, I'd like to help with the topic in the Subject: line. It seems to be a +TODO item. I've reviewed some threads discussing the matter, so I hope I've +acquired enough history concerning it. I've taken an initial swipe at +figuring out how to optimize sync'ing methods. It's based largely on +recommendations I've read on previous threads about fsync/O_SYNC and so on. +After reviewing, if anybody has recommendations on how to proceed then I'd +love to hear them. + +Attached is a little program that basically does a bunch of sequential writes +to a file. All of the sync'ing methods supported by PostgreSQL WAL can be +used. Results are printed in microseconds. Size and quanity of writes are +configurable. The documentation is in the code (how to configure, build, run, +etc.). I realize that this program doesn't reflect all of the possible +activities of a production database system, but I hope it's a step in the +right direction for this task. I've used it to see differences in behavior +between the various sync'ing methods on various platforms. + +Here's what I've found running the benchmark on some systems to which +I have access. The differences in behavior between platforms is quite vast. + +Summary first... + + +PostgreSQL should be run on an old Apple MacIntosh attached to +its own Hitachi disk array with 2GB cache or so. Use any sync method +except for fsync(). + + +Anyway, there is *a lot* of variance in file synching behavior across +different hardware and O/S platforms. It's probably not safe +to conclude much. That said, here are some findings so far based on +tests I've run: + +1. under no circumstances do fsync() or fdatasync() seem to perform +better than opening files with O_SYNC or O_DSYNC +2. where there are differences, opening files with O_SYNC or O_DSYNC +tends to be quite faster. +3. fsync() seems to be the slowest where there are differences. And +O_DSYNC seems to be the fastest where results differ. +4. the safest thing to assert at this point is that +Solaris systems ought to use the O_DSYNC method for WAL. + +----------- + +Test system(s) + +Athlon Linux: +AMD Athlon XP2000, 512MB RAM, single (54 or 7200?) RPM 20GB IDE disk, +reiserfs filesystem (3 something I think) +SuSE Linux kernel 2.4.21-99 + +Mac Linux: +I don't know the specific model. 400MHz G3, 512MB, single IDE disk, +ext2 filesystem +Debian GNU/Linux 2.4.16-powerpc + +HP Intel Linux: +Prolient HPDL380G3, 2 x 3GHz Xeon, 2GB RAM, SmartArray 5i 64MB cache, +2 x 15,000RPM 36GB U320 SCSI drives mirrored. I'm not sure if +writes are cached or not. There's no battery backup. +ext3 filesystem. +Redhat Enterprise Linux 3.0 kernel based on 2.4.21 + +Dell Intel OpenBSD: +Poweredge ?, single 1GHz PIII, 128MB RAM, single 7200RPM 80GB IDE disk, +ffs filesystem +OpenBSD 3.2 GENERIC kernel + +SUN Ultra2: +Ultra2, 2 x 296MHz UltraSPARC II, 2GB RAM, 2 x 10,000RPM 18GB U160 +SCSI drives mirrored with Solstice DiskSuite. UFS filesystem. +Solaris 8. + +SUN E4500 + HDS Thunder 9570v +E4500, 8 x 400MHz UltraSPARC II, 3GB RAM, +HDS Thunder 9570v, 2GB mirrored battery-backed cache, RAID5 with a +bunch of 146GB 10,000RPM FC drives. LUN is on single 2GB FC fabric +connection. +Veritas filesystem (VxFS) +Solaris 8. + +Test methodology: + +All test runs were done with CHUNKSIZE 8 * 1024, CHUNKS 2 * 1024, +FILESIZE_MULTIPLIER 2, and SLEEP 5. So a total of 16MB was sequentially +written for each benchmark. + +Results are in microseconds. + +PLATFORM: Athlon Linux +buffered: 48220 +fsync: 74854397 +fdatasync: 75061357 +open_sync: 73869239 +open_datasync: 74748145 +Notes: System mostly idle. Even during tests, top showed about 95% +idle. Something's not right on this box. All sync methods similarly +horrible on this system. + +PLATFORM: Mac Linux +buffered: 58912 +fsync: 1539079 +fdatasync: 769058 +open_sync: 767094 +open_datasync: 763074 +Notes: system mostly idle. fsync seems worst. Otherwise, they seem +pretty equivalent. This is the fastest system tested. + +PLATFORM: HP Intel Linux +buffered: 33026 +fsync: 29330067 +fdatasync: 28673880 +open_sync: 8783417 +open_datasync: 8747971 +Notes: system idle. O_SYNC and O_DSYNC methods seem to be a lot +better on this platform than fsync & fdatasync. + +PLATFORM: Dell Intel OpenBSD +buffered: 511890 +fsync: 1769190 +fdatasync: -------- +open_sync: 1748764 +open_datasync: 1747433 +Notes: system idle. I couldn't locate fdatasync() on this box, so I +couldn't test it. All sync methods seem equivalent and are very fast -- +though still trail the old Mac. + +PLATFORM: SUN Ultra2 +buffered: 1814824 +fsync: 73954800 +fdatasync: 52594532 +open_sync: 34405585 +open_datasync: 13883758 +Notes: system mostly idle, with occasional spikes from 1-10% utilization. +It looks like substantial difference between each sync method, with +O_DSYNC the best and fsync() the worst. There is substantial +difference between the open* and f* methods. + +PLATFORM: SUN E4500 + HDS Thunder 9570v +buffered: 233947 +fsync: 57802065 +fdatasync: 56631013 +open_sync: 2362207 +open_datasync: 1976057 +Notes: host about 30% idle, but the array tested on was completely idle. +Something looks seriously not right about fsync and fdatasync -- write +cache seems to have no effect on them. As for write cache, that +probably explains the 2 seconds or so for the open_sync and +open_datasync methods. + +-------------- + +Thanks for reading...I look forward to feedback, and hope to be helpful in +this effort! + +Mark + +---MOQ1095055866e1dd2dbc1ed81c0f7e60b7cb17d6f7b3 +Content-Type: text/x-csrc; name="syncbench.c" +Content-Transfer-Encoding: base64 +Content-Disposition: attachment; filename="syncbench.c" + +I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1 +ZGUgPHVuaXN0ZC5oPgojaW5jbHVkZSA8c3lzL3R5cGVzLmg+CiNpbmNsdWRl +IDxzeXMvc3RhdC5oPgojaW5jbHVkZSA8ZmNudGwuaD4KI2luY2x1ZGUgPGVy +cm5vLmg+CiNpbmNsdWRlIDxzdHJpbmcuaD4KI2luY2x1ZGUgPHN5cy90aW1l +Lmg+CgovKgoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioq +KioqKioqKioqKioqKioqKioqKioKCkxpY2Vuc2U6CnN5bmNiZW5jaDogYSBw +cm9ncmFtIHRvIGhlbHAgZGV0ZXJtaW5lIG9wdGltYWwgaS9vIHN5bmNocm9u +aXphdGlvbgptZWNoYW5pc21zCndyaXR0ZW4gYnkgTWFyayBUcmF2aXMKCkNv +cHlyaWdodCAoYykgMjAwNCBNYXJrIFRyYXZpcwoKUGVybWlzc2lvbiB0byB1 +c2UsIGNvcHksIG1vZGlmeSwgYW5kIGRpc3RyaWJ1dGUgdGhpcyBzb2Z0d2Fy +ZSBhbmQKaXRzIGRvY3VtZW50YXRpb24gZm9yIGFueSBwdXJwb3NlIGFuZCB3 +aXRob3V0IGZlZSBpcyBoZXJlYnkKZ3JhbnRlZCwgcHJvdmlkZWQgdGhhdCB0 +aGUgYWJvdmUgY29weXJpZ2h0IG5vdGljZSBhcHBlYXIgaW4gYWxsCmNvcGll +cyBhbmQgdGhhdCBib3RoIHRoYXQgY29weXJpZ2h0IG5vdGljZSBhbmQgdGhp +cyBwZXJtaXNzaW9uCm5vdGljZSBhcHBlYXIgaW4gc3VwcG9ydGluZyBkb2N1 +bWVudGF0aW9uLCBhbmQgdGhhdCB0aGUgbmFtZSBvZiB0aGUKYXV0aG9yIG5v +dCBiZSB1c2VkIGluIGFkdmVydGlzaW5nIG9yIHB1YmxpY2l0eSBwZXJ0YWlu +aW5nIHRvCmRpc3RyaWJ1dGlvbiBvZiB0aGUgc29mdHdhcmUgd2l0aG91dCBz +cGVjaWZpYywgd3JpdHRlbiBwcmlvcgpwZXJtaXNzaW9uLiBUaGUgYXV0aG9y +IG1ha2VzIG5vIHJlcHJlc2VudGF0aW9ucyBhYm91dCB0aGUKc3VpdGFiaWxp +dHkgb2YgdGhpcyBzb2Z0d2FyZSBmb3IgYW55IHB1cnBvc2UuICBJdCBpcyBw +cm92aWRlZCAiYXMKaXMiIHdpdGhvdXQgZXhwcmVzcyBvciBpbXBsaWVkIHdh +cnJhbnR5LgoKR09BTDoKClRvIGhlbHAgIkRldGVybWluZSBvcHRpbWFsIGZk +YXRhc3luYy9mc3luYywgT19TWU5DL09fRFNZTkMgb3B0aW9ucyIKZnJvbSB0 +aGUgUG9zdGdyZVNRTCBUT0RPIGxpc3QgKGh0dHA6Ly9kZXZlbG9wZXIucG9z +dGdyZXNxbC5vcmcvdG9kby5waHApCgpXSEFUIFRISVMgRE9FUzoKCldyaXRl +cyBzZXF1ZW50aWFsIGNodW5rcyBvZiBkYXRhIHRvIGEgZmlsZSBhbmQgc3lu +Y2hyb25pemVzIHdpdGggdGhlCkkvTyBkZXZpY2UgaW4gYSB2YXJpZXR5IG9m +IHdheXMuICBHaXZlcyByZXN1bHRzIGluIG1pY3Jvc2Vjb25kcy4KCkVESVQg +QkVGT1JFIENPTVBJTElORzoKClRoZXJlIGFyZSA2IHRoaW5ncyB3aGljaCBt +dXN0IGJlIGRlZmluZWQgaW4gb3JkZXIgZm9yIHRoaXMgdGhpbmcgdG8KY29t +cGlsZS4KCkZJTEVfU1lOQyBhbmQgT1BFTl9TWU5DIGRlZmluZSBob3cgZmls +ZSBjb250ZW50cyBhcmUgdG8gYmUgc3luYydkLCBhbmQKZWFjaCBwbGF0Zm9y +bSBoYXMgdmFyaW91cyBvcHRpb25zLiAgRklMRV9TWU5DIGRlZmluZXMgdGhl +IGZ1bmN0aW9uCmNhbGwgbWFkZSB0byBzeW5jIGFmdGVyIGVhY2ggd3JpdGUo +KS4gIE1vc3QgcGxhdGZvcm1zIHNob3VsZCBzdXBwb3J0IGZzeW5jKDIpCmF0 +IGEgbWluaW11bS4gIGZkYXRhc3luYygyKSBzaG91bGQgYmUgZmFzdGVyIG9u +IHBsYXRmb3JtcyB3aGljaCBzdXBwb3J0Cml0LgoKT1BFTl9TWU5DIGRlZmlu +ZXMgdGhlIGZsYWcgdG8gYmUgc2V0IGluIG9wZW4oMikgZm9yCnN5bmNocm9u +aXppbmcgYWxsIHdyaXRlcyB3aXRob3V0IGV4cGxpY2l0bHkgY2FsbGluZyBm +c3luYygyKSBvciBpdHMKa2luZC4gIE1vc3QgcGxhdGZvcm1zIHNob3VsZCBz +dXBwb3J0IE9fU1lOQyBhdCBhIG1pbmltdW0uICBPX0RTWU5DIHNob3VsZCBi +ZQpmYXN0ZXIgb24gcGxhdGZvcm1zIHdoaWNoIHN1cHBvcnQgaXQuICBBbmQg +c29tZSBlbnZpcm9ubWVudHMgaGF2ZQpuZWl0aGVyLiAgSSBjb3VsZCBvbmx5 +IGZpbmQgT19GU1lOQyBvbiBGcmVlQlNEIDQuMTAuICBBbnl3YXksIHJlYWRp +bmcgbWFuCnBhZ2VzIGZvciBvcGVuKDIpLCBmc3luYygyKSwgYW5kIGZkYXRh +c3luYygyKSBpcyBwcm9iYWJseSBhIGdvb2QgaWRlYQpiZWZvcmUgc2V0dGlu +ZyBGSUxFX1NZTkMgYW5kIE9QRU5fU1lOQy4KCioqKioqKioqKioqKioqKioq +KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKgoqLwoKLyoK +I2RlZmluZSBGSUxFX1NZTkMoWCkgICAgZmRhdGFzeW5jKFgpCiNkZWZpbmUg +T1BFTl9TWU5DICAgICAgIE9fRFNZTkMKKi8KCi8qCioqKioqKioqKioqKioq +KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioK +ClRoZSBvdGhlciA0IG1hY3JvcyBhcmUgQ0hVTktTSVpFLCBDSFVOS1MsIEZJ +TEVTSVpFX01VTFRJUExJRVIsIGFuZApTTEVFUC4gIENIVU5LU0laRSBpcyB0 +aGUgc2l6ZSBvZiBlYWNoIGNodW5rIG9mIGRhdGEgd3JpdHRlbiBpbiB0aGUg +dGVzdC4KQ0hVTktTIGlzIHRoZSBudW1iZXIgb2YgdGltZXMgdGhleSBhcmUg +d3JpdHRlbi4gIEFsbCB3cml0ZXMgYXJlCnNlcXVlbnRpYWwuICBCZWZvcmUg +dGhlIHRlc3QgaXMgcnVuLCBhIGZpbGUgaXMgY3JlYXRlZCwgZmlsbGVkIHdp +dGgKIkEiIGNoYXJhY3RlcnMsIGZzeW5jKDIpJ2QsIGFuZCB0aGVuIGNsb3Nl +ZC4gIFRoZW4gd2Ugc2xlZXAgZm9yIFNMRUVQCnNlY29uZHMgYmVmb3JlIHBy +b2NlZWRpbmcgd2l0aCB0aGUgYWN0dWFsIGJlbmNobWFyayBydW4uICBUaGUg +c2xlZXAKaXMgdG8gbGV0IHRoZSBJL08gZGV2aWNlIHF1aWVzY2UgaWYgaXQg +d2FudHMgdG8uCgpUaGUgc2l6ZSBvZiB0aGUgZmlsZSBjcmVhdGVkIGlzIEZJ +TEVTSVpFX01VTFRJUExFUiB0aW1lcyBDSFVOS1NJWkUKdGltZXMgQ0hVTktT +LiAgU28gaWYgRklMRVNJWkVfTVVMVElQTElFUiBleGNlZWRzIDEgdGhlbiB0 +aGUgZmlsZSB3aWxsCmJlIGJpZ2dlciB0aGFuIHRoZSBhbW91bnQgb2YgZGF0 +YSB3cml0dGVuIHRvIGl0LiAgSGF2aW5nIHRoZSBmaWxlIHNpemUKZXF1YWwg +dG8gb3IgZXhjZWVkaW5nIHRoZSBhbW91bnQgb2YgZGF0YSB3cml0dGVuIHNo +b3VsZCBoZWxwIHRvIHNpbXVsYXRlCnJlYWwtd29ybGQgV0FMIGJlaGF2aW9y +LiAgRXh0ZW5kaW5nIHRoZSBzaXplIG9mIGEgZmlsZSByZXF1aXJlcyBleHRy +YQp3b3JrIGZvciB0aGUgZmlsZXN5c3RlbSB0byBwZXJmb3JtLiAgVG8gbGVh +cm4gdGhlIGltcGFjdCBvZiB0aGF0LCBnbwphaGVhZCBhbmQgc2V0IEZJTEVT +SVpFX01VTFRJUExJRVIgdG8gbGVzcyB0aGFuIDEgaWYgeW91IHdhbnQuCgoq +KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioq +KioqKioqKioqCiovCgovKgojZGVmaW5lIENIVU5LU0laRQk4ICogMTAyNAoj +ZGVmaW5lIENIVU5LUwkJMiAqIDEwMjQKI2RlZmluZSBGSUxFU0laRV9NVUxU +SVBMSUVSCTIKI2RlZmluZSBTTEVFUAkJNQoqLwoKLyogCioqKioqKioqKioq +KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioK +Ck5vdGhpbmcgZWxzZSBzaG91bGQgbmVlZCB0byBiZSBtb2RpZmllZCBmcm9t +IHRoaXMgcG9pbnQsIGJ1dCBwbGVhc2UKa2VlcCByZWFkaW5nIGZvciBidWls +ZGluZyBhbmQgcnVubmluZyBpbnN0cnVjdGlvbnMuCgpCVUlMRElORzoKSXQg +c2hvdWxkIGJlIHNpbXBsZSBhcyBsb25nIGFzIHRoZSByaWdodCB0b29scyBh +cmUgaW4geW91ciAkUEFUSCAoY2MsCmV0Yy4pCgpMaW51eCBhbmQgKkJTRCBz +ZWVtIHRvIGJlIGhhcHB5IHdpdGggdGhpczoKY2Mgc3luY2JlbmNoLmMgLW8g +c3luY2JlbmNoCgpTb2xhcmlzIDggcmVxdWlyZXMgLWxydCBpbiBvcmRlciB0 +byBzdXBwb3J0IGZkYXRhc3luYzoKY2Mgc3luY2JlbmNoLmMgLWxydCAtbyBz +eW5jYmVuY2gKCk90aGVyIE8vUydzIHlvdSdsbCBoYXZlIHRvIGZpZ3VyZSBv +dXQgb24geW91ciBvd24uCgpSVU5OSU5HOgpJdCB0YWtlcyB0d28gYXJndW1l +bnRzLiAgVGhlIGZpcnN0IGlzIHRoZSBuYW1lIG9mIHRoZSBmaWxlIHRvIHVz +ZSBmb3IKdGhlIHRlc3QuICBJZiB0aGUgZmlsZSBkb2Vzbid0IGV4aXN0IGFs +cmVhZHksIGl0IHdpbGwgYmUgY3JlYXRlZC4gIElmCml0IGRvZXMgZXhpc3Qg +YWxyZWFkeSwgdGhlbiBpdCB3aWxsIGJlIHRydW5jYXRlZCBiZWZvcmUgd3Jp +dGluZy4KClRoZSBzZWNvbmQgYXJndW1lbnQgaXMgdGhlIG1vZGUgaW4gd2hp +Y2ggZmlsZSBkYXRhIGlzIHN5bmNocm9uaXplZCB0bwpkaXNrLiAgSXQgY2Fu +IGJlIG9uZSBvZiBidWZmZXJlZCwgZmlsZXN5bmMgYW5kIG9wZW5zeW5jLiAg +YnVmZmVyZWQKbWVhbnMgbm8gc3luY2luZyB0YWtlcyBwbGFjZS4gIFVubGVz +cyB5b3VyIGZpbGVzeXN0ZW0gaXMgbW91bnRlZApzeW5jaHJvbm91c2x5IHRo +aXMgc2hvdWxkIGJlIHRoZSBmYXN0ZXN0IG9wdGlvbiBieSBmYXIuICBmaWxl +c3luYwpleGVjdXRlcyB0aGUgZnVuY3Rpb24gZGVmaW5lZCBieSBGSUxFX1NZ +TkMgYWJvdmUgYWZ0ZXIgZWFjaCBjaHVuayBvZgpkYXRhIGlzIHdyaXR0ZW4u +ICBvcGVuc3luYyBvcGVuKCkncyB0aGUgZmlsZSB3aXRoIHRoZSBmbGFnIGRl +ZmluZWQgaW4KT1BFTl9TWU5DLgoKUG9zdGdyZVNRTCBzdXBwb3J0cyA1IG1l +dGhvZHMgb2Ygc3luYydpbmcgaWYgeW91IGNvdW50ICJmc3luYz1mYWxzZSIu +ICBUaGVzZQptZXRob2RzIGFyZSBpbiBwb3N0Z3Jlc3FsLmNvbmYgdW5kZXIg +dGhlICJXUklURSBBSEVBRCBMT0ciIHNlY3Rpb24uCgpIZXJlJ3MgaG93IHRv +IHVzZSB0aGlzIHRvb2wgdG8gdHJ5IGFuZCBzaW11bGF0ZSB0aG9zZSBtZXRo +b2RzOgoKUG9zdGdyZVNRTCBNZXRob2Q6CVN5bmNiZW5jaApmc3luYz1mYWxz +ZQkJcnVuIHdpdGggMm5kIGFyZ3VtZW50PWJ1ZmZlcmVkCmZzeW5jCQkJI2Rl +ZmluZSBGSUxFX1NZTkMoWCkJZnN5bmMoWCkKCQkJMm5kIGFyZ3VtZW50PWZp +bGVzeW5jCmZkYXRhc3luYwkJI2RlZmluZSBGSUxFX1NZTkMoWCkJZmRhdGFz +eW5jKFgpCgkJCTJuZCBhcmd1bWVudD1maWxlc3luYwpvcGVuX3N5bmMJCSNk +ZWZpbmUgT1BFTl9TWU5DCU9fU1lOQwoJCQkybmQgYXJndW1lbnQ9b3BlbnN5 +bmMKb3Blbl9kYXRhc3luYwkJI2RlZmluZSBPUEVOX1NZTkMJT19EU1lOQwoJ +CQkybmQgYXJndW1lbnQ9b3BlbnN5bmMKCk9idmlvdXNseSwgaWYgdGhlIHBs +YXRmb3JtIGRvZXNuJ3Qgc3VwcG9ydCB0aG9zZSB0aGluZ3MgZm9yIHdoYXRl +dmVyCnJlYXNvbiB0aGVuIHRoZSBwcm9ncmFtIHdvbid0IGJ1aWxkLgoKUkVT +VUxUUzoKClRoZSBudW1iZXIgb2YgbWljcm9zZWNvbmRzIGJldHdlZW4gd3Jp +dGVzIHN0YXJ0aW5nIGFuZCBlbmRpbmcgaXMKZGlzcGxheWVkLiAgVGltZSB0 +YWtlbiB0byBwcmUtcG9wdWxhdGUsIG9wZW4oKSwgb3IgY2xvc2UoKSB0aGUK +ZGF0YWZpbGUgaXMgbm90IGluY2x1ZGVkIGluIHRoaXMgY2FsY3VsYXRpb24u +ICBPYnZpb3VzbHksIHRoZSByZXN1bHRzCndpbGwgdmFyeSBiYXNlZCBvbiB0 +aGUgYW1vdW50IG9mIGRhdGEgd3JpdHRlbiwgc3luY2hyb25pemF0aW9uCm9w +dGlvbnMgdXNlZCwgaGFyZHdhcmUsIE8vUywgZmlsZXN5c3RlbSwgZXRjLiAg +SXQncyBhIGdvb2QgaWRlYSB0byB0cnkKdG8gcnVuIHRoaXMgb24gc3lzdGVt +cyB3aGljaCBhcmUgYXMgaWRsZSBhcyBwb3NzaWJsZSAtLSBlc3BlY2lhbGx5 +IHRoZQpJL08gZGV2aWNlKHMpIGJlaW5nIHRlc3RlZC4KCioqKioqKioqKioq +KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioK +Ki8KCmludCBtYWluKGludCBhcmdjLCBjaGFyICphcmd2W10pCnsKCiAgaW50 +IGZkLCBuLCBibV9vcGVuZmxhZywgYm1fZG9fZmlsZXN5bmM7CiAgY2hhciAq +YnVmOyAKICBzdHJ1Y3QgdGltZXZhbCB0dl9iZWZvcmUsIHR2X2FmdGVyOwog +IHN0cnVjdCB0aW1lem9uZSB0el9nYXJiYWdlOwoKICBpZiAoIGFyZ2MgIT0g +MyApCiAgewogIHByaW50ZigidXNhZ2U6ICVzIDxmaWxlbmFtZT4gPGJ1ZmZl +cmVkfGZpbGVzeW5jfG9wZW5zeW5jPlxuIiwgYXJndlswXSApOwogIGV4aXQo +MSk7CiAgfQoKICBibV9vcGVuZmxhZz0wOwogIGJtX2RvX2ZpbGVzeW5jPTA7 +CgogIGlmICggIXN0cm5jbXAoIGFyZ3ZbMl0sICJidWZmZXJlZCIsIHN0cmxl +bigiYXN5bmMiKSApICkKICB7CiAgICBwcmludGYoInRlc3QgdXNlcyAlc1xu +IiwgYXJndlsyXSk7CiAgfSBlbHNlIGlmICggIXN0cm5jbXAoIGFyZ3ZbMl0s +ICJmaWxlc3luYyIsIHN0cmxlbigiZmlsZXN5bmMiKSApICkKICB7CiAgICBw +cmludGYoInRlc3QgdXNlcyAlc1xuIiwgYXJndlsyXSk7CiAgICBibV9kb19m +aWxlc3luYz0xOwogIH0gZWxzZSBpZiAoICFzdHJuY21wKCBhcmd2WzJdLCAi +b3BlbnN5bmMiLCBzdHJsZW4oIm9wZW5zeW5jIikgKSApCiAgewogICAgcHJp +bnRmKCJ0ZXN0IHVzZXMgJXNcbiIsIGFyZ3ZbMl0pOwogICAgYm1fb3BlbmZs +YWc9T1BFTl9TWU5DOwogIH0gZWxzZQogIHsKICAgIHB1dHMoIlNlY29uZCBh +cmd1bWVudCBtdXN0IGJlIG9uZSBvZiBhc3luYyBmaWxlc3luYyBvcGVuc3lu +YyIpOwogICAgZXhpdCgxKTsKICB9CgogIHByaW50ZigiU3RhcnRpbmcgdGVz +dCB3aXRoIEZJTEVTSVpFOiAlaSwgQ0hVTktTSVpFOiAlaSwgQ0hVTktTOiAl +aVxuIiwgXAogICAgRklMRVNJWkVfTVVMVElQTElFUiAqIENIVU5LU0laRSAq +IENIVU5LUywgQ0hVTktTSVpFLCBDSFVOS1MgKTsKICBmZCA9IG9wZW4oIGFy +Z3ZbMV0sIE9fV1JPTkxZIHwgT19DUkVBVCB8IE9fVFJVTkMsIDA2NjYgKTsK +ICBpZiAoIGZkID09IC0xICkKICB7CiAgICBwZXJyb3IoIkNhbid0IGNyZWF0 +ZSBkYXRhIGZpbGUiKTsKICAgIGV4aXQoMSk7CiAgfQogIGJ1ZiA9IG1hbGxv +YyhDSFVOS1NJWkUpOwogIGlmICggYnVmID09IE5VTEwgKQogIHsKICAgIHB1 +dHMoIm1hbGxvYyBjaG9rZWQgZm9yIHNvbWUgcmVhc29uLiAgQnllISIpOwog +ICAgZXhpdCgxKTsKICB9CiAgLyoKICAgICAqKioqKioqKioqKioqKioqKioq +KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKgog +ICAgIE1ha2Ugc3VyZSB0aGF0IHRoZSB3aG9sZSBmaWxlIGlzIG5vdCBtYWRl +IHVwIG9mIE5VTExzLgogICAgIEkgc2VlbSB0byByZWNhbGwgYSBjaGFyYWN0 +ZXJpc3RpYyBvZiAqTklYIGZpbGVzeXN0ZW1zIHRoYXQgbGlrZXMKICAgICB0 +byBub3QgcG9wdWxhdGUgTlVMTC1maWxsZWQgZmlsZXMgd2l0aCBhY3R1YWwg +YmxvY2tzIGZ1bGwgb2YgTlVMTHMuCiAgICAgVGhpcyBtYXkgY2F1c2UgYWN0 +dWFsIHBvcHVsYXRpb24gb2YgdGhlIGZpbGUgdG8gY2F1c2UgYW4gdXBkYXRl +CiAgICAgb2YgbWV0YWRhdGEsIHdoaWNoIG1pZ2h0IGNhdXNlIHBlcmZvcm1h +bmNlIGlzc3Vlcy4gIEFueXdheSwgCiAgICAgcHJlLXBvcHVsYXRlIHRoZSBm +aWxlIHdpdGggIkEiIHRvIGhlZGdlIGFnYWluc3QgdGhhdC4KICAgICBJdCBt +YXkgYmUgZGVzaXJhYmxlIHRvIHByZS1wb3B1bGF0ZSBqdXN0IGxpa2UgV0FM +IGlzIHByZS1wb3B1bGF0ZWQuCiAgICAgT3IgbWF5YmUgdGhpcyBkb2Vzbid0 +IG1hdHRlci4KICAgICAqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioq +KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioKICAqLwogIG1lbXNl +dChidWYsIDY1LCBDSFVOS1NJWkUpOwogIAogIGZvciAoIG49MDsgbjxDSFVO +S1MqRklMRVNJWkVfTVVMVElQTElFUjsgbisrKQogIHsKICAgIGlmICggd3Jp +dGUoZmQsIGJ1ZiwgQ0hVTktTSVpFKSA9PSAtMSApCiAgICB7CiAgICAgIHBl +cnJvcigiQ2FuJ3Qgd3JpdGUgdG8gZGF0YSBmaWxlIik7CiAgICAgIGV4aXQo +MSk7CiAgICB9CiAgfQoKICBmcmVlKGJ1Zik7CgogIGlmICggZnN5bmMoZmQp +ICkKICB7CiAgICBwZXJyb3IoIkNhbid0IGZzeW5jIGRhdGEgZmlsZSIpOwog +ICAgZXhpdCgxKTsKICB9CgogIGlmICggY2xvc2UoZmQpICkKICB7CiAgICBw +ZXJyb3IoIkNhbid0IGNsb3NlIGRhdGEgZmlsZSIpOwogICAgZXhpdCgxKTsK +ICB9CgogIC8qIHNsZWVwIGZvciBncmlucy4gIHNvIG1heWJlIHRoZSBkZXZp +Y2Ugc2xvd3MgZG93biAqLwogIHNsZWVwKFNMRUVQKTsKCi8qIE9LIGl0J3Mg +Y3JlYXRlZC4gIE5vdyBvcGVuIGl0IGFnYWluIHRoZW4gc3RhcnQgdGhlIHNo +b3cgKi8KCiAgZmQgPSBvcGVuKCBhcmd2WzFdLCBPX1dST05MWSB8IGJtX29w +ZW5mbGFnLCAwNjY2ICk7CiAgaWYgKCBmZCA9PSAtMSApCiAgewogICAgcGVy +cm9yKCJDYW4ndCBvcGVuIGRhdGEgZmlsZSBmb3Igd3JpdGluZyIpOwogICAg +ZXhpdCgxKTsKICB9CiAgYnVmPW1hbGxvYyhDSFVOS1NJWkUpOwogIGlmICgg +YnVmID09IE5VTEwgKQogIHsKICAgIHB1dHMoIm1hbGxvYyBjaG9rZWQgZm9y +IHNvbWUgcmVhc29uLiIpOwogICAgZXhpdCgxKTsKICB9CiAgbWVtc2V0KGJ1 +ZiwgNjYsIENIVU5LU0laRSk7CgogIGdldHRpbWVvZmRheSggJnR2X2JlZm9y +ZSwgJnR6X2dhcmJhZ2UgKTsKICBmb3IgKCBuPTA7IG48Q0hVTktTOyBuKysp +CiAgewogICAgaWYgKCB3cml0ZShmZCwgYnVmLCBDSFVOS1NJWkUpID09IC0x +ICkKICAgIHsKICAgICAgcGVycm9yKCJDYW4ndCB3cml0ZSB0byBleGlzdGlu +ZyBkYXRhIGZpbGUiKTsKICAgICAgZXhpdCgxKTsKICAgIH0KICAgIGlmICgg +Ym1fZG9fZmlsZXN5bmMgKQogICAgewogICAgICBpZiAoIEZJTEVfU1lOQyhm +ZCkgKQogICAgICB7CiAgICAgICAgcGVycm9yKCJDYW4ndCBzeW5jIGRhdGEg +ZmlsZSIpOwogICAgICAgIGV4aXQoMSk7CiAgICAgIH0KICAgIH0KICB9IAog +IGdldHRpbWVvZmRheSggJnR2X2FmdGVyLCAmdHpfZ2FyYmFnZSApOwoKICBm +cmVlKGJ1Zik7CiAgcHJpbnRmKCJFbGFwc2VkIHVzZWM6ICVpXG4iLCAoICgo +dHZfYWZ0ZXIudHZfc2VjICogMTAwMDAwMCkgKwogICAgdHZfYWZ0ZXIudHZf +dXNlYykgLSAoKHR2X2JlZm9yZS50dl9zZWMgKiAxMDAwMDAwKSArIHR2X2Jl +Zm9yZS50dl91c2VjKSApICk7Cgp9Cgo= + +---MOQ1095055866e1dd2dbc1ed81c0f7e60b7cb17d6f7b3-- + +From pgsql-performance-owner@postgresql.org Mon Sep 13 08:58:14 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 339E9329E57 + for ; + Mon, 13 Sep 2004 08:58:02 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 83207-03 + for ; + Mon, 13 Sep 2004 07:57:56 +0000 (GMT) +Received: from web41501.mail.yahoo.com (web41501.mail.yahoo.com + [66.218.93.84]) + by svr1.postgresql.org (Postfix) with SMTP id AFACF329E51 + for ; + Mon, 13 Sep 2004 08:57:56 +0100 (BST) +Message-ID: <20040913075752.22635.qmail@web41501.mail.yahoo.com> +Received: from [67.33.169.246] by web41501.mail.yahoo.com via HTTP; + Mon, 13 Sep 2004 00:57:52 PDT +Date: Mon, 13 Sep 2004 00:57:52 -0700 (PDT) +From: Mark Cotner +Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres -- merge tables +To: pgsql-performance@postgresql.org +In-Reply-To: +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/81 +X-Sequence-Number: 8209 + +See comments . . . thanks for the feedback. + +'njoy, +Mark + +--- Christopher Browne wrote: + +> The world rejoiced as Mischa Sandberg +> wrote: +> > Mark Cotner wrote: +> >> Requirements: +> >> Merge table definition equivalent. We use these +> >> extensively. +> +> > Looked all over mysql.com etc, and afaics merge +> table is indeed +> > exactly a view of a union-all. Is that right? +> +> > PG supports views, of course, as well (now) as +> tablespaces, allowing +> > you to split tables/tablesets across multiple disk +> systems. PG is +> > also pretty efficient in query plans on such +> views, where (say) you +> > make one column a constant (identifier, sort of) +> per input table. +> +> The thing that _doesn't_ work well with these sorts +> of UNION views are +> when you do self-joins. Supposing you have 10 +> members, a self-join +> leads to a 100-way join, which is not particularly +> pretty. +> +> I'm quite curious as to how MySQL(tm) copes with +> this, although it may +> not be able to take place; they may not support +> that... +> +> >> Um, gonna sound silly, but the web interface has +> to remain "snappy" +> >> under load. I don't see this as a major concern +> since you don't +> >> require table locking. +> +> > Agreed. It's more in your warehouse design, and +> intelligent bounding +> > of queries. I'd say PG's query analyzer is a few +> years ahead of +> > MySQL for large and complex queries. +> +> The challenge comes in if the application has had +> enormous amounts of +> effort put into it to attune it exactly to +> MySQL(tm)'s feature set. +> +> The guys working on RT/3 have found this a +> challenge; they had rather +> a lot of dependancies on its case-insensitive string +> comparisons, +> causing considerable grief. +> + +Not so much, I've tried to be as agnostic as possible. + Much of the more advanced mining that I've written is +kinda MySQL specific, but needs to be rewritten as +stored procedures anyway. + +> > On the other hand, if you do warehouse-style +> loading (Insert, or PG +> > COPY, into a temp table; and then 'upsert' into +> the perm table), I +> > can guarantee 2500 inserts/sec is no problem. +> +> The big wins are thus: +> +> 1. Group plenty of INSERTs into a single +> transaction. +> +> 2. Better still, use COPY to cut parsing costs +> plenty more. +> +> 3. Adding indexes _after_ the COPY are a further +> win. +> +> Another possibility is to do clever things with +> stored procs; load +> incoming data using the above optimizations, and +> then run stored +> procedures to use some more or less fancy logic to +> put the data where +> it's ultimately supposed to be. Having the logic +> running inside the +> engine is the big optimization. + +Agreed, I did some preliminary testing today and am +very impressed. I wasn't used to running analyze +after a data load, but once I did that everything was +snappy. + +My best results from MySQL bulk inserts was around 36k +rows per second on a fairly wide table. Today I got +42k using the COPY command, but with the analyze post +insert the results were similar. These are excellent +numbers. It basically means we could have our +cake(great features) and eat it too(performance that's +good enough to run the app). + +Queries from my test views were equally pleasing. I +won't bore you with the details just yet, but +PostgreSQL is doing great. Not that you all are +surprised. ;) + + +> -- +> wm(X,Y):-write(X),write('@'),write(Y). +> wm('cbbrowne','linuxfinances.info'). +> http://linuxfinances.info/info/spreadsheets.html +> Rules of the Evil Overlord #198. "I will +> remember that any +> vulnerabilities I have are to be revealed strictly +> on a need-to-know +> basis. I will also remember that no one needs to +> know." +> +> +> ---------------------------(end of +> broadcast)--------------------------- +> TIP 8: explain analyze is your friend +> + + +From pgsql-performance-owner@postgresql.org Mon Sep 13 11:06:52 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 6F197329DD0 + for ; + Mon, 13 Sep 2004 11:06:41 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 25326-01 + for ; + Mon, 13 Sep 2004 10:06:35 +0000 (GMT) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by svr1.postgresql.org (Postfix) with ESMTP id 5ABF7329DB3 + for ; + Mon, 13 Sep 2004 11:06:36 +0100 (BST) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by news.hub.org (8.12.9/8.12.9) with ESMTP id i8DA6XCr025464 + for ; Mon, 13 Sep 2004 10:06:34 GMT + (envelope-from news@news.hub.org) +Received: (from news@localhost) + by news.hub.org (8.12.9/8.12.9/Submit) id i8D9o1hl020257 + for pgsql-performance@postgresql.org; Mon, 13 Sep 2004 09:50:01 GMT +From: Christopher Browne +X-Newsgroups: comp.databases.postgresql.performance +Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres -- merge tables +Date: Mon, 13 Sep 2004 05:21:42 -0400 +Organization: cbbrowne Computing Inc +Lines: 76 +Message-ID: +References: + <20040913075752.22635.qmail@web41501.mail.yahoo.com> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Complaints-To: usenet@news.hub.org +X-message-flag: Outlook is rather hackable, isn't it? +X-Home-Page: http://www.cbbrowne.com/info/ +X-Affero: http://svcs.affero.net/rm.php?r=cbbrowne +User-Agent: Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.4 (Security Through + Obscurity, + linux) +Cancel-Lock: sha1:vYAVGejSrshe5dTV2vs2YiGJLqI= +To: pgsql-performance@postgresql.org +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/82 +X-Sequence-Number: 8210 + +A long time ago, in a galaxy far, far away, mcotner@yahoo.com (Mark Cotner) wrote: +> Agreed, I did some preliminary testing today and am very impressed. +> I wasn't used to running analyze after a data load, but once I did +> that everything was snappy. + +Something worth observing is that this is true for _any_ of the +database systems supporting a "cost-based" optimization system, +including Oracle and DB2. + +When working with SAP R/3 Payroll, on one project, we found that when +the system was empty of data, the first few employee creates were +quick enough, but it almost immediately got excruciatingly slow. One +of the DBAs told the Oracle instance underneath to collect statistics +on the main table, and things _immediately_ got snappy again. But it +didn't get snappy until the conversion folk had run the conversion +process for several minutes, to the point to which it would get +painfully slow :-(. There, with MILLIONS of dollars worth of license +fees being paid, across the various vendors, it still took a fair bit +of manual fiddling. + +MySQL(tm) is just starting to get into cost-based optimization; in +that area, they're moving from where the "big DBs" were about 10 years +ago. It was either version 7 or 8 where Oracle started moving to +cost-based optimization, and (as with the anecdote above) it took a +release or two for people to get accustomed to the need to 'feed' the +optimizer with statistics. This is a "growing pain" that bites users +with any database where this optimization gets introduced. It's +worthwhile, but is certainly not costless. + +I expect some forseeable surprises will be forthcoming for MySQL AB's +customers in this regard... + +> My best results from MySQL bulk inserts was around 36k rows per +> second on a fairly wide table. Today I got 42k using the COPY +> command, but with the analyze post insert the results were similar. +> These are excellent numbers. It basically means we could have our +> cake(great features) and eat it too(performance that's good enough +> to run the app). + +In the end, performance for inserts is always fundamentally based on +how much disk I/O there is, and so it should come as no shock that +when roughly the same amount of data is getting laid down on disk, +performance won't differ much on these sorts of essentials. + +There are a few places where there's some need for cleverness; if you +see particular queries running unusually slowly, it's worth doing an +EXPLAIN or EXPLAIN ANALYZE on them, to see how the query plans are +being generated. There's some collected wisdom out here on how to +encourage the right plans. + +There are also unexpected results that are OK. We did a system +upgrade a few days ago that led to one of the tables starting out +totally empty. A summary report that looks at that table wound up +with a pretty wacky looking query plan (compared to what's usual) +because the postmaster knew that the query would be reading in +essentially the entire table. You'd normally expect an index scan, +looking for data for particular dates. In this case, it did a "scan +the whole table; filter out a few irrelevant entries" plan. + +It looked wacky, compared to what's usual, but it ran in about 2 +seconds, which was way FASTER than what's usual. So the plan was +exactly the right one. + +Telling the difference between the right plan and a poor one is a bit +of an art; we quite regularly take a look at query plans on this list +to figure out what might be not quite right. If you find slow ones, +make sure you have run ANALYZE on the tables recently, to be sure that +the plans are sane, and you may want to consider posting some of them +to see if others can point to improvements that can be made. +-- +If this was helpful, rate me +http://linuxfinances.info/info/linuxdistributions.html +"I can't believe my room doesn't have Ethernet! Why wasn't it wired +when the house was built?" +"The house was built in 1576." +-- Alex Kamilewicz on the Oxford breed of `conference American.' + +From pgsql-performance-owner@postgresql.org Mon Sep 13 12:38:17 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 0197E329C7B + for ; + Mon, 13 Sep 2004 12:38:15 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 49685-07 + for ; + Mon, 13 Sep 2004 11:38:07 +0000 (GMT) +Received: from mailserv.mobilecohesion.com (picard.mobilecohesion.com + [80.4.157.11]) + by svr1.postgresql.org (Postfix) with ESMTP id 1A2E3329C70 + for ; + Mon, 13 Sep 2004 12:38:09 +0100 (BST) +Received: from cpc1-blfs1-3-0-cust245.blfs.cable.ntl.com ([213.107.97.245] + helo=a31p005) by mailserv.mobilecohesion.com with asmtp (Exim 4.10) + id 1C6p9m-0007dr-00 + for pgsql-performance@postgresql.org; Mon, 13 Sep 2004 12:38:03 +0100 +From: "Damien Dougan" +To: +Subject: Help with extracting large volumes of records across related tables +Date: Mon, 13 Sep 2004 12:38:05 +0100 +Organization: Mobile Cohesion +Message-ID: <004b01c49986$228c3d60$6e01a8c0@a31p005> +MIME-Version: 1.0 +Content-Type: text/plain; + charset="us-ascii" +Content-Transfer-Encoding: 7bit +X-Priority: 3 (Normal) +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook, Build 10.0.4024 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 +Importance: Normal +X-MobileCohesion-MailScanner-Information: Please contact the ISP for more + information +X-MobileCohesion-MailScanner: Found to be clean +X-MailScanner-From: damien.dougan@mobilecohesion.com +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/83 +X-Sequence-Number: 8211 + + +Hi All, + +I am having a performance problem extracting a large volume of data from +Postgres 7.4.2, and was wondering if there was a more cunning way to get +the data out of the DB... + +This isn't a performance problem with any particular PgSQL operation, +its more a strategy for getting large volumes of related tables out of +the DB whilst perserving the relations between them. + + +Basically we have a number of tables, which are exposed as 2 public +views (say PvA and PvB). For each row in PvA, there are a number of +related rows in PvB (this number is arbitrary, which is one of the +reasons why it cant be expressed as additional columns in PvA - so we +really need 2 sets of tables - which leads to two sets of extract calls +- interwoven to associate PvA with PvB). + + +The problem is that for extraction, we ultimately want to grab a row +from PvA, and then all the related rows from PvB and store them together +offline (e.g. in XML). + +However, the number of rows at any time on the DB is likely to be in the +millions, with perhaps 25% of them being suitable for extraction at any +given batch run (ie several hundred thousand to several million). + + +Currently, the proposal is to grab several hundred rows from PvA (thus +avoiding issues with the resultset being very large), and then process +each of them by selecting the related rows in PvB (again, several +hundred rows at a time to avoid problems with large result sets). + +So the algorithm is basically: + + + Do + + Select the next 200 rows from PvA + + For each PvA row Do + Write current PvA row as XML + + Do + Select the next 200 rows from PvB + + For each PvB row Do + Write current PvB row as XML +within the parent PvA XML Element + End For + While More Rows + End For + While More Rows + + +However, this has a fairly significant performance impact, and I was +wondering if there was a faster way to do it (something like taking a +dump of the tables so they can be worked on offline - but a basic dump +means we have lost the 1:M relationships between PvA and PvB). + + +Are there any tools/tricks/tips with regards to extracting large volumes +of data across related tables from Postgres? It doesnt have to export +into XML, we can do post-processing on the extracted data as needed - +the important thing is to keep the relationship between PvA and PvB on a +row-by-row basis. + + +Many thanks, + +Damien + + +From pgsql-performance-owner@postgresql.org Mon Sep 13 13:12:05 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id CE5F3329DB0 + for ; + Mon, 13 Sep 2004 13:12:02 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 62943-05 + for ; + Mon, 13 Sep 2004 12:11:55 +0000 (GMT) +Received: from curry.tmsl.demon.co.uk (tmsl-adsl.demon.co.uk [80.177.114.181]) + by svr1.postgresql.org (Postfix) with ESMTP id 38395329C82 + for ; + Mon, 13 Sep 2004 13:11:57 +0100 (BST) +Received: from bacon.tmsl.demon.co.uk (bacon.tmsl.demon.co.uk [192.168.7.102]) + by curry.tmsl.demon.co.uk (8.11.6/8.11.6) with ESMTP id i8DCAv831388; + Mon, 13 Sep 2004 13:11:25 +0100 +Date: Mon, 13 Sep 2004 13:10:23 +0100 +From: Paul Thomas +To: Damien Dougan +Cc: pgsql-performance@postgresql.org +Subject: Re: Help with extracting large volumes of records across related + tables +Message-ID: <20040913131023.A6743@bacon> +References: <004b01c49986$228c3d60$6e01a8c0@a31p005> +Mime-Version: 1.0 +Content-Type: text/plain; format=flowed; charset=ISO-8859-1 +In-Reply-To: <004b01c49986$228c3d60$6e01a8c0@a31p005>; + from damien.dougan@mobilecohesion.com on Mon, Sep 13, 2004 at + 12:38:05 +0100 +X-Mailer: Balsa 1.2.3 +Lines: 17 +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/84 +X-Sequence-Number: 8212 + + +On 13/09/2004 12:38 Damien Dougan wrote: +> [snip] +> Are there any tools/tricks/tips with regards to extracting large volumes +> of data across related tables from Postgres? It doesnt have to export +> into XML, we can do post-processing on the extracted data as needed - +> the important thing is to keep the relationship between PvA and PvB on a +> row-by-row basis. + +Have you considered using cursors? + +-- +Paul Thomas ++------------------------------+-------------------------------------------+ +| Thomas Micro Systems Limited | Software Solutions for Business | +| Computer Consultants | http://www.thomas-micro-systems-ltd.co.uk | ++------------------------------+-------------------------------------------+ + +From pgsql-performance-owner@postgresql.org Tue Sep 14 05:25:08 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 75958329E01 + for ; + Mon, 13 Sep 2004 14:06:48 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 85513-04 + for ; + Mon, 13 Sep 2004 13:06:35 +0000 (GMT) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by svr1.postgresql.org (Postfix) with ESMTP id 37CF5329E1C + for ; + Mon, 13 Sep 2004 14:06:38 +0100 (BST) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by news.hub.org (8.12.9/8.12.9) with ESMTP id i8DD6XCn087040 + for ; Mon, 13 Sep 2004 13:06:33 GMT + (envelope-from news@news.hub.org) +Received: (from news@localhost) + by news.hub.org (8.12.9/8.12.9/Submit) id i8DCwraF083611 + for pgsql-performance@postgresql.org; Mon, 13 Sep 2004 12:58:53 GMT +From: Mischa Sandberg +Reply-To: ischamay.andbergsay@activestateway.com +User-Agent: Mozilla Thunderbird 0.7.3 (X11/20040803) +X-Accept-Language: en-us, en +MIME-Version: 1.0 +X-Newsgroups: comp.databases.postgresql.performance +Subject: Re: Help with extracting large volumes of records across related +References: <004b01c49986$228c3d60$6e01a8c0@a31p005> +In-Reply-To: <004b01c49986$228c3d60$6e01a8c0@a31p005> +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit +Lines: 50 +Message-ID: +Date: Mon, 13 Sep 2004 12:58:57 GMT +To: pgsql-performance@postgresql.org +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, + hits=1.1 tagged_above=0.0 required=5.0 tests=NO_DNS_FOR_FROM +X-Spam-Level: * +X-Archive-Number: 200409/107 +X-Sequence-Number: 8235 + +Damien Dougan wrote: +> Basically we have a number of tables, which are exposed as 2 public +> views (say PvA and PvB). For each row in PvA, there are a number of +> related rows in PvB (this number is arbitrary, which is one of the +> reasons why it cant be expressed as additional columns in PvA - so we +> really need 2 sets of tables - which leads to two sets of extract calls +> - interwoven to associate PvA with PvB). +> +> Are there any tools/tricks/tips with regards to extracting large volumes +> of data across related tables from Postgres? It doesnt have to export +> into XML, we can do post-processing on the extracted data as needed - +> the important thing is to keep the relationship between PvA and PvB on a +> row-by-row basis. + +Just recently had to come up with an alternative to MSSQL's "SQL..FOR +XML", for some five-level nested docs, that turned out to be faster (!) +and easier to understand: + +Use SQL to organize each of the row types into a single text field, plus +a single key field, as well as any filter fields you . Sort the union, +and have the reading process break them into documents. + +For example, if PvA has key (account_id, order_id) and +fields(order_date, ship_date) and PvB has key (order_id, product_id) and +fields (order_qty, back_order) + +CREATE VIEW PvABxml AS +SELECT account_id::text + order_id::text AS quay + ,'order_date="' + order_date::text + + '" ship_date="' + ship_date::text + '"' AS info + ,ship_date +FROM PvA + UNION ALL +SELECT account_id::text + order_id::text + product_id::text + ,'order_qty="' + order_qty::text +'"' + ,ship_date +FROM PvA JOIN PvB USING (order_id) + +Then: + +SELECT quay, info +FROM pvABxml +WHERE ship_date = '...' +ORDER BY quay + +gives you a stream of info in the (parent,child,child... +parent,child,child...) order you want, that assemble very easily into +XML documents. If you need to pick out, say, orders where there are +backordered items, you probably need to work with a temp table with +which to prefilter. + +From pgsql-performance-owner@postgresql.org Mon Sep 13 14:01:00 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 9B583329E44 + for ; + Mon, 13 Sep 2004 14:00:59 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 81103-07 + for ; + Mon, 13 Sep 2004 13:00:50 +0000 (GMT) +Received: from boutiquenumerique.com (gailleton-2-82-67-9-10.fbx.proxad.net + [82.67.9.10]) + by svr1.postgresql.org (Postfix) with ESMTP id 3F216329DB0 + for ; + Mon, 13 Sep 2004 14:00:48 +0100 (BST) +Received: (qmail 32670 invoked from network); 13 Sep 2004 15:00:56 +0200 +Received: from unknown (HELO musicbox) (192.168.0.2) + by gailleton-2-82-67-9-10.fbx.proxad.net with SMTP; + 13 Sep 2004 15:00:56 +0200 +Date: Mon, 13 Sep 2004 15:01:49 +0200 +To: pgsql-performance@postgresql.org +Subject: Re: Help with extracting large volumes of records across related + tables +References: <004b01c49986$228c3d60$6e01a8c0@a31p005> + <20040913131023.A6743@bacon> +From: =?iso-8859-15?Q?Pierre-Fr=E9d=E9ric_Caillaud?= + +Organization: =?iso-8859-15?Q?La_Boutique_Num=E9rique?= +Content-Type: text/plain; format=flowed; delsp=yes; charset=iso-8859-15 +MIME-Version: 1.0 +Content-Transfer-Encoding: 8bit +Message-ID: +In-Reply-To: <20040913131023.A6743@bacon> +User-Agent: Opera M2/7.53 (Linux, build 737) +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/85 +X-Sequence-Number: 8213 + + + + There's a very simple solution using cursors. + + As an example : + +create table categories ( id serial primary key, name text ); +create table items ( id serial primary key, cat_id integer references +categories(id), name text ); +create index items_cat_idx on items( cat_id ); + +insert stuff... + +select * from categories; + id | name +----+---------- + 1 | tools + 2 | supplies + 3 | food +(3 lignes) + +select * from items; + id | cat_id | name +----+--------+-------------- + 1 | 1 | hammer + 2 | 1 | screwdriver + 3 | 2 | nails + 4 | 2 | screws + 5 | 1 | wrench + 6 | 2 | bolts + 7 | 2 | cement + 8 | 3 | beer + 9 | 3 | burgers + 10 | 3 | french fries +(10 lignes) + + Now (supposing you use Python) you use the extremely simple sample +program below : + +import psycopg +db = psycopg.connect("host=localhost dbname=rencontres user=rencontres +password=.........") + +# Simple. Let's make some cursors. +cursor = db.cursor() +cursor.execute( "BEGIN;" ) +cursor.execute( "declare cat_cursor no scroll cursor without hold for +select * from categories order by id for read only;" ) +cursor.execute( "declare items_cursor no scroll cursor without hold for +select * from items order by cat_id for read only;" ) + +# set up some generators +def qcursor( cursor, psql_cursor_name ): + while True: + cursor.execute( "fetch 2 from %s;" % psql_cursor_name )guess + if not cursor.rowcount: + break +# print "%s fetched %d rows." % (psql_cursor_name, cursor.rowcount) + for row in cursor.dictfetchall(): + yield row + print "%s exhausted." % psql_cursor_name + +# use the generators +categories = qcursor( cursor, "cat_cursor" ) +items = qcursor( cursor, "items_cursor" ) + +current_item = items.next() +for cat in categories: + print "Category : ", cat + + # if no items (or all items in category are done) skip to next category + if cat['id'] < current_item['cat_id']: + continue + + # case of items without category (should not happen) + while cat['id'] > current_item['cat_id']: + current_item = items.next() + + while current_item['cat_id'] == cat['id']: + print "\t", current_item + current_item = items.next() + + +It produces the following output : + +Category : {'id': 1, 'name': 'tools'} + {'cat_id': 1, 'id': 1, 'name': 'hammer'} + {'cat_id': 1, 'id': 2, 'name': 'screwdriver'} + {'cat_id': 1, 'id': 5, 'name': 'wrench'} +Category : {'id': 2, 'name': 'supplies'} + {'cat_id': 2, 'id': 3, 'name': 'nails'} + {'cat_id': 2, 'id': 4, 'name': 'screws'} + {'cat_id': 2, 'id': 6, 'name': 'bolts'} + {'cat_id': 2, 'id': 7, 'name': 'cement'} +Category : {'id': 3, 'name': 'food'} + {'cat_id': 3, 'id': 8, 'name': 'beer'} + {'cat_id': 3, 'id': 9, 'name': 'burgers'} + {'cat_id': 3, 'id': 10, 'name': 'french fries'} + +This simple code, with "fetch 1000" instead of "fetch 2", dumps a database +of several million rows, where each categories contains generally 1 but +often 2-4 items, at the speed of about 10.000 items/s. + +Satisfied ? + + + + + + + +From pgsql-performance-owner@postgresql.org Mon Sep 13 14:04:48 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 033BE329E01 + for ; + Mon, 13 Sep 2004 14:04:47 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 81174-08 + for ; + Mon, 13 Sep 2004 13:04:39 +0000 (GMT) +Received: from boutiquenumerique.com (gailleton-2-82-67-9-10.fbx.proxad.net + [82.67.9.10]) + by svr1.postgresql.org (Postfix) with ESMTP id 71984329DB0 + for ; + Mon, 13 Sep 2004 14:04:42 +0100 (BST) +Received: (qmail 490 invoked from network); 13 Sep 2004 15:04:51 +0200 +Received: from unknown (HELO musicbox) (192.168.0.2) + by gailleton-2-82-67-9-10.fbx.proxad.net with SMTP; + 13 Sep 2004 15:04:51 +0200 +Date: Mon, 13 Sep 2004 15:05:43 +0200 +To: pgsql-performance@postgresql.org +Subject: Re: Help with extracting large volumes of records across related + tables +References: <004b01c49986$228c3d60$6e01a8c0@a31p005> + <20040913131023.A6743@bacon> +From: =?iso-8859-15?Q?Pierre-Fr=E9d=E9ric_Caillaud?= + +Organization: =?iso-8859-15?Q?La_Boutique_Num=E9rique?= +Content-Type: text/plain; format=flowed; delsp=yes; charset=iso-8859-15 +MIME-Version: 1.0 +Content-Transfer-Encoding: 8bit +Message-ID: +In-Reply-To: <20040913131023.A6743@bacon> +User-Agent: Opera M2/7.53 (Linux, build 737) +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/86 +X-Sequence-Number: 8214 + + +My simple python program dumps 1653992 items in 1654000 categories in : + +real 3m12.029s +user 1m36.720s +sys 0m2.220s + +It was running on the same machine as postgresql (AthlonXP 2500). +I Ctrl-C'd it before it dumped all the database but you get an idea. + +If you don't know Python and Generators, have a look ! + +From pgsql-performance-owner@postgresql.org Mon Sep 13 14:45:09 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 4BC1C329E01 + for ; + Mon, 13 Sep 2004 14:44:54 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 98387-06 + for ; + Mon, 13 Sep 2004 13:44:46 +0000 (GMT) +Received: from mailserv.mobilecohesion.com (picard.mobilecohesion.com + [80.4.157.11]) + by svr1.postgresql.org (Postfix) with ESMTP id C7C0C329E6C + for ; + Mon, 13 Sep 2004 14:44:48 +0100 (BST) +Received: from cpc1-blfs1-3-0-cust245.blfs.cable.ntl.com ([213.107.97.245] + helo=a31p005) by mailserv.mobilecohesion.com with asmtp (Exim 4.10) + id 1C6r8O-0008DA-00 + for pgsql-performance@postgresql.org; Mon, 13 Sep 2004 14:44:44 +0100 +From: "Damien Dougan" +To: +Subject: Re: Help with extracting large volumes of records across related + tables +Date: Mon, 13 Sep 2004 14:44:45 +0100 +Organization: Mobile Cohesion +Message-ID: <005801c49997$d4a91a20$6e01a8c0@a31p005> +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +X-Priority: 3 (Normal) +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook, Build 10.0.4024 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 +In-Reply-To: +Importance: Normal +X-MobileCohesion-MailScanner-Information: Please contact the ISP for more + information +X-MobileCohesion-MailScanner: Found to be clean +X-MailScanner-From: damien.dougan@mobilecohesion.com +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/87 +X-Sequence-Number: 8215 + +Pierre-Frederic, Paul, + +Thanks for your fast response (especially for the python code and +performance figure) - I'll chase this up as a solution - looks most +promising! + +Cheers, + +Damien + + +From pgsql-performance-owner@postgresql.org Mon Sep 13 14:59:46 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 8E2EC329E01 + for ; + Mon, 13 Sep 2004 14:59:40 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 02838-08 + for ; + Mon, 13 Sep 2004 13:59:32 +0000 (GMT) +Received: from boutiquenumerique.com (gailleton-2-82-67-9-10.fbx.proxad.net + [82.67.9.10]) + by svr1.postgresql.org (Postfix) with ESMTP id CDCD6329E1C + for ; + Mon, 13 Sep 2004 14:59:32 +0100 (BST) +Received: (qmail 2431 invoked from network); 13 Sep 2004 15:59:42 +0200 +Received: from unknown (HELO musicbox) (192.168.0.2) + by gailleton-2-82-67-9-10.fbx.proxad.net with SMTP; + 13 Sep 2004 15:59:42 +0200 +To: pgsql-performance@postgresql.org +Subject: Re: Help with extracting large volumes of records across related + tables +References: <005801c49997$d4a91a20$6e01a8c0@a31p005> +Message-ID: +Date: Mon, 13 Sep 2004 16:00:35 +0200 +From: =?iso-8859-15?Q?Pierre-Fr=E9d=E9ric_Caillaud?= + +Organization: =?iso-8859-15?Q?La_Boutique_Num=E9rique?= +Content-Type: text/plain; format=flowed; delsp=yes; charset=iso-8859-15 +MIME-Version: 1.0 +Content-Transfer-Encoding: 8bit +In-Reply-To: <005801c49997$d4a91a20$6e01a8c0@a31p005> +User-Agent: Opera M2/7.53 (Linux, build 737) +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/88 +X-Sequence-Number: 8216 + + + Thanks for the thanks ! + + Generally, when grouping stuff together, it is a good idea to have two +sorted lists, and to scan them simultaneously. I have already used this +solution several times outside of Postgres, and it worked very well (it +was with Berkeley DB and there were 3 lists to scan in order). The fact +that Python can very easily virtualize these lists using generators makes +it possible to do it without consuming too much memory. + +> Pierre-Frederic, Paul, +> +> Thanks for your fast response (especially for the python code and +> performance figure) - I'll chase this up as a solution - looks most +> promising! +> +> Cheers, +> +> Damien +> +> +> ---------------------------(end of broadcast)--------------------------- +> TIP 6: Have you searched our list archives? +> +> http://archives.postgresql.org +> + + + +From pgsql-performance-owner@postgresql.org Mon Sep 13 15:38:24 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 661DC329E62 + for ; + Mon, 13 Sep 2004 15:38:20 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 35382-06 + for ; + Mon, 13 Sep 2004 14:38:11 +0000 (GMT) +Received: from candle.pha.pa.us (candle.pha.pa.us [207.106.42.251]) + by svr1.postgresql.org (Postfix) with ESMTP id D3C3F329D14 + for ; + Mon, 13 Sep 2004 15:38:12 +0100 (BST) +Received: (from pgman@localhost) + by candle.pha.pa.us (8.11.6/8.11.6) id i8DEc8r04384; + Mon, 13 Sep 2004 10:38:08 -0400 (EDT) +From: Bruce Momjian +Message-Id: <200409131438.i8DEc8r04384@candle.pha.pa.us> +Subject: Re: Determine optimal fdatasync/fsync, O_SYNC/O_DSYNC options +In-Reply-To: <1095055866.414539fadb90d@webmail.rawbw.com> +To: mudfoot@rawbw.com +Date: Mon, 13 Sep 2004 10:38:08 -0400 (EDT) +Cc: pgsql-performance@postgresql.org +X-Mailer: ELM [version 2.4ME+ PL108 (25)] +MIME-Version: 1.0 +Content-Transfer-Encoding: 7bit +Content-Type: text/plain; charset=US-ASCII +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/89 +X-Sequence-Number: 8217 + + +Have you seen /src/tools/fsync? + +--------------------------------------------------------------------------- + +mudfoot@rawbw.com wrote: +> Hi, I'd like to help with the topic in the Subject: line. It seems to be a +> TODO item. I've reviewed some threads discussing the matter, so I hope I've +> acquired enough history concerning it. I've taken an initial swipe at +> figuring out how to optimize sync'ing methods. It's based largely on +> recommendations I've read on previous threads about fsync/O_SYNC and so on. +> After reviewing, if anybody has recommendations on how to proceed then I'd +> love to hear them. +> +> Attached is a little program that basically does a bunch of sequential writes +> to a file. All of the sync'ing methods supported by PostgreSQL WAL can be +> used. Results are printed in microseconds. Size and quanity of writes are +> configurable. The documentation is in the code (how to configure, build, run, +> etc.). I realize that this program doesn't reflect all of the possible +> activities of a production database system, but I hope it's a step in the +> right direction for this task. I've used it to see differences in behavior +> between the various sync'ing methods on various platforms. +> +> Here's what I've found running the benchmark on some systems to which +> I have access. The differences in behavior between platforms is quite vast. +> +> Summary first... +> +> +> PostgreSQL should be run on an old Apple MacIntosh attached to +> its own Hitachi disk array with 2GB cache or so. Use any sync method +> except for fsync(). +> +> +> Anyway, there is *a lot* of variance in file synching behavior across +> different hardware and O/S platforms. It's probably not safe +> to conclude much. That said, here are some findings so far based on +> tests I've run: +> +> 1. under no circumstances do fsync() or fdatasync() seem to perform +> better than opening files with O_SYNC or O_DSYNC +> 2. where there are differences, opening files with O_SYNC or O_DSYNC +> tends to be quite faster. +> 3. fsync() seems to be the slowest where there are differences. And +> O_DSYNC seems to be the fastest where results differ. +> 4. the safest thing to assert at this point is that +> Solaris systems ought to use the O_DSYNC method for WAL. +> +> ----------- +> +> Test system(s) +> +> Athlon Linux: +> AMD Athlon XP2000, 512MB RAM, single (54 or 7200?) RPM 20GB IDE disk, +> reiserfs filesystem (3 something I think) +> SuSE Linux kernel 2.4.21-99 +> +> Mac Linux: +> I don't know the specific model. 400MHz G3, 512MB, single IDE disk, +> ext2 filesystem +> Debian GNU/Linux 2.4.16-powerpc +> +> HP Intel Linux: +> Prolient HPDL380G3, 2 x 3GHz Xeon, 2GB RAM, SmartArray 5i 64MB cache, +> 2 x 15,000RPM 36GB U320 SCSI drives mirrored. I'm not sure if +> writes are cached or not. There's no battery backup. +> ext3 filesystem. +> Redhat Enterprise Linux 3.0 kernel based on 2.4.21 +> +> Dell Intel OpenBSD: +> Poweredge ?, single 1GHz PIII, 128MB RAM, single 7200RPM 80GB IDE disk, +> ffs filesystem +> OpenBSD 3.2 GENERIC kernel +> +> SUN Ultra2: +> Ultra2, 2 x 296MHz UltraSPARC II, 2GB RAM, 2 x 10,000RPM 18GB U160 +> SCSI drives mirrored with Solstice DiskSuite. UFS filesystem. +> Solaris 8. +> +> SUN E4500 + HDS Thunder 9570v +> E4500, 8 x 400MHz UltraSPARC II, 3GB RAM, +> HDS Thunder 9570v, 2GB mirrored battery-backed cache, RAID5 with a +> bunch of 146GB 10,000RPM FC drives. LUN is on single 2GB FC fabric +> connection. +> Veritas filesystem (VxFS) +> Solaris 8. +> +> Test methodology: +> +> All test runs were done with CHUNKSIZE 8 * 1024, CHUNKS 2 * 1024, +> FILESIZE_MULTIPLIER 2, and SLEEP 5. So a total of 16MB was sequentially +> written for each benchmark. +> +> Results are in microseconds. +> +> PLATFORM: Athlon Linux +> buffered: 48220 +> fsync: 74854397 +> fdatasync: 75061357 +> open_sync: 73869239 +> open_datasync: 74748145 +> Notes: System mostly idle. Even during tests, top showed about 95% +> idle. Something's not right on this box. All sync methods similarly +> horrible on this system. +> +> PLATFORM: Mac Linux +> buffered: 58912 +> fsync: 1539079 +> fdatasync: 769058 +> open_sync: 767094 +> open_datasync: 763074 +> Notes: system mostly idle. fsync seems worst. Otherwise, they seem +> pretty equivalent. This is the fastest system tested. +> +> PLATFORM: HP Intel Linux +> buffered: 33026 +> fsync: 29330067 +> fdatasync: 28673880 +> open_sync: 8783417 +> open_datasync: 8747971 +> Notes: system idle. O_SYNC and O_DSYNC methods seem to be a lot +> better on this platform than fsync & fdatasync. +> +> PLATFORM: Dell Intel OpenBSD +> buffered: 511890 +> fsync: 1769190 +> fdatasync: -------- +> open_sync: 1748764 +> open_datasync: 1747433 +> Notes: system idle. I couldn't locate fdatasync() on this box, so I +> couldn't test it. All sync methods seem equivalent and are very fast -- +> though still trail the old Mac. +> +> PLATFORM: SUN Ultra2 +> buffered: 1814824 +> fsync: 73954800 +> fdatasync: 52594532 +> open_sync: 34405585 +> open_datasync: 13883758 +> Notes: system mostly idle, with occasional spikes from 1-10% utilization. +> It looks like substantial difference between each sync method, with +> O_DSYNC the best and fsync() the worst. There is substantial +> difference between the open* and f* methods. +> +> PLATFORM: SUN E4500 + HDS Thunder 9570v +> buffered: 233947 +> fsync: 57802065 +> fdatasync: 56631013 +> open_sync: 2362207 +> open_datasync: 1976057 +> Notes: host about 30% idle, but the array tested on was completely idle. +> Something looks seriously not right about fsync and fdatasync -- write +> cache seems to have no effect on them. As for write cache, that +> probably explains the 2 seconds or so for the open_sync and +> open_datasync methods. +> +> -------------- +> +> Thanks for reading...I look forward to feedback, and hope to be helpful in +> this effort! +> +> Mark +> + +[ Attachment, skipping... ] + +> +> ---------------------------(end of broadcast)--------------------------- +> TIP 5: Have you checked our extensive FAQ? +> +> http://www.postgresql.org/docs/faqs/FAQ.html + +-- + Bruce Momjian | http://candle.pha.pa.us + pgman@candle.pha.pa.us | (610) 359-1001 + + If your life is a hard drive, | 13 Roberts Road + + Christ can be your backup. | Newtown Square, Pennsylvania 19073 + +From pgsql-performance-owner@postgresql.org Tue Sep 14 05:24:48 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id F30B3329E45 + for ; + Mon, 13 Sep 2004 17:54:40 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 57388-10 + for ; + Mon, 13 Sep 2004 16:54:36 +0000 (GMT) +Received: from hub.org (hub.org [200.46.204.220]) + by svr1.postgresql.org (Postfix) with ESMTP id CA2B4329E68 + for ; + Mon, 13 Sep 2004 17:54:35 +0100 (BST) +Received: from localhost (unknown [200.46.204.144]) + by hub.org (Postfix) with ESMTP id 1755748FE2D + for ; + Mon, 13 Sep 2004 13:54:35 -0300 (ADT) +Received: from hub.org ([200.46.204.220]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 56420-09 for ; + Mon, 13 Sep 2004 16:54:30 +0000 (GMT) +Received: from ganymede.hub.org (blk-222-46-91.eastlink.ca [24.222.46.91]) + by hub.org (Postfix) with ESMTP id DF97848FE2C + for ; + Mon, 13 Sep 2004 13:54:29 -0300 (ADT) +Received: by ganymede.hub.org (Postfix, from userid 1000) + id 0B3BF3B522; Mon, 13 Sep 2004 13:54:30 -0300 (ADT) +Received: from localhost (localhost [127.0.0.1]) + by ganymede.hub.org (Postfix) with ESMTP id 0A7533B512 + for ; + Mon, 13 Sep 2004 13:54:30 -0300 (ADT) +X-Return-Path: +X-Received: from localhost ([unix socket]) + by ganymede.hub.org (Cyrus v2.2.8) with LMTPA; + Mon, 13 Sep 2004 13:30:35 -0300 +X-Sieve: CMU Sieve 2.2 +X-Received: from localhost (localhost.hub.org [127.0.0.1]) + by ganymede.hub.org (Postfix) with ESMTP id 36B7B3B383 + for ; Mon, 13 Sep 2004 13:30:31 -0300 (ADT) +X-Received: from mail.postgresql.org [200.46.204.71] + by localhost with IMAP (fetchmail-6.2.5) + for scrappy@localhost (single-drop); + Mon, 13 Sep 2004 13:30:31 -0300 (ADT) +X-Received: from svr1.postgresql.org ([unix socket]) + by svr1.postgresql.org (Cyrus v2.2.8) with LMTPA; + Mon, 13 Sep 2004 17:27:40 +0100 +X-Sieve: CMU Sieve 2.2 +X-Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 23FD4329E6C + for ; Mon, 13 Sep 2004 17:27:40 +0100 (BST) +X-Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 47887-04 for ; + Mon, 13 Sep 2004 16:27:35 +0000 (GMT) +X-Received: from math.uchicago.edu (math.uchicago.edu [128.135.72.38]) + by svr1.postgresql.org (Postfix) with ESMTP id 5D0FD329C70 + for ; + Mon, 13 Sep 2004 17:27:34 +0100 (BST) +X-Received: from math.uchicago.edu (localhost [127.0.0.1]) + by math.uchicago.edu (8.12.10/8.12.10) with ESMTP id i8DGRMlS008880 + for ; Mon, 13 Sep 2004 11:27:33 -0500 +X-Received: from localhost (bill@localhost) + by math.uchicago.edu (8.12.10/8.12.10/Submit) with ESMTP id + i8DFml0V024785 + for ; Mon, 13 Sep 2004 10:48:47 -0500 +Date: Mon, 13 Sep 2004 10:48:46 -0500 (CDT) +From: Bill Fefferman +To: psql-performance@postgresql.org +Subject: tblspace +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=ISO-8859-1 +Content-Transfer-Encoding: 8BIT +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-DCC: : +X-Spam-Pyzor: +ReSent-Date: Mon, 13 Sep 2004 13:54:24 -0300 (ADT) +Resent-From: "Marc G. Fournier" +Resent-To: pgsql-performance@postgresql.org +ReSent-Subject: tblspace +ReSent-Message-ID: <20040913135424.K1081@ganymede.hub.org> +X-Virus-Scanned: by amavisd-new at hub.org +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/106 +X-Sequence-Number: 8234 + +Hi, I have downloaded the new postgresql (version 8.0 beta2) and I was +wondering what performance features I can take advantage of before I start +to dump my 3/4 terrabyte database into the new database. More +specifically +I am interested in tablespaces--what exactly is this feature, some sort of +organizational addition (?) and how can I best take advantage of this....? +Anything else? Furthermore, if I compile from source will I be able to +revert to using the packaged version of postgresql 8.0 stable later on +without modifying the database(I use debian)�.? + +Thanks. + + +From pgsql-performance-owner@postgresql.org Mon Sep 13 20:32:56 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 1BE14329DC4 + for ; + Mon, 13 Sep 2004 20:32:51 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 11778-04 + for ; + Mon, 13 Sep 2004 19:32:45 +0000 (GMT) +Received: from mail0.rawbw.com (mail0.rawbw.com [198.144.192.41]) + by svr1.postgresql.org (Postfix) with ESMTP id B5B8A329D86 + for ; + Mon, 13 Sep 2004 20:32:45 +0100 (BST) +Received: (from www@localhost) + by mail0.rawbw.com (8.11.6p2/8.11.6) id i8DJWiL11647 + for pgsql-performance@postgresql.org; + Mon, 13 Sep 2004 12:32:44 -0700 (PDT) +Received: from cybs-gw.ic3.com (cybs-gw.ic3.com [66.185.177.10]) + by webmail.rawbw.com (IMP) with HTTP + for ; Mon, 13 Sep 2004 12:32:44 -0700 +Message-ID: <1095103964.4145f5dc3ea48@webmail.rawbw.com> +Date: Mon, 13 Sep 2004 12:32:44 -0700 +From: mudfoot@rawbw.com +To: pgsql-performance@postgresql.org +Subject: Re: Determine optimal fdatasync/fsync, O_SYNC/O_DSYNC options +References: <200409131438.i8DEc8r04384@candle.pha.pa.us> +In-Reply-To: <200409131438.i8DEc8r04384@candle.pha.pa.us> +MIME-Version: 1.0 +Content-Type: text/plain; charset=ISO-8859-1 +Content-Transfer-Encoding: 8bit +User-Agent: Internet Messaging Program (IMP) 3.2.1 +X-Originating-IP: 66.185.177.10 +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.3 tagged_above=0.0 required=5.0 tests=NO_REAL_NAME +X-Spam-Level: +X-Archive-Number: 200409/90 +X-Sequence-Number: 8218 + +Quoting Bruce Momjian : + +> +> Have you seen /src/tools/fsync? +> + +I have now. Thanks. + +From pgsql-performance-owner@postgresql.org Mon Sep 13 21:36:49 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 112FA329E01 + for ; + Mon, 13 Sep 2004 21:36:48 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 33467-09 + for ; + Mon, 13 Sep 2004 20:36:41 +0000 (GMT) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by svr1.postgresql.org (Postfix) with ESMTP id A7C91329C83 + for ; + Mon, 13 Sep 2004 21:36:42 +0100 (BST) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by news.hub.org (8.12.9/8.12.9) with ESMTP id i8DKaeCn036561 + for ; Mon, 13 Sep 2004 20:36:40 GMT + (envelope-from news@news.hub.org) +Received: (from news@localhost) + by news.hub.org (8.12.9/8.12.9/Submit) id i8DKSAgj033605 + for pgsql-performance@postgresql.org; Mon, 13 Sep 2004 20:28:10 GMT +From: Gaetano Mendola +X-Newsgroups: comp.databases.postgresql.performance +Subject: Re: Determine optimal fdatasync/fsync, O_SYNC/O_DSYNC options +Date: Mon, 13 Sep 2004 22:28:05 +0200 +Organization: PYRENET Midi-pyrenees Provider +Lines: 86 +Message-ID: <414602D5.3000506@bigfoot.com> +References: <1095055866.414539fadb90d@webmail.rawbw.com> + <200409131438.i8DEc8r04384@candle.pha.pa.us> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit +X-Complaints-To: abuse@pyrenet.fr +To: Bruce Momjian +User-Agent: Mozilla Thunderbird 0.7.3 (Windows/20040803) +X-Accept-Language: en-us, en +In-Reply-To: <200409131438.i8DEc8r04384@candle.pha.pa.us> +X-Enigmail-Version: 0.85.0.0 +X-Enigmail-Supports: pgp-inline, pgp-mime +To: pgsql-performance@postgresql.org +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/91 +X-Sequence-Number: 8219 + +Bruce Momjian wrote: + +> Have you seen /src/tools/fsync? +> + +Now that the argument is already open, why postgres choose +on linux fdatasync? I'm understanding from other posts that +on this platform open_sync is better than fdatasync. + +However I choose open_sync. During initdb why don't detect +this parameter ? + +Regards +Gaetano Mendola + + + + + +These are my times: + + + +kernel 2.4.9-e.24smp ( RAID SCSI ): + +Simple write timing: + write 0.011544 + +Compare fsync times on write() and non-write() descriptor: +(If the times are similar, fsync() can sync data written + on a different descriptor.) + write, fsync, close 1.233312 + write, close, fsync 1.242086 + +Compare one o_sync write to two: + one 16k o_sync write 0.517633 + two 8k o_sync writes 0.824603 + +Compare file sync methods with one 8k write: + (o_dsync unavailable) + open o_sync, write 0.438580 + write, fdatasync 1.239377 + write, fsync, 1.178017 + +Compare file sync methods with 2 8k writes: + (o_dsync unavailable) + open o_sync, write 0.818720 + write, fdatasync 1.395602 + write, fsync, 1.351214 + + + + +kernel 2.4.22-1.2199.nptlsmp (single EIDE disk): + +Simple write timing: + write 0.023697 + +Compare fsync times on write() and non-write() descriptor: +(If the times are similar, fsync() can sync data written + on a different descriptor.) + write, fsync, close 0.688765 + write, close, fsync 0.702166 + +Compare one o_sync write to two: + one 16k o_sync write 0.498296 + two 8k o_sync writes 0.543956 + +Compare file sync methods with one 8k write: + (o_dsync unavailable) + open o_sync, write 0.259664 + write, fdatasync 0.971712 + write, fsync, 1.006096 + +Compare file sync methods with 2 8k writes: + (o_dsync unavailable) + open o_sync, write 0.536882 + write, fdatasync 1.160347 + write, fsync, 1.189699 + + + + + + + + +From pgsql-performance-owner@postgresql.org Mon Sep 13 22:15:09 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id F1AA0329E75 + for ; + Mon, 13 Sep 2004 22:15:05 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 48563-03 + for ; + Mon, 13 Sep 2004 21:14:59 +0000 (GMT) +Received: from davinci.ethosmedia.com (server226.ethosmedia.com + [209.128.84.226]) + by svr1.postgresql.org (Postfix) with ESMTP id 7768C329E4C + for ; + Mon, 13 Sep 2004 22:14:58 +0100 (BST) +Received: from [64.81.245.111] (account josh@agliodbs.com HELO + temoku.sf.agliodbs.com) + by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.1.8) + with ESMTP id 6346224; Mon, 13 Sep 2004 14:16:18 -0700 +From: Josh Berkus +Reply-To: josh@agliodbs.com +Organization: Aglio Database Solutions +To: Gaetano Mendola +Subject: Re: Determine optimal fdatasync/fsync, O_SYNC/O_DSYNC options +Date: Mon, 13 Sep 2004 14:15:59 -0700 +User-Agent: KMail/1.6.2 +Cc: pgsql-performance@postgresql.org +References: <1095055866.414539fadb90d@webmail.rawbw.com> + <200409131438.i8DEc8r04384@candle.pha.pa.us> + <414602D5.3000506@bigfoot.com> +In-Reply-To: <414602D5.3000506@bigfoot.com> +MIME-Version: 1.0 +Content-Disposition: inline +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +Message-Id: <200409131415.59936.josh@agliodbs.com> +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/92 +X-Sequence-Number: 8220 + +Gaetano, + +> Now that the argument is already open, why postgres choose +> on linux fdatasync? I'm understanding from other posts that +> on this platform open_sync is better than fdatasync. + +Not necessarily. For example, here's my test results, on Linux 2.6.7, +writing to a ReiserFS mount on a Software RAID 1 slave of 2 IDE disks, on an +Athalon 1600mhz single-processor machine. I ran the loop 10,000 times +instead of 1000 because tests with 1,000 varied too much. + +Simple write timing: + write 0.088701 + +Compare fsync times on write() and non-write() descriptor: +(If the times are similar, fsync() can sync data written + on a different descriptor.) + write, fsync, close 3.593958 + write, close, fsync 3.556978 + +Compare one o_sync write to two: + one 16k o_sync write 42.951595 + two 8k o_sync writes 11.251389 + +Compare file sync methods with one 8k write: + (o_dsync unavailable) + open o_sync, write 6.807060 + write, fdatasync 7.207879 + write, fsync, 7.209087 + +Compare file sync methods with 2 8k writes: + (o_dsync unavailable) + open o_sync, write 13.120305 + write, fdatasync 7.583871 + write, fsync, 7.801748 + +-- +--Josh + +Josh Berkus +Aglio Database Solutions +San Francisco + +From pgsql-performance-owner@postgresql.org Mon Sep 13 22:18:40 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 4BE23329D8A + for ; + Mon, 13 Sep 2004 22:18:38 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 49138-10 + for ; + Mon, 13 Sep 2004 21:18:32 +0000 (GMT) +Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) + by svr1.postgresql.org (Postfix) with ESMTP id EE3D3329D69 + for ; + Mon, 13 Sep 2004 22:18:33 +0100 (BST) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i8DLIRwn024309; + Mon, 13 Sep 2004 17:18:27 -0400 (EDT) +To: Gaetano Mendola +Cc: Bruce Momjian , + pgsql-performance@postgresql.org +Subject: Re: Determine optimal fdatasync/fsync, O_SYNC/O_DSYNC options +In-reply-to: <414602D5.3000506@bigfoot.com> +References: <1095055866.414539fadb90d@webmail.rawbw.com> + <200409131438.i8DEc8r04384@candle.pha.pa.us> + <414602D5.3000506@bigfoot.com> +Comments: In-reply-to Gaetano Mendola + message dated "Mon, 13 Sep 2004 22:28:05 +0200" +Date: Mon, 13 Sep 2004 17:18:26 -0400 +Message-ID: <24308.1095110306@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/93 +X-Sequence-Number: 8221 + +Gaetano Mendola writes: +> Now that the argument is already open, why postgres choose +> on linux fdatasync? I'm understanding from other posts that +> on this platform open_sync is better than fdatasync. + +AFAIR, we've seen *one* test from *one* person alleging that. +And it was definitely not that way when we tested the behavior +originally, several releases back. I'd like to see more evidence, +or better some indication that the Linux kernel changed algorithms, +before changing the default. + +The tests that started this thread are pretty unconvincing in my eyes, +because they are comparing open_sync against code that fsyncs after each +one-block write. Under those circumstances, *of course* fsync will lose +(or at least do no better), because it's forcing the same number of +writes through a same-or-less-efficient API. The reason that this isn't +a trivial choice is that Postgres doesn't necessarily need to fsync +after every block of WAL. In particular, when doing large transactions +there could be many blocks written between fsyncs, and in that case you +could come out ahead with fsync because the kernel would have more +freedom to schedule disk writes. + +So, the only test I put a whole lot of faith in is testing your own +workload on your own Postgres server. But if we want to set up a toy +test program to test this stuff, it's at least got to have an easily +adjustable (and preferably randomizable) distance between fsyncs. + +Also, tests on IDE drives have zero credibility to start with, unless +you can convince me you know how to turn off write buffering on the +drive... + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Mon Sep 13 22:50:25 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 54C14329D8C + for ; + Mon, 13 Sep 2004 22:50:18 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 59658-09 + for ; + Mon, 13 Sep 2004 21:50:11 +0000 (GMT) +Received: from cmailm4.svr.pol.co.uk (cmailm4.svr.pol.co.uk [195.92.193.211]) + by svr1.postgresql.org (Postfix) with ESMTP id 6F901329D91 + for ; + Mon, 13 Sep 2004 22:50:12 +0100 (BST) +Received: from modem-1611.llama.dialup.pol.co.uk ([217.135.182.75] + helo=happyplace) by cmailm4.svr.pol.co.uk with smtp (Exim 4.14) + id 1C6yiA-0007cb-Oy; Mon, 13 Sep 2004 22:50:11 +0100 +From: "Simon Riggs" +To: , + "Mark Cotner" +Cc: "Christopher Browne" +Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres -- merge tables +Date: Mon, 13 Sep 2004 23:07:35 +0100 +Message-ID: +MIME-Version: 1.0 +Content-Type: text/plain; + charset="us-ascii" +Content-Transfer-Encoding: 7bit +X-Priority: 3 (Normal) +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) +In-Reply-To: +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 +Importance: Normal +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/94 +X-Sequence-Number: 8222 + + +Mark, + +I thought some additional comments on top of Christopher's excellent notes +might help you. + +> Christopher Browne +> The world rejoiced as Mischa Sandberg +> wrote: +> > Mark Cotner wrote: +> >> Requirements: +> >> Merge table definition equivalent. We use these +> >> extensively. +> +> > Looked all over mysql.com etc, and afaics merge table is indeed +> > exactly a view of a union-all. Is that right? +> + +PostgreSQL's functionality is in many ways similar to Oracle Partitioning. + +Loading up your data in many similar tables, then creating a view like: + +CREATE VIEW BIGTABLE (idate, col1, col2, col3...) AS +SELECT 200409130800, col1, col2, col3... FROM table200409130800 +UNION ALL +SELECT 200409131000, col1, col2, col3... FROM table200409131000 +UNION ALL +SELECT 200409131200, col1, col2, col3... FROM table200409131200 +...etc... + +will allow the PostgreSQL optimizer to eliminate partitions from the query +when you run queries which include a predicate on the partitioning_col, e.g. + +select count(*) from bigtable where idate >= 200409131000 + +will scan the last two partitions only... + +There are a few other ways of creating the view that return the same answer, +but only using constants in that way will allow the partitions to be +eliminated from the query, and so run for much longer. + +So you can give different VIEWS to different user groups, have different +indexes on different tables etc. + +However, I haven't managed to get this technique to work when performing a +star join to a TIME dimension table, since the parition elimination relies +on comparison of constant expressions. You'll need to check out each main +join type to make sure it works for you in your environment. + +> > PG supports views, of course, as well (now) as tablespaces, allowing +> > you to split tables/tablesets across multiple disk systems. PG is +> > also pretty efficient in query plans on such views, where (say) you +> > make one column a constant (identifier, sort of) per input table. +> +> The thing that _doesn't_ work well with these sorts of UNION views are +> when you do self-joins. Supposing you have 10 members, a self-join +> leads to a 100-way join, which is not particularly pretty. +> + +Well, that only happens when you forget to include the partitioning constant +in the self join. + +e.g. select count(*) from bigtable a, bigtable b where a.idate = +.idate; --works just fine + +The optimizer really is smart enough to handle that too, but I'm sure such +large self-joins aren't common for you anyhow. + +> I'm quite curious as to how MySQL(tm) copes with this, although it may +> not be able to take place; they may not support that... +> + +It doesn't, AFAIK. + +> Christopher Browne wrote +> A long time ago, in a galaxy far, far away, mcotner@yahoo.com +> (Mark Cotner) wrote: +> > Agreed, I did some preliminary testing today and am very impressed. +> > I wasn't used to running analyze after a data load, but once I did +> > that everything was snappy. +> +> Something worth observing is that this is true for _any_ of the +> database systems supporting a "cost-based" optimization system, +> including Oracle and DB2. + +Agreed. You can reduce the time for the ANALYZE by ignoring some of the +(measures) columns not used in WHERE clauses. + +Also, if you're sure that each load is very similar to the last, you might +even consider directly updating pg_statistic rows with the statistical +values produced from an earlier ANALYZE...scary, but it can work. + +To create a set of tables of > 600Gb, you will benefit from creating each +table WITHOUT OIDS. + +Hope some of that helps you... + +Best Regards, Simon Riggs + + +From pgsql-performance-owner@postgresql.org Tue Sep 14 01:51:32 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id F139E329C82 + for ; + Tue, 14 Sep 2004 01:51:30 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 24605-05 + for ; + Tue, 14 Sep 2004 00:51:23 +0000 (GMT) +Received: from mproxy.gmail.com (rproxy.gmail.com [64.233.170.197]) + by svr1.postgresql.org (Postfix) with ESMTP id 8424F329E7F + for ; + Tue, 14 Sep 2004 01:51:25 +0100 (BST) +Received: by mproxy.gmail.com with SMTP id v18so449157rnb + for ; + Mon, 13 Sep 2004 17:51:22 -0700 (PDT) +Received: by 10.38.8.74 with SMTP id 74mr1923039rnh; + Mon, 13 Sep 2004 17:51:22 -0700 (PDT) +Received: by 10.38.8.4 with HTTP; Mon, 13 Sep 2004 17:51:22 -0700 (PDT) +Message-ID: <3f71fdf104091317515c756512@mail.gmail.com> +Date: Mon, 13 Sep 2004 19:51:22 -0500 +From: Stephen Crowley +Reply-To: Stephen Crowley +To: pgsql-performance@postgresql.org +Subject: Large # of rows in query extremely slow, not using index +Mime-Version: 1.0 +Content-Type: text/plain; charset=US-ASCII +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/95 +X-Sequence-Number: 8223 + +Does postgres cache the entire result set before it begins returning +data to the client? + +I have a table with ~8 million rows and I am executing a query which +should return about ~800,000 rows. The problem is that as soon as I +execute the query it absolutely kills my machine and begins swapping +for 5 or 6 minutes before it begins returning results. Is postgres +trying to load the whole query into memory before returning anything? +Also, why would it choose not to use the index? It is properly +estimating the # of rows returned. If I set enable_seqscan to off it +is just as slow. + +Running postgres 8.0 beta2 dev2 + +explain select * from island_history where date='2004-09-07' and stock='QQQ'; + QUERY PLAN +--------------------------------------------------------------------------- + Seq Scan on island_history (cost=0.00..266711.23 rows=896150 width=83) + Filter: ((date = '2004-09-07'::date) AND ((stock)::text = 'QQQ'::text)) +(2 rows) + +Any help would be appreciated + +--Stephen + + Table "public.island_history" + Column | Type | Modifiers +------------------+------------------------+----------- + date | date | not null + stock | character varying(6) | + time | time without time zone | not null + reference_number | numeric(9,0) | not null + message_type | character(1) | not null + buy_sell_ind | character(1) | + shares | numeric(6,0) | + remaining_shares | numeric(6,0) | + price | numeric(10,4) | + display | character(1) | + match_number | numeric(9,0) | not null +Indexes: + "island_history_pkey" PRIMARY KEY, btree (date, reference_number, +message_type, "time", match_number) + "island_history_date_stock_time" btree (date, stock, "time") + "island_history_oid" btree (oid) + +From pgsql-performance-owner@postgresql.org Tue Sep 14 02:11:25 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 7F08B329E8D + for ; + Tue, 14 Sep 2004 02:11:22 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 32166-03 + for ; + Tue, 14 Sep 2004 01:11:15 +0000 (GMT) +Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) + by svr1.postgresql.org (Postfix) with ESMTP id 7CB7D329E85 + for ; + Tue, 14 Sep 2004 02:11:16 +0100 (BST) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i8E1B7N1028089; + Mon, 13 Sep 2004 21:11:07 -0400 (EDT) +To: Stephen Crowley +Cc: pgsql-performance@postgresql.org +Subject: Re: Large # of rows in query extremely slow, not using index +In-reply-to: <3f71fdf104091317515c756512@mail.gmail.com> +References: <3f71fdf104091317515c756512@mail.gmail.com> +Comments: In-reply-to Stephen Crowley + message dated "Mon, 13 Sep 2004 19:51:22 -0500" +Date: Mon, 13 Sep 2004 21:11:07 -0400 +Message-ID: <28088.1095124267@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/97 +X-Sequence-Number: 8225 + +Stephen Crowley writes: +> Does postgres cache the entire result set before it begins returning +> data to the client? + +The backend doesn't, but libpq does, and I think JDBC does too. + +I'd recommend using a cursor so you can FETCH a reasonable number of +rows at a time. + +> Also, why would it choose not to use the index? + +Selecting 1/10th of a table is almost always a poor candidate for an +index scan. You've got about 100 rows per page (assuming the planner's +width estimate is credible) and so on average every page of the table +has about ten rows that need to be picked up and returned. You might as +well just seqscan and be sure you don't read any page more than once. + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Tue Sep 14 02:11:22 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 88CF7329E88 + for ; + Tue, 14 Sep 2004 02:11:19 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 31579-06 + for ; + Tue, 14 Sep 2004 01:11:11 +0000 (GMT) +Received: from tht.net (vista.tht.net [216.126.88.2]) + by svr1.postgresql.org (Postfix) with ESMTP id CEBDA329E8E + for ; + Tue, 14 Sep 2004 02:11:13 +0100 (BST) +Received: from [134.22.70.99] (dyn-70-99.tor.dsl.tht.net [134.22.70.99]) + by tht.net (Postfix) with ESMTP + id 5A3D276B25; Mon, 13 Sep 2004 21:11:19 -0400 (EDT) +Subject: Re: Large # of rows in query extremely slow, not using +From: Rod Taylor +To: Stephen Crowley +Cc: Postgresql Performance +In-Reply-To: <3f71fdf104091317515c756512@mail.gmail.com> +References: <3f71fdf104091317515c756512@mail.gmail.com> +Content-Type: multipart/signed; micalg=pgp-sha1; + protocol="application/pgp-signature"; + boundary="=-e+iD4DbyehpoRLK7c36o" +Message-Id: <1095124271.79631.44.camel@jester> +Mime-Version: 1.0 +X-Mailer: Ximian Evolution 1.4.6 +Date: Mon, 13 Sep 2004 21:11:13 -0400 +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/96 +X-Sequence-Number: 8224 + +--=-e+iD4DbyehpoRLK7c36o +Content-Type: text/plain +Content-Transfer-Encoding: quoted-printable + +On Mon, 2004-09-13 at 20:51, Stephen Crowley wrote: +> Does postgres cache the entire result set before it begins returning +> data to the client? + +Sometimes you need to be careful as to how the clients treat the data.=20 + +For example psql will resize columns width on the length (width) of the +data returned. + +PHP and Perl will retrieve and cache all of the rows if you request a +row count ($sth->rows() or pg_num_rows($rset)) + + +You may find that using a cursor will help you out. + +> I have a table with ~8 million rows and I am executing a query which +> should return about ~800,000 rows. The problem is that as soon as I +> execute the query it absolutely kills my machine and begins swapping +> for 5 or 6 minutes before it begins returning results. Is postgres +> trying to load the whole query into memory before returning anything? +> Also, why would it choose not to use the index? It is properly +> estimating the # of rows returned. If I set enable_seqscan to off it +> is just as slow. +>=20 +> Running postgres 8.0 beta2 dev2 +>=20 +> explain select * from island_history where date=3D'2004-09-07' and stock= +=3D'QQQ'; +> QUERY PLAN +> -------------------------------------------------------------------------= +-- +> Seq Scan on island_history (cost=3D0.00..266711.23 rows=3D896150 width= +=3D83) +> Filter: ((date =3D '2004-09-07'::date) AND ((stock)::text =3D 'QQQ'::t= +ext)) +> (2 rows) +>=20 +> Any help would be appreciated +>=20 +> --Stephen +>=20 +> Table "public.island_history" +> Column | Type | Modifiers +> ------------------+------------------------+----------- +> date | date | not null +> stock | character varying(6) | +> time | time without time zone | not null +> reference_number | numeric(9,0) | not null +> message_type | character(1) | not null +> buy_sell_ind | character(1) | +> shares | numeric(6,0) | +> remaining_shares | numeric(6,0) | +> price | numeric(10,4) | +> display | character(1) | +> match_number | numeric(9,0) | not null +> Indexes: +> "island_history_pkey" PRIMARY KEY, btree (date, reference_number, +> message_type, "time", match_number) +> "island_history_date_stock_time" btree (date, stock, "time") +> "island_history_oid" btree (oid) +>=20 +> ---------------------------(end of broadcast)--------------------------- +> TIP 8: explain analyze is your friend +--=20 +Rod Taylor + +Build A Brighter Lamp :: Linux Apache {middleware} PostgreSQL +PGP Key: http://www.rbt.ca/signature.asc + +--=-e+iD4DbyehpoRLK7c36o +Content-Type: application/pgp-signature; name=signature.asc +Content-Description: This is a digitally signed message part + +-----BEGIN PGP SIGNATURE----- +Version: GnuPG v1.2.5 (FreeBSD) + +iD8DBQBBRkUv6DETLow6vwwRAqUzAJ9JLNSP9hV8HBDSF0JUV7Eeowh1EQCfXvT5 +ILK4piXRrr2f+kCkB02CJHE= +=Lddw +-----END PGP SIGNATURE----- + +--=-e+iD4DbyehpoRLK7c36o-- + + +From pgsql-performance-owner@postgresql.org Tue Sep 14 02:22:29 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 0BAC0329E87 + for ; + Tue, 14 Sep 2004 02:22:27 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 33774-08 + for ; + Tue, 14 Sep 2004 01:22:19 +0000 (GMT) +Received: from mproxy.gmail.com (rproxy.gmail.com [64.233.170.193]) + by svr1.postgresql.org (Postfix) with ESMTP id DC19A329E8A + for ; + Tue, 14 Sep 2004 02:22:22 +0100 (BST) +Received: by mproxy.gmail.com with SMTP id 80so129693rnk + for ; + Mon, 13 Sep 2004 18:22:19 -0700 (PDT) +Received: by 10.38.179.63 with SMTP id b63mr498703rnf; + Mon, 13 Sep 2004 18:22:19 -0700 (PDT) +Received: by 10.38.8.4 with HTTP; Mon, 13 Sep 2004 18:22:19 -0700 (PDT) +Message-ID: <3f71fdf104091318228099815@mail.gmail.com> +Date: Mon, 13 Sep 2004 20:22:19 -0500 +From: Stephen Crowley +Reply-To: Stephen Crowley +To: pgsql-performance@postgresql.org +Subject: Re: Large # of rows in query extremely slow, not using index +In-Reply-To: <28088.1095124267@sss.pgh.pa.us> +Mime-Version: 1.0 +Content-Type: text/plain; charset=US-ASCII +Content-Transfer-Encoding: 7bit +References: <3f71fdf104091317515c756512@mail.gmail.com> + <28088.1095124267@sss.pgh.pa.us> +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/98 +X-Sequence-Number: 8226 + +On Mon, 13 Sep 2004 21:11:07 -0400, Tom Lane wrote: +> Stephen Crowley writes: +> > Does postgres cache the entire result set before it begins returning +> > data to the client? +> +> The backend doesn't, but libpq does, and I think JDBC does too. +> +> I'd recommend using a cursor so you can FETCH a reasonable number of +> rows at a time. + +That is incredible. Why would libpq do such a thing? JDBC as well? I +know oracle doesn't do anything like that, not sure about mysql. Is +there any way to turn it off? In this case I was just using psql but +will be using JDBC for the app. About cursors, I thought a jdbc +ResultSet WAS a cursor, am I mistaken? + +Thanks, +Stephen + +From pgsql-performance-owner@postgresql.org Tue Sep 14 02:28:23 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id CAEB4329D28 + for ; + Tue, 14 Sep 2004 02:28:21 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 35065-09 + for ; + Tue, 14 Sep 2004 01:28:14 +0000 (GMT) +Received: from candle.pha.pa.us (candle.pha.pa.us [207.106.42.251]) + by svr1.postgresql.org (Postfix) with ESMTP id A35EF329C82 + for ; + Tue, 14 Sep 2004 02:28:13 +0100 (BST) +Received: (from pgman@localhost) + by candle.pha.pa.us (8.11.6/8.11.6) id i8E1S9i04905; + Mon, 13 Sep 2004 21:28:09 -0400 (EDT) +From: Bruce Momjian +Message-Id: <200409140128.i8E1S9i04905@candle.pha.pa.us> +Subject: Re: Determine optimal fdatasync/fsync, O_SYNC/O_DSYNC options +In-Reply-To: <24308.1095110306@sss.pgh.pa.us> +To: Tom Lane +Date: Mon, 13 Sep 2004 21:28:09 -0400 (EDT) +Cc: Gaetano Mendola , + pgsql-performance@postgresql.org +X-Mailer: ELM [version 2.4ME+ PL108 (25)] +MIME-Version: 1.0 +Content-Transfer-Encoding: 7bit +Content-Type: text/plain; charset=US-ASCII +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/99 +X-Sequence-Number: 8227 + +Tom Lane wrote: +> The tests that started this thread are pretty unconvincing in my eyes, +> because they are comparing open_sync against code that fsyncs after each +> one-block write. Under those circumstances, *of course* fsync will lose +> (or at least do no better), because it's forcing the same number of +> writes through a same-or-less-efficient API. The reason that this isn't +> a trivial choice is that Postgres doesn't necessarily need to fsync +> after every block of WAL. In particular, when doing large transactions +> there could be many blocks written between fsyncs, and in that case you +> could come out ahead with fsync because the kernel would have more +> freedom to schedule disk writes. + +My guess is that the majority of queries do not fill more than one WAL +block. Sure some do, but in those cases the fsync is probably small +compared to the duration of the query. If we had a majority of queries +filling more than one block we would be checkpointing like crazy and we +don't normally get reports about that. + +-- + Bruce Momjian | http://candle.pha.pa.us + pgman@candle.pha.pa.us | (610) 359-1001 + + If your life is a hard drive, | 13 Roberts Road + + Christ can be your backup. | Newtown Square, Pennsylvania 19073 + +From pgsql-performance-owner@postgresql.org Tue Sep 14 02:39:59 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 16BD6329D15 + for ; + Tue, 14 Sep 2004 02:39:56 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 36528-10 + for ; + Tue, 14 Sep 2004 01:39:47 +0000 (GMT) +Received: from pns.mm.eutelsat.org (pns.mm.eutelsat.org [194.214.173.227]) + by svr1.postgresql.org (Postfix) with ESMTP id 9839F329D69 + for ; + Tue, 14 Sep 2004 02:39:49 +0100 (BST) +Received: from nts-03.mm.eutelsat.org (localhost [127.0.0.1]) + by pns.mm.eutelsat.org (8.11.6/linuxconf) with ESMTP id i8E1cVe02547; + Tue, 14 Sep 2004 03:38:33 +0200 +Received: from [127.0.0.1] (accesspoint.mm.eutelsat.org [194.214.173.4]) + by nts-03.mm.eutelsat.org (8.11.6/linuxconf) with ESMTP id i8E1diV20869; + Tue, 14 Sep 2004 03:39:44 +0200 +Message-ID: <41464BD7.808@bigfoot.com> +Date: Tue, 14 Sep 2004 03:39:35 +0200 +From: Gaetano Mendola +User-Agent: Mozilla Thunderbird 0.7.3 (Windows/20040803) +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: Tom Lane +Cc: Bruce Momjian , + pgsql-performance@postgresql.org +Subject: Re: Determine optimal fdatasync/fsync, O_SYNC/O_DSYNC options +References: <1095055866.414539fadb90d@webmail.rawbw.com> + <200409131438.i8DEc8r04384@candle.pha.pa.us> + <414602D5.3000506@bigfoot.com> <24308.1095110306@sss.pgh.pa.us> +In-Reply-To: <24308.1095110306@sss.pgh.pa.us> +X-Enigmail-Version: 0.85.0.0 +X-Enigmail-Supports: pgp-inline, pgp-mime +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/100 +X-Sequence-Number: 8228 + +-----BEGIN PGP SIGNED MESSAGE----- +Hash: SHA1 + +Tom Lane wrote: + +| Gaetano Mendola writes: +| +|>Now that the argument is already open, why postgres choose +|>on linux fdatasync? I'm understanding from other posts that +|>on this platform open_sync is better than fdatasync. +| +| +| AFAIR, we've seen *one* test from *one* person alleging that. +| And it was definitely not that way when we tested the behavior +| originally, several releases back. I'd like to see more evidence, +| or better some indication that the Linux kernel changed algorithms, +| before changing the default. + +I remember more then one person claim that open_sync *apparently* +was working better then fdatasync, however I trust you ( here is +3:00 AM ). + + +| The tests that started this thread are pretty unconvincing in my eyes, +| because they are comparing open_sync against code that fsyncs after each +| one-block write. Under those circumstances, *of course* fsync will lose +| (or at least do no better), because it's forcing the same number of +| writes through a same-or-less-efficient API. +| +| The reason that this isn't a trivial choice is that Postgres doesn't +| necessarily need to fsync after every block of WAL. In particular, +| when doing large transactions there could be many blocks written between +| fsyncs, and in that case you could come out ahead with fsync because the +| kernel would have more freedom to schedule disk writes. + +Are you suggesting that postgres shall use more the one sync method and use +one or the other depending on the activity is performing ? + +| So, the only test I put a whole lot of faith in is testing your own +| workload on your own Postgres server. But if we want to set up a toy +| test program to test this stuff, it's at least got to have an easily +| adjustable (and preferably randomizable) distance between fsyncs. +| +| Also, tests on IDE drives have zero credibility to start with, unless +| you can convince me you know how to turn off write buffering on the +| drive... + +I reported the IDE times just for info; however my SAN works better +with open_sync. Can we trust on numbers given by tools/fsync ? I seen +some your objections in the past but I don't know if there was some fix +from that time. + + +Regards +Gaetano Mendola + + + + + + + + + +-----BEGIN PGP SIGNATURE----- +Version: GnuPG v1.2.4 (MingW32) +Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org + +iD8DBQFBRkvW7UpzwH2SGd4RAia1AKD2L5JLhpRNvBzPq9Lv5bAfFJvRmwCffjC5 +hg7V0Sfm2At7yR1C+gBCzPE= +=RsSy +-----END PGP SIGNATURE----- + + +From pgsql-performance-owner@postgresql.org Tue Sep 14 02:49:25 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 1FBEC329D3E + for ; + Tue, 14 Sep 2004 02:49:23 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 39161-09 + for ; + Tue, 14 Sep 2004 01:49:15 +0000 (GMT) +Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) + by svr1.postgresql.org (Postfix) with ESMTP id 0B8BE329D15 + for ; + Tue, 14 Sep 2004 02:49:18 +0100 (BST) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i8E1nE4T028433; + Mon, 13 Sep 2004 21:49:15 -0400 (EDT) +To: Stephen Crowley +Cc: pgsql-performance@postgresql.org +Subject: Re: Large # of rows in query extremely slow, not using index +In-reply-to: <3f71fdf104091318228099815@mail.gmail.com> +References: <3f71fdf104091317515c756512@mail.gmail.com> + <28088.1095124267@sss.pgh.pa.us> + <3f71fdf104091318228099815@mail.gmail.com> +Comments: In-reply-to Stephen Crowley + message dated "Mon, 13 Sep 2004 20:22:19 -0500" +Date: Mon, 13 Sep 2004 21:49:14 -0400 +Message-ID: <28432.1095126554@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/101 +X-Sequence-Number: 8229 + +Stephen Crowley writes: +> On Mon, 13 Sep 2004 21:11:07 -0400, Tom Lane wrote: +>> Stephen Crowley writes: +>>> Does postgres cache the entire result set before it begins returning +>>> data to the client? +>> +>> The backend doesn't, but libpq does, and I think JDBC does too. + +> That is incredible. Why would libpq do such a thing? + +Because the API it presents doesn't allow for the possibility of query +failure after having given you back a PGresult: either you have the +whole result available with no further worries, or you don't. +If you think it's "incredible", let's see you design an equally +easy-to-use API that doesn't make this assumption. + +(Now having said that, I would have no objection to someone extending +libpq to offer an alternative streaming API for query results. It +hasn't got to the top of anyone's to-do list though ... and I'm +unconvinced that psql could use it if it did exist.) + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Tue Sep 14 03:01:12 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 4EE51329D03 + for ; + Tue, 14 Sep 2004 03:01:09 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 45372-01 + for ; + Tue, 14 Sep 2004 02:01:01 +0000 (GMT) +Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) + by svr1.postgresql.org (Postfix) with ESMTP id E5164329D2A + for ; + Tue, 14 Sep 2004 03:01:04 +0100 (BST) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i8E210XG028519; + Mon, 13 Sep 2004 22:01:00 -0400 (EDT) +To: Bruce Momjian +Cc: Gaetano Mendola , + pgsql-performance@postgresql.org +Subject: Re: Determine optimal fdatasync/fsync, O_SYNC/O_DSYNC options +In-reply-to: <200409140128.i8E1S9i04905@candle.pha.pa.us> +References: <200409140128.i8E1S9i04905@candle.pha.pa.us> +Comments: In-reply-to Bruce Momjian + message dated "Mon, 13 Sep 2004 21:28:09 -0400" +Date: Mon, 13 Sep 2004 22:00:59 -0400 +Message-ID: <28518.1095127259@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/102 +X-Sequence-Number: 8230 + +Bruce Momjian writes: +> If we had a majority of queries filling more than one block we would +> be checkpointing like crazy and we don't normally get reports about +> that. + +[ raised eyebrow... ] And of course the 30-second-checkpoint-warning +stuff is a useless feature that no one ever exercises. + +But your logic doesn't hold up anyway. People may be doing large +transactions without necessarily doing them back-to-back-to-back; +there could be idle time in between. For instance, I'd think an average +transaction size of 100 blocks would be more than enough to make fsync a +winner. There are 2K blocks per WAL segment, so 20 of these would fit +in a segment. With the default WAL parameters you could do sixty such +transactions per five minutes, or one every five seconds, without even +causing more-frequent-than-default checkpoints; and you could do two a +second without setting off the checkpoint-warning alarm. The lack of +checkpoint complaints doesn't prove that this isn't a common real-world +load. + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Tue Sep 14 05:52:29 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 72DBD329DC4 + for ; + Tue, 14 Sep 2004 05:52:28 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 83883-04 + for ; + Tue, 14 Sep 2004 04:52:22 +0000 (GMT) +Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) + by svr1.postgresql.org (Postfix) with ESMTP id 15239329D5A + for ; + Tue, 14 Sep 2004 05:52:22 +0100 (BST) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i8E4qL0l002334; + Tue, 14 Sep 2004 00:52:21 -0400 (EDT) +To: bill@uchicago.edu +Cc: pgsql-performance@postgresql.org +Subject: Re: tblspaces integrated in new postgresql (version 8.0) +In-reply-to: <3129.64.81.139.18.1095039306.squirrel@maladroit.uchicago.edu> +References: <3129.64.81.139.18.1095039306.squirrel@maladroit.uchicago.edu> +Comments: In-reply-to bill@uchicago.edu + message dated "Sun, 12 Sep 2004 20:35:06 -0500" +Date: Tue, 14 Sep 2004 00:52:21 -0400 +Message-ID: <2333.1095137541@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/108 +X-Sequence-Number: 8236 + +bill@uchicago.edu writes: +> I am interested in tablespaces--what exactly is this feature, some sort of +> organizational addition (?) and howcan I best take advantage of this....? + +See +http://developer.postgresql.org/docs/postgres/manage-ag-tablespaces.html + +It doesn't talk a lot yet about *why* you'd want to use this ... + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Tue Sep 14 05:58:04 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 53073329DC4 + for ; + Tue, 14 Sep 2004 05:58:04 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 86210-02 + for ; + Tue, 14 Sep 2004 04:57:58 +0000 (GMT) +Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) + by svr1.postgresql.org (Postfix) with ESMTP id 2ACBC329C70 + for ; + Tue, 14 Sep 2004 05:57:59 +0100 (BST) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i8E4vpjk002396; + Tue, 14 Sep 2004 00:57:51 -0400 (EDT) +To: Vijay Moses +Cc: pgsql-performance@postgresql.org +Subject: Re: Four table join with million records - performance improvement? +In-reply-to: <17b0d951040912213055195d56@mail.gmail.com> +References: <17b0d951040912213055195d56@mail.gmail.com> +Comments: In-reply-to Vijay Moses + message dated "Mon, 13 Sep 2004 10:00:41 +0530" +Date: Tue, 14 Sep 2004 00:57:51 -0400 +Message-ID: <2395.1095137871@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/109 +X-Sequence-Number: 8237 + +Vijay Moses writes: +> Hi i have four sample tables ename, esal, edoj and esum +> All of them have 1000000 records. Im running the following +> query : select ename.eid, name, sal, doj, summary from +> ename,esal,edoj,esum where ename.eid=esal.eid and ename.eid=edoj.eid +> and ename.eid=esum.eid. Its a join of all four tables which returns +> all 1 million records. The eid field in ename is a Primary Key and the +> eid in all other tables are Foreign Keys. I have created an index for +> all Foreign Keys. This query takes around 16 MINUTES to complete. Can +> this time be reduced? + +The indexes will be completely useless for that sort of query; the +reasonable choices are sort/merge or hashjoin. For either one, your +best way to speed it up is to increase sort_mem. + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Tue Sep 14 07:04:42 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id BB388329E44 + for ; + Tue, 14 Sep 2004 07:04:40 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 03519-05 + for ; + Tue, 14 Sep 2004 06:04:34 +0000 (GMT) +Received: from mproxy.gmail.com (rproxy.gmail.com [64.233.170.195]) + by svr1.postgresql.org (Postfix) with ESMTP id 35803329E4C + for ; + Tue, 14 Sep 2004 07:04:34 +0100 (BST) +Received: by mproxy.gmail.com with SMTP id v18so490595rnb + for ; + Mon, 13 Sep 2004 23:04:33 -0700 (PDT) +Received: by 10.38.8.74 with SMTP id 74mr2063333rnh; + Mon, 13 Sep 2004 23:04:33 -0700 (PDT) +Received: by 10.38.8.4 with HTTP; Mon, 13 Sep 2004 23:04:33 -0700 (PDT) +Message-ID: <3f71fdf104091323047de7bb01@mail.gmail.com> +Date: Tue, 14 Sep 2004 01:04:33 -0500 +From: Stephen Crowley +Reply-To: Stephen Crowley +To: pgsql-performance@postgresql.org +Subject: Re: Large # of rows in query extremely slow, not using index +In-Reply-To: <28432.1095126554@sss.pgh.pa.us> +Mime-Version: 1.0 +Content-Type: text/plain; charset=US-ASCII +Content-Transfer-Encoding: 7bit +References: <3f71fdf104091317515c756512@mail.gmail.com> + <28088.1095124267@sss.pgh.pa.us> + <3f71fdf104091318228099815@mail.gmail.com> + <28432.1095126554@sss.pgh.pa.us> +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/110 +X-Sequence-Number: 8238 + +Problem solved.. I set the fetchSize to a reasonable value instead of +the default of unlimited in the PreparedStatement and now the query +is . After some searching it seeems this is a common problem, would it +make sense to change the default value to something other than 0 in +the JDBC driver? + +If I get some extra time I'll look into libpq and see what is required +to fix the API. Most thirdparty programs and existing JDBC apps won't +work with the current paradigm when returning large result sets. + +Thanks, +Stephen + + + +On Mon, 13 Sep 2004 21:49:14 -0400, Tom Lane wrote: +> Stephen Crowley writes: +> > On Mon, 13 Sep 2004 21:11:07 -0400, Tom Lane wrote: +> >> Stephen Crowley writes: +> >>> Does postgres cache the entire result set before it begins returning +> >>> data to the client? +> >> +> >> The backend doesn't, but libpq does, and I think JDBC does too. +> +> > That is incredible. Why would libpq do such a thing? +> +> Because the API it presents doesn't allow for the possibility of query +> failure after having given you back a PGresult: either you have the +> whole result available with no further worries, or you don't. +> If you think it's "incredible", let's see you design an equally +> easy-to-use API that doesn't make this assumption. +> +> (Now having said that, I would have no objection to someone extending +> libpq to offer an alternative streaming API for query results. It +> hasn't got to the top of anyone's to-do list though ... and I'm +> unconvinced that psql could use it if it did exist.) + +From pgsql-performance-owner@postgresql.org Tue Sep 14 08:39:54 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 27503329E12 + for ; + Tue, 14 Sep 2004 08:39:53 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 34691-01 + for ; + Tue, 14 Sep 2004 07:39:45 +0000 (GMT) +Received: from web41502.mail.yahoo.com (web41502.mail.yahoo.com + [66.218.93.85]) + by svr1.postgresql.org (Postfix) with SMTP id 1C7A6329D86 + for ; + Tue, 14 Sep 2004 08:39:44 +0100 (BST) +Message-ID: <20040914073943.95193.qmail@web41502.mail.yahoo.com> +Received: from [67.33.169.246] by web41502.mail.yahoo.com via HTTP; + Tue, 14 Sep 2004 00:39:43 PDT +Date: Tue, 14 Sep 2004 00:39:43 -0700 (PDT) +From: Mark Cotner +Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres -- merge tables +To: Christopher Browne , + pgsql-performance@postgresql.org +In-Reply-To: +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/111 +X-Sequence-Number: 8239 + +You all have been so very helpful so far and I really +appreciate it. + +The data in these tables is thankfully static since +they are logging tables and an analyze only takes +about 4 minutes for the largest of them. + +I've finished porting the schema and am importing the +data now. My estimates for just two-thirds(60 of the +90 days) of one of our 30 cable systems(MySQL dbs) is +estimated to take about 16 hours. This may seem like +a lot, but I'm satisfied with the performance. I've +created a slightly normalized version and some stored +procedures to help me normalize the data. When this +finishes I'm going to query the data as is with the +views as you suggested, and I'm going to create views +for the normalized version to test that as well. This +will then be contrasted to the MySQL query results and +I plan to write a white paper of my findings. + +I don't have any concerns that Postgres will do fine, +but if I run into any performance problems I'll be +sure and post them here first. + +It should be noted that our development life cycle is +currently severely hindered by lack of features in +MySQL like views and stored procedures. Frankly I've +implemented some pretty ugly SQL using as many as 5 +temp tables to generate a result set with MySQL. +Having stored procedures and views is going to help us +tremendously. This performance evaluation is to +verify that Postgres can handle what we're going to +throw at it, not to find out if it's faster in +milliseconds than MySQL. We love the speed and ease +of maintenance with MySQL, but have simply outgrown +it. This will be reflected in the white paper. + +I have already imported our customer tables, which +aren't too small(2.4M rows x 3 tables), and stuck a +view in front of it. The view queried faster than +MySQL would query a pre-joined flat table. + +Getting carried away . . . needless to say I'm really +excited about the possiblity of Postgres, but I won't +bore you with the details just yet. I'll send the +link out to the white paper so you all can review it +before I send it anywhere else. If anything could +have been optimized more please let me know and I'll +see that it gets updated before it's widely published. + +Thanks again for all the great feedback! + +'njoy, +Mark + +--- Christopher Browne wrote: + +> A long time ago, in a galaxy far, far away, +> mcotner@yahoo.com (Mark Cotner) wrote: +> > Agreed, I did some preliminary testing today and +> am very impressed. +> > I wasn't used to running analyze after a data +> load, but once I did +> > that everything was snappy. +> +> Something worth observing is that this is true for +> _any_ of the +> database systems supporting a "cost-based" +> optimization system, +> including Oracle and DB2. +> +> When working with SAP R/3 Payroll, on one project, +> we found that when +> the system was empty of data, the first few employee +> creates were +> quick enough, but it almost immediately got +> excruciatingly slow. One +> of the DBAs told the Oracle instance underneath to +> collect statistics +> on the main table, and things _immediately_ got +> snappy again. But it +> didn't get snappy until the conversion folk had run +> the conversion +> process for several minutes, to the point to which +> it would get +> painfully slow :-(. There, with MILLIONS of dollars +> worth of license +> fees being paid, across the various vendors, it +> still took a fair bit +> of manual fiddling. +> +> MySQL(tm) is just starting to get into cost-based +> optimization; in +> that area, they're moving from where the "big DBs" +> were about 10 years +> ago. It was either version 7 or 8 where Oracle +> started moving to +> cost-based optimization, and (as with the anecdote +> above) it took a +> release or two for people to get accustomed to the +> need to 'feed' the +> optimizer with statistics. This is a "growing pain" +> that bites users +> with any database where this optimization gets +> introduced. It's +> worthwhile, but is certainly not costless. +> +> I expect some forseeable surprises will be +> forthcoming for MySQL AB's +> customers in this regard... +> +> > My best results from MySQL bulk inserts was around +> 36k rows per +> > second on a fairly wide table. Today I got 42k +> using the COPY +> > command, but with the analyze post insert the +> results were similar. +> > These are excellent numbers. It basically means +> we could have our +> > cake(great features) and eat it too(performance +> that's good enough +> > to run the app). +> +> In the end, performance for inserts is always +> fundamentally based on +> how much disk I/O there is, and so it should come as +> no shock that +> when roughly the same amount of data is getting laid +> down on disk, +> performance won't differ much on these sorts of +> essentials. +> +> There are a few places where there's some need for +> cleverness; if you +> see particular queries running unusually slowly, +> it's worth doing an +> EXPLAIN or EXPLAIN ANALYZE on them, to see how the +> query plans are +> being generated. There's some collected wisdom out +> here on how to +> encourage the right plans. +> +> There are also unexpected results that are OK. We +> did a system +> upgrade a few days ago that led to one of the tables +> starting out +> totally empty. A summary report that looks at that +> table wound up +> with a pretty wacky looking query plan (compared to +> what's usual) +> because the postmaster knew that the query would be +> reading in +> essentially the entire table. You'd normally expect +> an index scan, +> looking for data for particular dates. In this +> case, it did a "scan +> the whole table; filter out a few irrelevant +> entries" plan. +> +> It looked wacky, compared to what's usual, but it +> ran in about 2 +> seconds, which was way FASTER than what's usual. So +> the plan was +> exactly the right one. +> +> Telling the difference between the right plan and a +> poor one is a bit +> of an art; we quite regularly take a look at query +> plans on this list +> to figure out what might be not quite right. If you +> find slow ones, +> make sure you have run ANALYZE on the tables +> recently, to be sure that +> the plans are sane, and you may want to consider +> posting some of them +> to see if others can point to improvements that can +> be made. +> -- +> If this was helpful, +> rate me +> +http://linuxfinances.info/info/linuxdistributions.html +> "I can't believe my room doesn't have Ethernet! Why +> wasn't it wired +> when the house was built?" +> "The house was built in 1576." +> -- Alex Kamilewicz on the Oxford breed of +> `conference American.' +> +> ---------------------------(end of +> broadcast)--------------------------- +> TIP 7: don't forget to increase your free space map +> settings +> + + +From pgsql-performance-owner@postgresql.org Tue Sep 14 10:06:59 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 2058A329D69 + for ; + Tue, 14 Sep 2004 10:06:59 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 61878-05 + for ; + Tue, 14 Sep 2004 09:06:55 +0000 (GMT) +Received: from boutiquenumerique.com (gailleton-2-82-67-9-10.fbx.proxad.net + [82.67.9.10]) + by svr1.postgresql.org (Postfix) with ESMTP id 9EBA6329D20 + for ; + Tue, 14 Sep 2004 10:06:55 +0100 (BST) +Received: (qmail 18204 invoked from network); 14 Sep 2004 11:07:02 +0200 +Received: from unknown (HELO musicbox) (192.168.0.2) + by gailleton-2-82-67-9-10.fbx.proxad.net with SMTP; + 14 Sep 2004 11:07:02 +0200 +To: pgsql-performance@postgresql.org +Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres -- merge tables +References: <20040914073943.95193.qmail@web41502.mail.yahoo.com> +Message-ID: +Date: Tue, 14 Sep 2004 11:07:59 +0200 +From: =?iso-8859-15?Q?Pierre-Fr=E9d=E9ric_Caillaud?= + +Organization: =?iso-8859-15?Q?La_Boutique_Num=E9rique?= +Content-Type: text/plain; format=flowed; delsp=yes; charset=iso-8859-15 +MIME-Version: 1.0 +Content-Transfer-Encoding: 8bit +In-Reply-To: <20040914073943.95193.qmail@web41502.mail.yahoo.com> +User-Agent: Opera M2/7.53 (Linux, build 737) +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/112 +X-Sequence-Number: 8240 + + + + Performance hint : + + For static data, do not normalize too much. + For instance if you have a row which can be linked to several other rows, +you can do this : + +create table parents ( + id serial primary key, + values... ) + +create table children ( + id serial primary key, + parent_id references parents(id), + integer slave_value ) + + + Or you can do this, using an array : + +create table everything ( + id serial primary key, + integer[] children_values, + values... ) + + Pros : + No Joins. Getting the list of chilndren_values from table everything is +just a select. + On an application with several million rows, a query lasting 150 ms with +a Join takes 30 ms with an array. + You can build the arrays from normalized tables by using an aggregate +function. + You can index the array elements with a GIST index... + + Cons : + No joins, thus your queries are a little bit limited ; problems if the +array is too long ; + + + + + +From pgsql-performance-owner@postgresql.org Tue Sep 14 13:15:09 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id A4F80329CD2 + for ; + Tue, 14 Sep 2004 13:15:08 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 28412-06 + for ; + Tue, 14 Sep 2004 12:14:56 +0000 (GMT) +Received: from mail.logi-track.com (www.logi-track.com [213.239.193.212]) + by svr1.postgresql.org (Postfix) with ESMTP id 587E2329C65 + for ; + Tue, 14 Sep 2004 13:14:58 +0100 (BST) +Received: from kingfisher.intern.logi-track.com (G6863.g.pppool.de + [80.185.104.99]) + by mail.logi-track.com (Postfix) with ESMTP id CE523305A3; + Tue, 14 Sep 2004 14:14:57 +0200 (CEST) +Received: from kingfisher.intern.logi-track.com (localhost [127.0.0.1]) + by kingfisher.intern.logi-track.com (Postfix) with SMTP id 04A1EAB306; + Tue, 14 Sep 2004 14:14:53 +0200 (CEST) +Date: Tue, 14 Sep 2004 14:14:52 +0200 +From: Markus Schaber +To: PostgreSQL Performance List +Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres -- +Message-ID: <20040914141452.002e5d4e@kingfisher.intern.logi-track.com> +In-Reply-To: +References: <20040912042442.49915.qmail@web41508.mail.yahoo.com> + +Organization: logi-track ag, =?ISO-8859-15?Q?z=FCrich?= +X-Mailer: Sylpheed-Claws 0.9.12a (GTK+ 1.2.10; i386-pc-linux-gnu) +X-Face: Nx5T&>Nj$VrVPv}sC3IL&)TqHHOKCz/|)R$i"*r@w0{*I6w; + UNU_hdl1J4NI_m{IMztq=>cmM}1gCLbAF+9\#CGkG8}Y{x%SuQ>1#t:; + Z(|\qdd[i]HStki~#w1$TPF}:0w-7"S\Ev|_a$K wrote: + +> On the other hand, if you do warehouse-style loading (Insert, or PG=20 +> COPY, into a temp table; and then 'upsert' into the perm table), I can=20 +> guarantee 2500 inserts/sec is no problem. + +As we can forsee that we'll have similar insert rates to cope with in +the not-so-far future, what do you mean with 'upsert'? Do you mean a +stored procedure that iterates over the temp table? + +Generally, what is the fastest way for doing bulk processing of=20 +update-if-primary-key-matches-and-insert-otherwise operations? + +Thanks, +Markus Schaber + +--=20 +markus schaber | dipl. informatiker +logi-track ag | rennweg 14-16 | ch 8001 z=FCrich +phone +41-43-888 62 52 | fax +41-43-888 62 53 +mailto:schabios@logi-track.com | www.logi-track.com + +From pgsql-performance-owner@postgresql.org Tue Sep 14 13:43:07 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 2E558329C65 + for ; + Tue, 14 Sep 2004 13:43:06 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 38361-05 + for ; + Tue, 14 Sep 2004 12:42:54 +0000 (GMT) +Received: from usbb-lacimss1.unisys.com (usbb-lacimss1.unisys.com + [192.63.108.51]) + by svr1.postgresql.org (Postfix) with ESMTP id 0BD7B329E8B + for ; + Tue, 14 Sep 2004 13:42:55 +0100 (BST) +Received: from usbb-lacgw2.lac.uis.unisys.com ([129.226.160.22]unverified) by + usbb-lacimss1 with InterScan Messaging Security Suite; + Tue, 14 Sep 2004 08:45:17 -0400 +Received: from usbb-lacgw2.lac.uis.unisys.com ([129.226.160.25]) by + usbb-lacgw2.lac.uis.unisys.com with Microsoft SMTPSVC(6.0.3790.47); + Tue, 14 Sep 2004 08:42:52 -0400 +Received: from gbmk-eugw2.eu.uis.unisys.com ([129.221.133.27]) by + usbb-lacgw2.lac.uis.unisys.com with Microsoft SMTPSVC(6.0.3790.47); + Tue, 14 Sep 2004 08:42:52 -0400 +Received: from nlshl-exch1.eu.uis.unisys.com ([192.39.239.20]) by + gbmk-eugw2.eu.uis.unisys.com with Microsoft SMTPSVC(6.0.3790.47); + Tue, 14 Sep 2004 13:42:41 +0100 +X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0 +Content-class: urn:content-classes:message +MIME-Version: 1.0 +Content-Type: text/plain; + charset="ISO-8859-15" +Content-Transfer-Encoding: quoted-printable +Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres -- +Date: Tue, 14 Sep 2004 14:42:20 +0200 +Message-ID: + +X-MS-Has-Attach: +X-MS-TNEF-Correlator: +Thread-Topic: [PERFORM] Data Warehouse Reevaluation - MySQL vs Postgres -- +Thread-Index: AcSaVKWDrhYhjh7MT/WuINY6FfknwwAAuZLA +From: "Leeuw van der, Tim" +To: "Markus Schaber" , + "PostgreSQL Performance List" +X-OriginalArrivalTime: 14 Sep 2004 12:42:41.0655 (UTC) + FILETIME=[532E2870:01C49A58] +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/114 +X-Sequence-Number: 8242 + +Hi, + +I found bulk-insert to perform very slow, when compared to MySQL / Oracle. = +All inserts were done in 1 transaction. However, mitigating factors here we= +re: +- Application was a .Net application using ODBC drivers +- PostgreSQL 7.3 running on CYGWIN with cygipc daemon +- Probably very bad tuning in the config file, if any tuning done at all +- The application was issuing 'generic' SQL since it was generally used wit= +h Oracle and MySQL databases. So no tricks like using COPY or multiple rows= + with 1 INSERT statement. No stored procedures either. +- When doing queries, most of the time the results were comparable to or be= +tter than MySQL (the only other database that I tested with myself). + + +So what I can say is, that if you want fast INSERT performance from Postgre= +SQL then you'll probably have to do some trickery that you wouldn't have to= + do with a default MySQL installation. + +regards, + +--Tim + + +-----Original Message----- +From: pgsql-performance-owner@postgresql.org [mailto:pgsql-performance-owne= +r@postgresql.org]On Behalf Of Markus Schaber +Sent: Tuesday, September 14, 2004 2:15 PM +To: PostgreSQL Performance List +Subject: Re: [PERFORM] Data Warehouse Reevaluation - MySQL vs Postgres -- + + +Hi, Mischa, + +On Sun, 12 Sep 2004 20:47:17 GMT +Mischa Sandberg wrote: + +> On the other hand, if you do warehouse-style loading (Insert, or PG=20 +> COPY, into a temp table; and then 'upsert' into the perm table), I can=20 +> guarantee 2500 inserts/sec is no problem. + +As we can forsee that we'll have similar insert rates to cope with in +the not-so-far future, what do you mean with 'upsert'? Do you mean a +stored procedure that iterates over the temp table? + +Generally, what is the fastest way for doing bulk processing of=20 +update-if-primary-key-matches-and-insert-otherwise operations? + +Thanks, +Markus Schaber + +--=20 +markus schaber | dipl. informatiker +logi-track ag | rennweg 14-16 | ch 8001 z=FCrich +phone +41-43-888 62 52 | fax +41-43-888 62 53 +mailto:schabios@logi-track.com | www.logi-track.com + +---------------------------(end of broadcast)--------------------------- +TIP 4: Don't 'kill -9' the postmaster + +From pgsql-performance-owner@postgresql.org Tue Sep 14 14:28:04 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 7446A329E90 + for ; + Tue, 14 Sep 2004 14:28:03 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 57306-03 + for ; + Tue, 14 Sep 2004 13:27:58 +0000 (GMT) +Received: from hotmail.com (bay18-dav12.bay18.hotmail.com [65.54.187.192]) + by svr1.postgresql.org (Postfix) with ESMTP id 6F67D329E86 + for ; + Tue, 14 Sep 2004 14:28:00 +0100 (BST) +Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; + Tue, 14 Sep 2004 06:24:35 -0700 +Received: from 67.81.98.198 by bay18-dav12.bay18.hotmail.com with DAV; + Tue, 14 Sep 2004 13:24:35 +0000 +X-Originating-IP: [67.81.98.198] +X-Originating-Email: [awerman2@hotmail.com] +X-Sender: awerman2@hotmail.com +From: "Aaron Werman" +To: , + +References: <20040912042442.49915.qmail@web41508.mail.yahoo.com> + +Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres -- merge tables +Date: Tue, 14 Sep 2004 09:24:35 -0400 +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 6.00.2800.1437 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 +Message-ID: +X-OriginalArrivalTime: 14 Sep 2004 13:24:35.0782 (UTC) + FILETIME=[2DB77E60:01C49A5E] +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/115 +X-Sequence-Number: 8243 + +> Mark Cotner wrote: + +> > The time has come to reevaluate/rearchitect an +> > application which I built about 3 years ago. There +> > are no performance concerns with MySQL, but it would +> > benefit greatly from stored procedures, views, etc. +> + +From: "Mischa Sandberg" + +> If your company is currently happy with MySQL, there probably are other +> (nontechnical) reasons to stick with it. I'm impressed that you'd +> consider reconsidering PG. + +I'd like to second Mischa on that issue. In general, if you migrate an +*existing* application from one RDBMS to another, you should expect +performance to decrease significantly. This is always true in a well +performing system even if the replacement technology is more sophisticated. +This is because of several factors. + +Even if you try to develop in totally agnostic generic SQL, you are always +customizing to a feature set, namely the ones in the current system. Any +existing application has had substantial tuning and tweaking, and the new +one is at a disadvantage. Moreover, an existing system is a Skinnerian +reward/punishment system to the developers and DBAs, rewarding or punishing +them for very environment specific choices - resulting in an application, +dbms, OS, and platform that are both explicitly and unconsciously customized +to work together in a particular manner. + +The net effect is a rule of thumb that I use: + +NEVER reimplement an existing system unless the project includes substantial +functional imporovement. + +Every time I've broken that rule, I've found that users expectations, based +on the application they are used to, are locked in. Any place where the new +system is slower, the users are dissatisfied; where it exceeds expectations +it isn't appreciated: the users are used to the old system quirks, and the +improvements only leave them uncomforable since the system "acts +differently". (I've broken the rule on occation for standardization +conversions.) + +My expectation is that pg will not get a fair shake here. If you do it - I'd +like to see the results anyway. + +/Aaron + +From pgsql-performance-owner@postgresql.org Tue Sep 14 14:33:15 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id F1833329E8E + for ; + Tue, 14 Sep 2004 14:33:14 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 58280-07 + for ; + Tue, 14 Sep 2004 13:33:04 +0000 (GMT) +Received: from trofast.sesse.net (trofast.sesse.net [129.241.93.32]) + by svr1.postgresql.org (Postfix) with ESMTP id D48D9329E86 + for ; + Tue, 14 Sep 2004 14:33:06 +0100 (BST) +Received: from sesse by trofast.sesse.net with local (Exim 3.36 #1 (Debian)) + id 1C7DQf-0000eO-00 + for ; Tue, 14 Sep 2004 15:33:05 +0200 +Date: Tue, 14 Sep 2004 15:33:05 +0200 +From: "Steinar H. Gunderson" +To: PostgreSQL Performance List +Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres -- +Message-ID: <20040914133305.GB2118@uio.no> +Mail-Followup-To: PostgreSQL Performance List + +References: + +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: + +X-Operating-System: Linux 2.6.6 on a i686 +User-Agent: Mutt/1.5.6+20040818i +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/116 +X-Sequence-Number: 8244 + +On Tue, Sep 14, 2004 at 02:42:20PM +0200, Leeuw van der, Tim wrote: +> - PostgreSQL 7.3 running on CYGWIN with cygipc daemon + +Isn't this doomed to kill your performance anyhow? + +/* Steinar */ +-- +Homepage: http://www.sesse.net/ + +From pgsql-performance-owner@postgresql.org Tue Sep 14 15:01:54 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 291B3329E86 + for ; + Tue, 14 Sep 2004 15:01:52 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 74395-01 + for ; + Tue, 14 Sep 2004 14:01:38 +0000 (GMT) +Received: from usbb-lacimss1.unisys.com (usbb-lacimss1.unisys.com + [192.63.108.51]) + by svr1.postgresql.org (Postfix) with ESMTP id EAA19329E8B + for ; + Tue, 14 Sep 2004 15:01:40 +0100 (BST) +Received: from usbb-lacgw1.lac.uis.unisys.com ([129.226.160.21]unverified) by + usbb-lacimss1 with InterScan Messaging Security Suite; + Tue, 14 Sep 2004 10:03:45 -0400 +Received: from usbb-lacgw1.lac.uis.unisys.com ([129.226.160.23]) by + usbb-lacgw1.lac.uis.unisys.com with Microsoft SMTPSVC(6.0.3790.0); + Tue, 14 Sep 2004 10:01:18 -0400 +Received: from gbmk-eugw1.eu.uis.unisys.com ([129.221.133.28]) by + usbb-lacgw1.lac.uis.unisys.com with Microsoft SMTPSVC(6.0.3790.0); + Tue, 14 Sep 2004 10:01:18 -0400 +Received: from nlshl-exch1.eu.uis.unisys.com ([192.39.239.20]) by + gbmk-eugw1.eu.uis.unisys.com with Microsoft SMTPSVC(6.0.3790.47); + Tue, 14 Sep 2004 15:01:03 +0100 +X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0 +Content-class: urn:content-classes:message +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: quoted-printable +Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres -- +Date: Tue, 14 Sep 2004 16:00:58 +0200 +Message-ID: + +X-MS-Has-Attach: +X-MS-TNEF-Correlator: +Thread-Topic: [PERFORM] Data Warehouse Reevaluation - MySQL vs Postgres -- +Thread-Index: AcSaYl2a7Cx49F4rR7WvYkqsK/hfkAAAG15g +From: "Leeuw van der, Tim" +To: "Steinar H. Gunderson" , + "PostgreSQL Performance List" +X-OriginalArrivalTime: 14 Sep 2004 14:01:03.0468 (UTC) + FILETIME=[45ADE2C0:01C49A63] +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/117 +X-Sequence-Number: 8245 + + +-----Original Message----- +From: pgsql-performance-owner@postgresql.org [mailto:pgsql-performance-owne= +r@postgresql.org]On Behalf Of Steinar H. Gunderson +Sent: Tuesday, September 14, 2004 3:33 PM +To: PostgreSQL Performance List +Subject: Re: [PERFORM] Data Warehouse Reevaluation - MySQL vs Postgres -- + + +> On Tue, Sep 14, 2004 at 02:42:20PM +0200, Leeuw van der, Tim wrote: +> > - PostgreSQL 7.3 running on CYGWIN with cygipc daemon +>=20 +> Isn't this doomed to kill your performance anyhow? + +Yes and no, therefore I mentioned it explicitly as one of the caveats. When= + doing selects I could get performance very comparable to MySQL, so I don't= + want to blame poor insert-performance on cygwin/cygipc per se. +I'm not working on this app. anymore and don't have a working test-environm= +ent for it anymore so I cannot retest now with more recent versions. + +regards, + +--Tim + +>=20 +> /* Steinar */ +> --=20 +> Homepage: http://www.sesse.net/ + + + +---------------------------(end of broadcast)--------------------------- +TIP 8: explain analyze is your friend + +From pgsql-performance-owner@postgresql.org Tue Sep 14 15:20:39 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 3E2ED329D69 + for ; + Tue, 14 Sep 2004 15:20:38 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 83137-01 + for ; + Tue, 14 Sep 2004 14:20:27 +0000 (GMT) +Received: from main.gmane.org (main.gmane.org [80.91.229.2]) + by svr1.postgresql.org (Postfix) with ESMTP id 6C7C8329E8E + for ; + Tue, 14 Sep 2004 15:20:31 +0100 (BST) +Received: from root by main.gmane.org with local (Exim 3.35 #1 (Debian)) + id 1C7EAZ-0004M1-00 + for ; Tue, 14 Sep 2004 16:20:31 +0200 +Received: from srv.protecting.net ([212.126.218.242]) + by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) + id 1AlnuQ-0007hv-00 + for ; Tue, 14 Sep 2004 16:20:31 +0200 +Received: from hf0722x by srv.protecting.net with local (Gmexim 0.1 (Debian)) + id 1AlnuQ-0007hv-00 + for ; Tue, 14 Sep 2004 16:20:31 +0200 +X-Injected-Via-Gmane: http://gmane.org/ +To: pgsql-performance@postgresql.org +From: Harald Fuchs +Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres -- +Date: 14 Sep 2004 16:15:43 +0200 +Organization: Linux Private Site +Lines: 11 +Message-ID: +References: + +Reply-To: hf0722x@protecting.net +Mime-Version: 1.0 +Content-Type: text/plain; charset=US-ASCII +X-Complaints-To: usenet@sea.gmane.org +X-Gmane-NNTP-Posting-Host: srv.protecting.net +User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/118 +X-Sequence-Number: 8246 + +In article , +"Leeuw van der, Tim" writes: + +> So what I can say is, that if you want fast INSERT performance from +> PostgreSQL then you'll probably have to do some trickery that you +> wouldn't have to do with a default MySQL installation. + +I think the word "INSERT" is superfluous in the above sentence ;-) + +Contrary to MySQL, you can't expect decent PostgreSQL performance on +decent hardware without some tuning. + + +From pgsql-performance-owner@postgresql.org Tue Sep 14 15:24:07 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id B1863329D58 + for ; + Tue, 14 Sep 2004 15:24:06 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 81308-10 + for ; + Tue, 14 Sep 2004 14:23:53 +0000 (GMT) +Received: from mailgate3.cinetic.de (mailgate3.cinetic.de [217.72.192.164]) + by svr1.postgresql.org (Postfix) with ESMTP id DD19F329D3E + for ; + Tue, 14 Sep 2004 15:23:53 +0100 (BST) +Received: from exchange02.int.cinetic.de (exchange02.int.cinetic.de + [10.2.1.12]) + by mailgate3.cinetic.de (8.11.6p2/8.11.2/SuSE Linux 8.11.0-0.4) with + ESMTP id i8EEN4K06232; Tue, 14 Sep 2004 16:23:04 +0200 +Received: from [10.1.8.177] ([10.1.8.177]) by exchange02.int.cinetic.de with + Microsoft SMTPSVC(6.0.3790.0); Tue, 14 Sep 2004 16:23:03 +0200 +Message-ID: <4146FEC6.2040007@webde-ag.de> +Date: Tue, 14 Sep 2004 16:23:02 +0200 +From: Michael Kleiser +Reply-To: mkl@webde-ag.de +Organization: WEB.DE AG +User-Agent: Mozilla/5.0 (X11; U; Linux i686; de-AT; rv:1.7.2) Gecko/20040803 +X-Accept-Language: de, , de-de, de-at, en, en-us +MIME-Version: 1.0 +To: "Leeuw van der, Tim" +Cc: "Steinar H. Gunderson" , + PostgreSQL Performance List +Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres -- +References: + +In-Reply-To: + +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit +X-OriginalArrivalTime: 14 Sep 2004 14:23:03.0587 (UTC) + FILETIME=[58880F30:01C49A66] +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/119 +X-Sequence-Number: 8247 + +What MySQl-table-type did you use? +Was it "MyISAM" which don't supports transactions ? +Yes I read about that bulk-inserts with this table-type are very fast. +In Data Warehouse one often don't need transactions. + + +Leeuw van der, Tim schrieb: +> +> -----Original Message----- +> From: pgsql-performance-owner@postgresql.org +> [mailto:pgsql-performance-owner@postgresql.org]On Behalf Of Steinar H. +> Gunderson +> Sent: Tuesday, September 14, 2004 3:33 PM +> To: PostgreSQL Performance List +> Subject: Re: [PERFORM] Data Warehouse Reevaluation - MySQL vs Postgres -- +> +> +> > On Tue, Sep 14, 2004 at 02:42:20PM +0200, Leeuw van der, Tim wrote: +> > > - PostgreSQL 7.3 running on CYGWIN with cygipc daemon +> > +> > Isn't this doomed to kill your performance anyhow? +> +> Yes and no, therefore I mentioned it explicitly as one of the caveats. +> When doing selects I could get performance very comparable to MySQL, so +> I don't want to blame poor insert-performance on cygwin/cygipc per se. +> I'm not working on this app. anymore and don't have a working +> test-environment for it anymore so I cannot retest now with more recent +> versions. +> +> regards, +> +> --Tim +> +> > +> > /* Steinar */ +> > -- +> > Homepage: http://www.sesse.net/ +> +> +> +> ---------------------------(end of broadcast)--------------------------- +> TIP 8: explain analyze is your friend +> +> ---------------------------(end of broadcast)--------------------------- +> TIP 2: you can get off all lists at once with the unregister command +> (send "unregister YourEmailAddressHere" to majordomo@postgresql.org) +> + +From pgsql-performance-owner@postgresql.org Tue Sep 14 15:32:53 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id D7FF4329DF7 + for ; + Tue, 14 Sep 2004 15:32:51 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 87445-03 + for ; + Tue, 14 Sep 2004 14:32:41 +0000 (GMT) +Received: from relay.snowman.net (relay.snowman.net [66.92.160.56]) + by svr1.postgresql.org (Postfix) with ESMTP id 0DBA8329D9F + for ; + Tue, 14 Sep 2004 15:32:43 +0100 (BST) +Received: from ns.snowman.net (ns.snowman.net [10.10.0.2]) + by relay.snowman.net (8.12.11/8.12.11/Debian-5) with ESMTP id + i8EEWX7D017963; Tue, 14 Sep 2004 10:32:33 -0400 +Received: from ns.snowman.net (localhost [127.0.0.1]) + by ns.snowman.net (8.12.11/8.12.11/Debian-5) with ESMTP id + i8EEX48a019464; Tue, 14 Sep 2004 10:33:04 -0400 +Received: (from sfrost@localhost) + by ns.snowman.net (8.12.11/8.12.11/Debian-5) id i8EEX3Ig019462; + Tue, 14 Sep 2004 10:33:03 -0400 +Date: Tue, 14 Sep 2004 10:33:03 -0400 +From: Stephen Frost +To: Markus Schaber +Cc: PostgreSQL Performance List +Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres -- +Message-ID: <20040914143303.GR21419@ns.snowman.net> +Mail-Followup-To: Markus Schaber , + PostgreSQL Performance List +References: <20040912042442.49915.qmail@web41508.mail.yahoo.com> + + <20040914141452.002e5d4e@kingfisher.intern.logi-track.com> +Mime-Version: 1.0 +Content-Type: multipart/signed; micalg=pgp-sha1; + protocol="application/pgp-signature"; boundary="RF5hBp8jldNhGZp7" +Content-Disposition: inline +In-Reply-To: <20040914141452.002e5d4e@kingfisher.intern.logi-track.com> +X-Editor: Vim http://www.vim.org/ +X-Info: http://www.snowman.net +X-Operating-System: Linux/2.4.24ns.3.0 (i686) +X-Uptime: 10:24:11 up 227 days, 9:25, 9 users, load average: 0.11, 0.26, 0.21 +User-Agent: Mutt/1.5.5.1+cvs20040105i +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/120 +X-Sequence-Number: 8248 + +--RF5hBp8jldNhGZp7 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +Content-Transfer-Encoding: quoted-printable + +* Markus Schaber (schabios@logi-track.com) wrote: +> Generally, what is the fastest way for doing bulk processing of=20 +> update-if-primary-key-matches-and-insert-otherwise operations? + +This is a very good question, and I havn't seen much of an answer to it +yet. I'm curious about the answer myself, actually. In the more recent +SQL specs, from what I understand, this is essentially what the 'MERGE' +command is for. This was recently added and unfortunately is not yet +supported in Postgres. Hopefully it will be added soon. + +Otherwise, what I've done is basically an update followed by an insert +using outer joins. If there's something better, I'd love to hear about +it. The statements looks something like: + +update X + set colA =3D a.colA, + colB =3D a.colB + from Y a + where keyA =3D a.keyA and + keyB =3D a.keyB; + +insert into X + select a.keyA, + a.keyB, + a.colA, + a.colB + from Y a left join X b + using (keyA, keyB) + where b.keyA is NULL and + b.keyB is NULL; + +With the appropriate indexes, this is pretty fast but I think a merge +would be much faster. + + Thanks, + + Stephen + +--RF5hBp8jldNhGZp7 +Content-Type: application/pgp-signature; name="signature.asc" +Content-Description: Digital signature +Content-Disposition: inline + +-----BEGIN PGP SIGNATURE----- +Version: GnuPG v1.2.4 (GNU/Linux) + +iD8DBQFBRwEfrzgMPqB3kigRAo4/AJ9HyzNvLF9BFRzjAs3WEgRy9h1LuACeMQFh +Cl9BjMh9bkPnj53iJVWAIys= +=P65B +-----END PGP SIGNATURE----- + +--RF5hBp8jldNhGZp7-- + +From pgsql-performance-owner@postgresql.org Tue Sep 14 16:17:35 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 52A83329D58 + for ; + Tue, 14 Sep 2004 16:17:31 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 05537-09 + for ; + Tue, 14 Sep 2004 15:17:25 +0000 (GMT) +Received: from pc7.berlin.powerweb.de (pc7.berlin.powerweb.de [62.67.228.13]) + by svr1.postgresql.org (Postfix) with ESMTP id 7F794329CAE + for ; + Tue, 14 Sep 2004 16:17:19 +0100 (BST) +Received: from spock (p50840984.dip0.t-ipconnect.de [80.132.9.132]) + by pc7.berlin.powerweb.de (8.9.3p3/8.9.3) with SMTP id RAA02115 + for ; Tue, 14 Sep 2004 17:17:15 +0200 +Message-ID: <008e01c49a6e$670d2010$6602a8c0@spock> +From: "Harald Lau (Sector-X)" +To: +References: <20040912042442.49915.qmail@web41508.mail.yahoo.com> + + +Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres -- merge tables +Date: Tue, 14 Sep 2004 17:20:43 +0200 +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: quoted-printable +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 6.00.2800.1106 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/121 +X-Sequence-Number: 8249 + +-----BEGIN PGP SIGNED MESSAGE----- +Hash: SHA1 + +> From: "Mischa Sandberg" +>=20 +> > If your company is currently happy with MySQL, there probably are +> > other (nontechnical) reasons to stick with it. I'm impressed that +> > you'd consider reconsidering PG. +>=20 +> I'd like to second Mischa on that issue. + +Though both of you are right from my point of view, I don't think +it's very useful to discuss this item here. + +Having once migrated a MySQL-DB to PG I can confirm, that in fact +chances are good you will be unhappy if you adopt the MySQL +data-model and the SQL 1:1. +As well as PG has to be much more configured and optimized than +MySQL. +As well as the client-application is supposed to be modified to a +certain extend, particularly if you want to take over some -or some +more- business-logic from client to database. + +But, from what Mark stated so far I'm sure he is not going to migrate +his app just for fun, resp. without having considered this. + +> NEVER reimplement an existing system unless the project includes +> substantial functional imporovement. + +or monetary issues +I know one big database that was migrated from Oracle to PG and +another from SQLServer to PG because of licence-costs. Definitely +there are some more. +That applies to MySQL, too; licence policy is somewhat obscure to me, +but under certain circumstances you have to pay + +regards Harald + +-----BEGIN PGP SIGNATURE----- +Version: PGPfreeware 6.5.3 for non-commercial use + +iQA/AwUBQUb+O8JpD/drhCuMEQJCZACgqdJsrWjOwdP779PFaFMjxdgvqkwAoIPc +jPONy6urLRLf3vylVjVlEyci +=3D/1Ka +-----END PGP SIGNATURE----- + + +From pgsql-performance-owner@postgresql.org Tue Sep 14 17:44:05 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 79800329E01 + for ; + Tue, 14 Sep 2004 17:44:04 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 40241-09 + for ; + Tue, 14 Sep 2004 16:44:02 +0000 (GMT) +Received: from mail.logi-track.com (burro.logi-track.com [213.239.193.212]) + by svr1.postgresql.org (Postfix) with ESMTP id D036D329D86 + for ; + Tue, 14 Sep 2004 17:44:01 +0100 (BST) +Received: from kingfisher.intern.logi-track.com (G6863.g.pppool.de + [80.185.104.99]) + by mail.logi-track.com (Postfix) with ESMTP id 82B06305A3; + Tue, 14 Sep 2004 18:44:04 +0200 (CEST) +Received: from kingfisher.intern.logi-track.com (localhost [127.0.0.1]) + by kingfisher.intern.logi-track.com (Postfix) with SMTP id BA621AB31B; + Tue, 14 Sep 2004 18:43:58 +0200 (CEST) +Date: Tue, 14 Sep 2004 18:43:58 +0200 +From: Markus Schaber +To: Stephen Crowley +Cc: pgsql-performance@postgresql.org +Subject: Re: Large # of rows in query extremely slow, not using +Message-ID: <20040914184358.08e271fe@kingfisher.intern.logi-track.com> +In-Reply-To: <3f71fdf104091317515c756512@mail.gmail.com> +References: <3f71fdf104091317515c756512@mail.gmail.com> +Organization: logi-track ag, =?ISO-8859-15?Q?z=FCrich?= +X-Mailer: Sylpheed-Claws 0.9.12a (GTK+ 1.2.10; i386-pc-linux-gnu) +X-Face: Nx5T&>Nj$VrVPv}sC3IL&)TqHHOKCz/|)R$i"*r@w0{*I6w; + UNU_hdl1J4NI_m{IMztq=>cmM}1gCLbAF+9\#CGkG8}Y{x%SuQ>1#t:; + Z(|\qdd[i]HStki~#w1$TPF}:0w-7"S\Ev|_a$K wrote: + +> Does postgres cache the entire result set before it begins returning +> data to the client? +>=20 +> I have a table with ~8 million rows and I am executing a query which +> should return about ~800,000 rows. The problem is that as soon as I +> execute the query it absolutely kills my machine and begins swapping +> for 5 or 6 minutes before it begins returning results. Is postgres +> trying to load the whole query into memory before returning anything? +> Also, why would it choose not to use the index? It is properly +> estimating the # of rows returned. If I set enable_seqscan to off it +> is just as slow. + +As you get about 10% of all rows in the table, the query will hit every +page of the table. + +Maybe it helps to CLUSTER the table using the index on your query +parameters, and then set enable_seqscan to off. + +But beware, that you have to re-CLUSTER after modifications. + +HTH, +Markus + + + +--=20 +markus schaber | dipl. informatiker +logi-track ag | rennweg 14-16 | ch 8001 z=FCrich +phone +41-43-888 62 52 | fax +41-43-888 62 53 +mailto:schabios@logi-track.com | www.logi-track.com + +From pgsql-general-owner@postgresql.org Tue Sep 14 18:29:14 2004 +X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id A26FA329E83 + for ; + Tue, 14 Sep 2004 18:29:11 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 55234-10 + for ; + Tue, 14 Sep 2004 17:29:01 +0000 (GMT) +Received: from lorax.kcilink.com (lorax.kciLink.com [206.112.95.1]) + by svr1.postgresql.org (Postfix) with ESMTP id 909BD329E79 + for ; + Tue, 14 Sep 2004 18:29:01 +0100 (BST) +Received: from localhost (localhost [127.0.0.1]) + by lorax.kcilink.com (Postfix) with ESMTP id DF6D54018 + for ; + Tue, 14 Sep 2004 13:28:59 -0400 (EDT) +Received: from lorax.kcilink.com ([127.0.0.1]) + by localhost (lorax.kcilink.com [127.0.0.1]) (amavisd-new, port 10024) + with LMTP id 41956-07 for ; + Tue, 14 Sep 2004 13:28:59 -0400 (EDT) +Received: by lorax.kcilink.com (Postfix, from userid 8) + id 4856C3FEB; Tue, 14 Sep 2004 13:28:59 -0400 (EDT) +To: pgsql-general@postgresql.org +Path: not-for-mail +From: Vivek Khera +Newsgroups: ml.postgres.general +Subject: Re: disk performance benchmarks +Date: Tue, 14 Sep 2004 13:28:59 -0400 +Organization: Khera Communications, Inc., Rockville, MD +Lines: 29 +Message-ID: +References: +NNTP-Posting-Host: yertle.kcilink.com +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Trace: lorax.kcilink.com 1095182939 76361 65.205.34.180 (14 Sep 2004 + 17:28:59 GMT) +X-Complaints-To: daemon@kciLink.com +NNTP-Posting-Date: Tue, 14 Sep 2004 17:28:59 +0000 (UTC) +User-Agent: Gnus/5.1002 (Gnus v5.10.2) XEmacs/21.4 (Security Through + Obscurity, berkeley-unix) +Cancel-Lock: sha1:FCO1xVPZgX3MKdS0WdmeCZ8Up8U= +X-Virus-Scanned: by amavisd-new at kcilink.com +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/639 +X-Sequence-Number: 65845 + +>>>>> "SW" == Shane Wright writes: + +SW> But, we have now taken the plunge and I'm in a position to do some +SW> benchmarking to actually get some data. Basically I was wondering if +SW> anyone else had any particular recommendations (or requests) about the +SW> most useful kinds of benchmarks to do. + +I did a bunch of benchmarking on a 14 disk SCSI RAID array comparing +RAID 5, 10, and 50. My tests consisted of doing a full restore of a +30Gb database (including indexes) and comparing the times to do the +restore, the time to make the indexes, and the time to vacuum. Then I +ran a bunch of queries. + +It was damn near impossible to pick a 'better' RAID config, so I just +went with RAID5. + +You can find many of my posts on this topic on the list archives from +about august - october of last year. + +Basically, you have to approach it holistically to tune the system: Pg +config parameters, memory, and disk speed are the major factors. + +That and your schema needs to be not idiotic. :-) + +-- +=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +Vivek Khera, Ph.D. Khera Communications, Inc. +Internet: khera@kciLink.com Rockville, MD +1-301-869-4449 x806 +AIM: vivekkhera Y!: vivek_khera http://www.khera.org/~vivek/ + +From pgsql-general-owner@postgresql.org Tue Sep 14 19:12:31 2004 +X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id CE46C329E71 + for ; + Tue, 14 Sep 2004 19:12:29 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 74665-04 + for ; + Tue, 14 Sep 2004 18:12:26 +0000 (GMT) +Received: from gghcwest.com (adsl-64-164-133-219.dsl.snfc21.pacbell.net + [64.164.133.219]) + by svr1.postgresql.org (Postfix) with ESMTP id 4FB8B329CBC + for ; + Tue, 14 Sep 2004 19:12:26 +0100 (BST) +Received: from localhost.localdomain (toonses.gghcwest.com [192.168.168.115]) + by gghcwest.com (8.12.10/8.12.9) with ESMTP id i8EICJst030616; + Tue, 14 Sep 2004 11:12:19 -0700 +Received: from jwb by localhost.localdomain with local (Exim 4.34) + id 1C7HmE-0001Ze-Sp; Tue, 14 Sep 2004 11:11:38 -0700 +Subject: Re: disk performance benchmarks +From: "Jeffrey W. Baker" +To: Vivek Khera +Cc: pgsql-general@postgresql.org +In-Reply-To: +References: + +Content-Type: text/plain +Content-Transfer-Encoding: 7bit +Message-Id: <1095185498.5792.12.camel@localhost.localdomain> +Mime-Version: 1.0 +X-Mailer: Ximian Evolution 1.4.6 +Date: Tue, 14 Sep 2004 11:11:38 -0700 +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/642 +X-Sequence-Number: 65848 + +On Tue, 2004-09-14 at 10:28, Vivek Khera wrote: +> >>>>> "SW" == Shane Wright writes: +> +> SW> But, we have now taken the plunge and I'm in a position to do some +> SW> benchmarking to actually get some data. Basically I was wondering if +> SW> anyone else had any particular recommendations (or requests) about the +> SW> most useful kinds of benchmarks to do. +> +> I did a bunch of benchmarking on a 14 disk SCSI RAID array comparing +> RAID 5, 10, and 50. My tests consisted of doing a full restore of a +> 30Gb database (including indexes) and comparing the times to do the +> restore, the time to make the indexes, and the time to vacuum. Then I +> ran a bunch of queries. +> +> It was damn near impossible to pick a 'better' RAID config, so I just +> went with RAID5. +> +> You can find many of my posts on this topic on the list archives from +> about august - october of last year. +> +> Basically, you have to approach it holistically to tune the system: Pg +> config parameters, memory, and disk speed are the major factors. +> +> That and your schema needs to be not idiotic. :-) + +I've recently bee frustrated by this topic, because it seems like you +can design the hell out of a system, getting everything tuned with micro +and macro benchmarks, but when you put it in production the thing falls +apart. + +Current issue: + +A dual 64-bit Opteron 244 machine with 8GB main memory, two 4-disk RAID5 +arrays (one for database, one for xlogs). PG's config is extremely +generous, and in isolated benchmarks it's very fast. + +But, in reality, performance is abyssmal. There's something about what +PG does inside commits and checkpoints that sends Linux into a catatonic +state. For instance here's a snapshot of vmstat during a parallel heavy +select/insert load: + +procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu---- + r b swpd free buff cache si so bi bo in cs us sy id wa + 3 0 216 13852 39656 7739724 0 0 820 2664 2868 2557 16 2 74 7 + 0 0 216 17580 39656 7736460 0 0 3024 4700 3458 4313 42 6 52 0 + 0 0 216 16428 39676 7737324 0 0 840 4248 3930 4516 0 4 89 8 + 0 1 216 18620 39672 7736920 0 0 7576 516 2738 3347 1 4 55 39 + 0 0 216 14972 39672 7738960 0 0 1992 2532 2509 2288 2 3 93 3 + 0 0 216 13564 39672 7740592 0 0 1640 2656 2581 2066 1 3 97 0 + 0 0 216 12028 39672 7742292 0 0 1688 3576 2072 1626 1 2 96 0 + 0 0 216 18364 39680 7736164 0 0 1804 3372 1836 1379 1 4 96 0 + 0 0 216 16828 39684 7737588 0 0 1432 2756 2256 1720 1 3 94 2 + 0 0 216 15452 39684 7738812 0 0 1188 2184 2384 1830 1 2 97 0 + 0 1 216 15388 39684 7740104 0 0 1336 2628 2490 1974 2 3 94 2 + 6 0 216 15424 39684 7740240 0 0 104 3472 2757 1940 3 2 92 2 + 0 0 216 14784 39700 7741856 0 0 1668 3320 2718 2332 0 3 97 0 + +You can see there's not much progress being made there. In the +presence of a farily pathetic writeout, there's a tiny trickle of disk +reads, userspace isn't making any progress, the kernel isn't busy, and +few processes are in iowait. So what the heck is going on? + +This state of non-progress persists as long as the checkpoint subprocess +is active. I'm sure there's some magic way to improve this but I +haven't found it yet. + +PS this is with Linux 2.6.7. + +Regards, +jwb + +From pgsql-performance-owner@postgresql.org Tue Sep 14 19:19:38 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id DBFCF329DB0 + for ; + Tue, 14 Sep 2004 19:19:36 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 78350-01 + for ; + Tue, 14 Sep 2004 18:19:34 +0000 (GMT) +Received: from lorax.kcilink.com (lorax.kciLink.com [206.112.95.1]) + by svr1.postgresql.org (Postfix) with ESMTP id 55A92329D15 + for ; + Tue, 14 Sep 2004 19:19:34 +0100 (BST) +Received: from localhost (localhost [127.0.0.1]) + by lorax.kcilink.com (Postfix) with ESMTP id 5F39A3F4C + for ; + Tue, 14 Sep 2004 14:19:34 -0400 (EDT) +Received: from lorax.kcilink.com ([127.0.0.1]) + by localhost (lorax.kcilink.com [127.0.0.1]) (amavisd-new, port 10024) + with LMTP id 01597-02-2 for ; + Tue, 14 Sep 2004 14:19:33 -0400 (EDT) +Received: by lorax.kcilink.com (Postfix, from userid 8) + id C91643EEE; Tue, 14 Sep 2004 14:19:33 -0400 (EDT) +To: pgsql-performance@postgresql.org +Path: not-for-mail +From: Vivek Khera +Newsgroups: ml.postgres.performance +Subject: Re: Determine optimal fdatasync/fsync, O_SYNC/O_DSYNC options +Date: Tue, 14 Sep 2004 14:19:33 -0400 +Organization: Khera Communications, Inc., Rockville, MD +Lines: 20 +Message-ID: +References: <200409140128.i8E1S9i04905@candle.pha.pa.us> + <28518.1095127259@sss.pgh.pa.us> +NNTP-Posting-Host: yertle.kcilink.com +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Trace: lorax.kcilink.com 1095185973 93382 65.205.34.180 (14 Sep 2004 + 18:19:33 GMT) +X-Complaints-To: daemon@kciLink.com +NNTP-Posting-Date: Tue, 14 Sep 2004 18:19:33 +0000 (UTC) +User-Agent: Gnus/5.1002 (Gnus v5.10.2) XEmacs/21.4 (Security Through + Obscurity, berkeley-unix) +Cancel-Lock: sha1:X/IYUmE1QbpRaZbfrOCWdbkybpQ= +X-Virus-Scanned: by amavisd-new at kcilink.com +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/123 +X-Sequence-Number: 8251 + +>>>>> "TL" == Tom Lane writes: + +TL> Bruce Momjian writes: +>> If we had a majority of queries filling more than one block we would +>> be checkpointing like crazy and we don't normally get reports about +>> that. + +TL> [ raised eyebrow... ] And of course the 30-second-checkpoint-warning +TL> stuff is a useless feature that no one ever exercises. + +Well, last year about this time I discovered in my testing I was +excessively checkpointing; I found that the error message was +confusing, and Bruce cleaned it up. So at least one person excercised +that feature, namely me. :-) + +-- +=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +Vivek Khera, Ph.D. Khera Communications, Inc. +Internet: khera@kciLink.com Rockville, MD +1-301-869-4449 x806 +AIM: vivekkhera Y!: vivek_khera http://www.khera.org/~vivek/ + +From pgsql-performance-owner@postgresql.org Tue Sep 14 20:32:56 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id A34FB329C63 + for ; + Tue, 14 Sep 2004 20:32:53 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 01129-10 + for ; + Tue, 14 Sep 2004 19:32:43 +0000 (GMT) +Received: from hotmail.com (bay18-f22.bay18.hotmail.com [65.54.187.72]) + by svr1.postgresql.org (Postfix) with ESMTP id A8A90329C67 + for ; + Tue, 14 Sep 2004 20:32:43 +0100 (BST) +Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; + Tue, 14 Sep 2004 11:20:50 -0700 +Received: from 67.81.98.198 by by18fd.bay18.hotmail.msn.com with HTTP; + Tue, 14 Sep 2004 18:20:50 GMT +X-Originating-IP: [67.81.98.198] +X-Originating-Email: [awerman2@hotmail.com] +X-Sender: awerman2@hotmail.com +From: "aaron werman" +To: harald@sector-x.de, pgsql-performance@postgresql.org +Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres -- merge tables +Date: Tue, 14 Sep 2004 14:20:50 -0400 +Mime-Version: 1.0 +Content-Type: text/plain; format=flowed +Message-ID: +X-OriginalArrivalTime: 14 Sep 2004 18:20:50.0923 (UTC) + FILETIME=[9086C3B0:01C49A87] +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/126 +X-Sequence-Number: 8254 + +>From: "Harald Lau (Sector-X)" +... +> > From: "Mischa Sandberg" +> > +> > > If your company is currently happy with MySQL, there probably are +> > > other (nontechnical) reasons to stick with it. I'm impressed that +> > > you'd consider reconsidering PG. +> > +> > I'd like to second Mischa on that issue. +> +>Though both of you are right from my point of view, I don't think +>it's very useful to discuss this item here. +> + +It is kinda windy for the list, but the point is that a big part of +performance is developer expectation and user expectation. I'd hope to lower +expectations before we see an article in eWeek. Perhaps this thread should +move to the advocacy list until the migration needs specific advice. + +_________________________________________________________________ +Get ready for school! Find articles, homework help and more in the Back to +School Guide! http://special.msn.com/network/04backtoschool.armx + + +From pgsql-performance-owner@postgresql.org Tue Sep 14 19:27:58 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 7B4F8329CDD + for ; + Tue, 14 Sep 2004 19:27:56 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 81549-02 + for ; + Tue, 14 Sep 2004 18:27:46 +0000 (GMT) +Received: from lorax.kcilink.com (lorax.kciLink.com [206.112.95.1]) + by svr1.postgresql.org (Postfix) with ESMTP id 827BE329CBC + for ; + Tue, 14 Sep 2004 19:27:47 +0100 (BST) +Received: from localhost (localhost [127.0.0.1]) + by lorax.kcilink.com (Postfix) with ESMTP id 34DC33FF7 + for ; + Tue, 14 Sep 2004 14:27:47 -0400 (EDT) +Received: from lorax.kcilink.com ([127.0.0.1]) + by localhost (lorax.kcilink.com [127.0.0.1]) (amavisd-new, port 10024) + with LMTP id 74149-03-2 for ; + Tue, 14 Sep 2004 14:27:46 -0400 (EDT) +Received: by lorax.kcilink.com (Postfix, from userid 8) + id A16D13FEB; Tue, 14 Sep 2004 14:27:46 -0400 (EDT) +To: pgsql-performance@postgresql.org +Path: not-for-mail +From: Vivek Khera +Newsgroups: ml.postgres.performance +Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres -- merge tables +Date: Tue, 14 Sep 2004 14:27:46 -0400 +Organization: Khera Communications, Inc., Rockville, MD +Lines: 20 +Message-ID: +References: <20040914073943.95193.qmail@web41502.mail.yahoo.com> +NNTP-Posting-Host: yertle.kcilink.com +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Trace: lorax.kcilink.com 1095186466 93382 65.205.34.180 (14 Sep 2004 + 18:27:46 GMT) +X-Complaints-To: daemon@kciLink.com +NNTP-Posting-Date: Tue, 14 Sep 2004 18:27:46 +0000 (UTC) +User-Agent: Gnus/5.1002 (Gnus v5.10.2) XEmacs/21.4 (Security Through + Obscurity, berkeley-unix) +Cancel-Lock: sha1:TU9G2KvbJ31xz0Z32dsg4kQ2QYE= +X-Virus-Scanned: by amavisd-new at kcilink.com +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/124 +X-Sequence-Number: 8252 + +>>>>> "MC" == Mark Cotner writes: + +MC> I've finished porting the schema and am importing the +MC> data now. My estimates for just two-thirds(60 of the +MC> 90 days) of one of our 30 cable systems(MySQL dbs) is +MC> estimated to take about 16 hours. This may seem like +MC> a lot, but I'm satisfied with the performance. I've + +be sure to load your data without indexes defined for your initial +import. + +check your logs to see if increasing checkpoint_segments is +recommended. I found that bumping it up to 50 helped speed up my +data loads (restore from dump) significantly. + +-- +=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +Vivek Khera, Ph.D. Khera Communications, Inc. +Internet: khera@kciLink.com Rockville, MD +1-301-869-4449 x806 +AIM: vivekkhera Y!: vivek_khera http://www.khera.org/~vivek/ + +From pgsql-performance-owner@postgresql.org Tue Sep 14 20:27:01 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 020FE329CDD + for ; + Tue, 14 Sep 2004 20:26:58 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 99529-09 + for ; + Tue, 14 Sep 2004 19:26:48 +0000 (GMT) +Received: from boutiquenumerique.com (gailleton-2-82-67-9-10.fbx.proxad.net + [82.67.9.10]) + by svr1.postgresql.org (Postfix) with ESMTP id 2AADC329C82 + for ; + Tue, 14 Sep 2004 20:26:47 +0100 (BST) +Received: (qmail 7141 invoked from network); 14 Sep 2004 21:26:56 +0200 +Received: from unknown (HELO musicbox) (192.168.0.2) + by gailleton-2-82-67-9-10.fbx.proxad.net with SMTP; + 14 Sep 2004 21:26:56 +0200 +Date: Tue, 14 Sep 2004 21:27:55 +0200 +To: pgsql-performance@postgresql.org +Subject: Re: Large # of rows in query extremely slow, not using +References: <3f71fdf104091317515c756512@mail.gmail.com> + <20040914184358.08e271fe@kingfisher.intern.logi-track.com> +From: =?iso-8859-15?Q?Pierre-Fr=E9d=E9ric_Caillaud?= + +Organization: =?iso-8859-15?Q?La_Boutique_Num=E9rique?= +Content-Type: text/plain; format=flowed; delsp=yes; charset=iso-8859-15 +MIME-Version: 1.0 +Content-Transfer-Encoding: 8bit +Message-ID: +In-Reply-To: <20040914184358.08e271fe@kingfisher.intern.logi-track.com> +User-Agent: Opera M2/7.53 (Linux, build 737) +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/125 +X-Sequence-Number: 8253 + + +>> I have a table with ~8 million rows and I am executing a query which +>> should return about ~800,000 rows. The problem is that as soon as I +>> execute the query it absolutely kills my machine and begins swapping +>> for 5 or 6 minutes before it begins returning results. Is postgres +>> trying to load the whole query into memory before returning anything? +>> Also, why would it choose not to use the index? It is properly +>> estimating the # of rows returned. If I set enable_seqscan to off it +>> is just as slow. + + 1; EXPLAIN ANALYZE. + + Note the time it takes. It should not swap, just read data from the disk +(and not kill the machine). + + 2; Run the query in your software + + Note the time it takes. Watch RAM usage. If it's vastly longer and you're +swimming in virtual memory, postgres is not the culprit... rather use a +cursor to fetch a huge resultset bit by bit. + + Tell us what you find ? + + Regards. + +From pgsql-performance-owner@postgresql.org Tue Sep 14 21:21:31 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 69435329E86 + for ; + Tue, 14 Sep 2004 21:21:30 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 20488-03 + for ; + Tue, 14 Sep 2004 20:21:20 +0000 (GMT) +Received: from cmailm4.svr.pol.co.uk (cmailm4.svr.pol.co.uk [195.92.193.211]) + by svr1.postgresql.org (Postfix) with ESMTP id E3B6C329DB0 + for ; + Tue, 14 Sep 2004 21:21:20 +0100 (BST) +Received: from modem-802.lemur.dialup.pol.co.uk ([217.135.131.34] + helo=happyplace) by cmailm4.svr.pol.co.uk with smtp (Exim 4.14) + id 1C7Jni-0004LC-HB; Tue, 14 Sep 2004 21:21:18 +0100 +From: "Simon Riggs" +To: "Stephen Frost" , + "Markus Schaber" +Cc: "PostgreSQL Performance List" +Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres -- +Date: Tue, 14 Sep 2004 21:38:49 +0100 +Message-ID: +MIME-Version: 1.0 +Content-Type: text/plain; + charset="us-ascii" +Content-Transfer-Encoding: 7bit +X-Priority: 3 (Normal) +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) +In-Reply-To: <20040914143303.GR21419@ns.snowman.net> +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 +Importance: Normal +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/127 +X-Sequence-Number: 8255 + +> Stephen Frost +> * Markus Schaber (schabios@logi-track.com) wrote: +> > Generally, what is the fastest way for doing bulk processing of +> > update-if-primary-key-matches-and-insert-otherwise operations? +> +> This is a very good question, and I havn't seen much of an answer to it +> yet. I'm curious about the answer myself, actually. In the more recent +> SQL specs, from what I understand, this is essentially what the 'MERGE' +> command is for. This was recently added and unfortunately is not yet +> supported in Postgres. Hopefully it will be added soon. +> + +Yes, I think it is an important feature for both Data Warehousing (used in +set-operation mode for bulk processing) and OLTP (saves a round-trip to the +database, so faster on single rows also). It's in my top 10 for 2005. + +Best Regards, Simon Riggs + + + +From pgsql-general-owner@postgresql.org Tue Sep 14 22:45:46 2004 +X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id AAE22329D3B + for ; + Tue, 14 Sep 2004 22:45:44 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 48377-07 + for ; + Tue, 14 Sep 2004 21:45:41 +0000 (GMT) +Received: from flake.decibel.org (flake.decibel.org [66.143.173.58]) + by svr1.postgresql.org (Postfix) with ESMTP id 0BBC9329D2A + for ; + Tue, 14 Sep 2004 22:45:41 +0100 (BST) +Received: by flake.decibel.org (Postfix, from userid 1001) + id F10E61C8B6; Tue, 14 Sep 2004 16:45:40 -0500 (CDT) +Date: Tue, 14 Sep 2004 16:45:40 -0500 +From: "Jim C. Nasby" +To: "Jeffrey W. Baker" +Cc: Vivek Khera , pgsql-general@postgresql.org +Subject: Re: disk performance benchmarks +Message-ID: <20040914214540.GJ56059@decibel.org> +References: + + <1095185498.5792.12.camel@localhost.localdomain> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <1095185498.5792.12.camel@localhost.localdomain> +X-Operating-System: FreeBSD 4.10-RELEASE-p2 i386 +X-Distributed: Join the Effort! http://www.distributed.net +User-Agent: Mutt/1.5.6i +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/656 +X-Sequence-Number: 65862 + +On Tue, Sep 14, 2004 at 11:11:38AM -0700, Jeffrey W. Baker wrote: +> procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu---- +> r b swpd free buff cache si so bi bo in cs us sy id wa +> 3 0 216 13852 39656 7739724 0 0 820 2664 2868 2557 16 2 74 7 +> 0 0 216 17580 39656 7736460 0 0 3024 4700 3458 4313 42 6 52 0 +> 0 0 216 16428 39676 7737324 0 0 840 4248 3930 4516 0 4 89 8 +> 0 1 216 18620 39672 7736920 0 0 7576 516 2738 3347 1 4 55 39 +> 0 0 216 14972 39672 7738960 0 0 1992 2532 2509 2288 2 3 93 3 +> 0 0 216 13564 39672 7740592 0 0 1640 2656 2581 2066 1 3 97 0 +> 0 0 216 12028 39672 7742292 0 0 1688 3576 2072 1626 1 2 96 0 +> 0 0 216 18364 39680 7736164 0 0 1804 3372 1836 1379 1 4 96 0 +> 0 0 216 16828 39684 7737588 0 0 1432 2756 2256 1720 1 3 94 2 +> 0 0 216 15452 39684 7738812 0 0 1188 2184 2384 1830 1 2 97 0 +> 0 1 216 15388 39684 7740104 0 0 1336 2628 2490 1974 2 3 94 2 +> 6 0 216 15424 39684 7740240 0 0 104 3472 2757 1940 3 2 92 2 +> 0 0 216 14784 39700 7741856 0 0 1668 3320 2718 2332 0 3 97 0 +> +> You can see there's not much progress being made there. In the + +Those IO numbers look pretty high for nothing going on. Are you sure +you're not IO bound? +-- +Jim C. Nasby, Database Consultant decibel@decibel.org +Give your computer some brain candy! www.distributed.net Team #1828 + +Windows: "Where do you want to go today?" +Linux: "Where do you want to go tomorrow?" +FreeBSD: "Are you guys coming, or what?" + +From pgsql-performance-owner@postgresql.org Tue Sep 14 23:33:48 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 2E35A329D3B + for ; + Tue, 14 Sep 2004 23:33:45 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 63185-02 + for ; + Tue, 14 Sep 2004 22:33:33 +0000 (GMT) +Received: from flake.decibel.org (flake.decibel.org [66.143.173.58]) + by svr1.postgresql.org (Postfix) with ESMTP id 5CA70329C6B + for ; + Tue, 14 Sep 2004 23:33:34 +0100 (BST) +Received: by flake.decibel.org (Postfix, from userid 1001) + id 4D0E11C8B7; Tue, 14 Sep 2004 17:33:33 -0500 (CDT) +Date: Tue, 14 Sep 2004 17:33:33 -0500 +From: "Jim C. Nasby" +To: Simon Riggs +Cc: pgsql-performance@postgresql.org, Mark Cotner , + Christopher Browne +Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres -- merge tables +Message-ID: <20040914223333.GL56059@decibel.org> +References: + +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: +X-Operating-System: FreeBSD 4.10-RELEASE-p2 i386 +X-Distributed: Join the Effort! http://www.distributed.net +User-Agent: Mutt/1.5.6i +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/128 +X-Sequence-Number: 8256 + +On Mon, Sep 13, 2004 at 11:07:35PM +0100, Simon Riggs wrote: +> PostgreSQL's functionality is in many ways similar to Oracle Partitioning. +> +> Loading up your data in many similar tables, then creating a view like: +> +> CREATE VIEW BIGTABLE (idate, col1, col2, col3...) AS +> SELECT 200409130800, col1, col2, col3... FROM table200409130800 +> UNION ALL +> SELECT 200409131000, col1, col2, col3... FROM table200409131000 +> UNION ALL +> SELECT 200409131200, col1, col2, col3... FROM table200409131200 +> ...etc... +> +> will allow the PostgreSQL optimizer to eliminate partitions from the query +> when you run queries which include a predicate on the partitioning_col, e.g. +> +> select count(*) from bigtable where idate >= 200409131000 +> +> will scan the last two partitions only... +> +> There are a few other ways of creating the view that return the same answer, +> but only using constants in that way will allow the partitions to be +> eliminated from the query, and so run for much longer. + +Is there by any chance a set of functions to manage adding and removing +partitions? Certainly this can be done by hand, but having a set of +tools would make life much easier. I just looked but didn't see anything +on GBorg. +-- +Jim C. Nasby, Database Consultant decibel@decibel.org +Give your computer some brain candy! www.distributed.net Team #1828 + +Windows: "Where do you want to go today?" +Linux: "Where do you want to go tomorrow?" +FreeBSD: "Are you guys coming, or what?" + +From pgsql-general-owner@postgresql.org Tue Sep 14 23:50:10 2004 +X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 73AD8329D2A + for ; + Tue, 14 Sep 2004 23:49:37 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 68186-01 + for ; + Tue, 14 Sep 2004 22:49:33 +0000 (GMT) +Received: from gghcwest.com (adsl-64-164-133-219.dsl.snfc21.pacbell.net + [64.164.133.219]) + by svr1.postgresql.org (Postfix) with ESMTP id 679DC329CDD + for ; + Tue, 14 Sep 2004 23:49:34 +0100 (BST) +Received: from localhost.localdomain (toonses.gghcwest.com [192.168.168.115]) + by gghcwest.com (8.12.10/8.12.9) with ESMTP id i8EMnVst002966 + for ; Tue, 14 Sep 2004 15:49:31 -0700 +Received: from jwb by localhost.localdomain with local (Exim 4.34) + id 1C7M6V-0001tD-B3 + for pgsql-general@postgresql.org; Tue, 14 Sep 2004 15:48:51 -0700 +Subject: Re: disk performance benchmarks +From: "Jeffrey W. Baker" +To: pgsql-general@postgresql.org +In-Reply-To: <20040914214540.GJ56059@decibel.org> +References: + + <1095185498.5792.12.camel@localhost.localdomain> + <20040914214540.GJ56059@decibel.org> +Content-Type: text/plain +Content-Transfer-Encoding: 7bit +Message-Id: <1095202131.7232.2.camel@localhost.localdomain> +Mime-Version: 1.0 +X-Mailer: Ximian Evolution 1.4.6 +Date: Tue, 14 Sep 2004 15:48:51 -0700 +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/659 +X-Sequence-Number: 65865 + +On Tue, 2004-09-14 at 14:45, Jim C. Nasby wrote: +> On Tue, Sep 14, 2004 at 11:11:38AM -0700, Jeffrey W. Baker wrote: +> > procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu---- +> > r b swpd free buff cache si so bi bo in cs us sy id wa +> > 3 0 216 13852 39656 7739724 0 0 820 2664 2868 2557 16 2 74 7 +> > 0 0 216 17580 39656 7736460 0 0 3024 4700 3458 4313 42 6 52 0 +> > 0 0 216 16428 39676 7737324 0 0 840 4248 3930 4516 0 4 89 8 +> > 0 1 216 18620 39672 7736920 0 0 7576 516 2738 3347 1 4 55 39 +> > 0 0 216 14972 39672 7738960 0 0 1992 2532 2509 2288 2 3 93 3 +> > 0 0 216 13564 39672 7740592 0 0 1640 2656 2581 2066 1 3 97 0 +> > 0 0 216 12028 39672 7742292 0 0 1688 3576 2072 1626 1 2 96 0 +> > 0 0 216 18364 39680 7736164 0 0 1804 3372 1836 1379 1 4 96 0 +> > 0 0 216 16828 39684 7737588 0 0 1432 2756 2256 1720 1 3 94 2 +> > 0 0 216 15452 39684 7738812 0 0 1188 2184 2384 1830 1 2 97 0 +> > 0 1 216 15388 39684 7740104 0 0 1336 2628 2490 1974 2 3 94 2 +> > 6 0 216 15424 39684 7740240 0 0 104 3472 2757 1940 3 2 92 2 +> > 0 0 216 14784 39700 7741856 0 0 1668 3320 2718 2332 0 3 97 0 +> > +> > You can see there's not much progress being made there. In the +> +> Those IO numbers look pretty high for nothing going on. Are you sure +> you're not IO bound? + +Just for the list to get an idea of the kinds of performance problems +I'm trying to eliminate, check out these vmstat captures: + +http://saturn5.com/~jwb/pg.html + +Performance is okay-ish for about three minutes at a stretch and then +extremely bad during the fourth minute, and the cycle repeats all day. +During the bad periods everything involving the database just blocks. + +-jwb + +From pgsql-performance-owner@postgresql.org Thu Sep 16 05:20:39 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 38732329EAF + for ; + Wed, 15 Sep 2004 00:07:11 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 70858-07 + for ; + Tue, 14 Sep 2004 23:06:54 +0000 (GMT) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by svr1.postgresql.org (Postfix) with ESMTP id 53604329D8C + for ; + Wed, 15 Sep 2004 00:06:56 +0100 (BST) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by news.hub.org (8.12.9/8.12.9) with ESMTP id i8EN6rCn073501 + for ; Tue, 14 Sep 2004 23:06:53 GMT + (envelope-from news@news.hub.org) +Received: (from news@localhost) + by news.hub.org (8.12.9/8.12.9/Submit) id i8EMwHTC071071 + for pgsql-performance@postgresql.org; Tue, 14 Sep 2004 22:58:17 GMT +From: Mischa Sandberg +Reply-To: ischamay.andbergsay@activestateway.com +User-Agent: Mozilla Thunderbird 0.7.3 (X11/20040803) +X-Accept-Language: en-us, en +MIME-Version: 1.0 +X-Newsgroups: comp.databases.postgresql.performance +Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres -- +References: <20040912042442.49915.qmail@web41508.mail.yahoo.com> + + <20040914141452.002e5d4e@kingfisher.intern.logi-track.com> + <20040914143303.GR21419@ns.snowman.net> +In-Reply-To: <20040914143303.GR21419@ns.snowman.net> +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit +Lines: 58 +Message-ID: +Date: Tue, 14 Sep 2004 22:58:20 GMT +To: pgsql-performance@postgresql.org +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, + hits=1.1 tagged_above=0.0 required=5.0 tests=NO_DNS_FOR_FROM +X-Spam-Level: * +X-Archive-Number: 200409/151 +X-Sequence-Number: 8279 + +Googling 'upsert' (an Oraclism, I believe) will get you hits on Oracle +and DB2's implementation of MERGE, which does what AMOUNTS to what is +described below (one mass UPDATE...FROM, one mass INSERT...WHERE NOT +EXISTS). + +No, you shouldn't iterate row-by-row through the temp table. +Whenever possible, try to do updates in one single (mass) operation. +Doing it that way gives the optimizer the best chance at amortizing +fixed costs, and batching operations. + +--------- +In any database other than Postgres, I would recommend doing the +INSERT /followed by/ the UPDATE. That order looks wonky --- your update +ends up pointlessly operating on the rows just INSERTED. The trick is, +UPDATE acquires and holds write locks (the rows were previously visible +to other processes), while INSERT's write locks refer to rows that no +other process could try to lock. + +Stephen Frost wrote: +> * Markus Schaber (schabios@logi-track.com) wrote: +> +>>Generally, what is the fastest way for doing bulk processing of +>>update-if-primary-key-matches-and-insert-otherwise operations? +> +> +> This is a very good question, and I havn't seen much of an answer to it +> yet. I'm curious about the answer myself, actually. In the more recent +> SQL specs, from what I understand, this is essentially what the 'MERGE' +> command is for. This was recently added and unfortunately is not yet +> supported in Postgres. Hopefully it will be added soon. +> +> Otherwise, what I've done is basically an update followed by an insert +> using outer joins. If there's something better, I'd love to hear about +> it. The statements looks something like: +> +> update X +> set colA = a.colA, +> colB = a.colB +> from Y a +> where keyA = a.keyA and +> keyB = a.keyB; +> +> insert into X +> select a.keyA, +> a.keyB, +> a.colA, +> a.colB +> from Y a left join X b +> using (keyA, keyB) +> where b.keyA is NULL and +> b.keyB is NULL; +> +> With the appropriate indexes, this is pretty fast but I think a merge +> would be much faster. +> +> Thanks, +> +> Stephen + +From pgsql-performance-owner@postgresql.org Wed Sep 15 00:15:05 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 38325329CDD + for ; + Wed, 15 Sep 2004 00:14:58 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 73191-04 + for ; + Tue, 14 Sep 2004 23:14:46 +0000 (GMT) +Received: from cmailm1.svr.pol.co.uk (cmailm1.svr.pol.co.uk [195.92.193.18]) + by svr1.postgresql.org (Postfix) with ESMTP id 2850D329C6B + for ; + Wed, 15 Sep 2004 00:14:47 +0100 (BST) +Received: from modem-3036.leopard.dialup.pol.co.uk ([217.135.155.220] + helo=happyplace) by cmailm1.svr.pol.co.uk with smtp (Exim 4.14) + id 1C7MVa-0007Io-8t; Wed, 15 Sep 2004 00:14:46 +0100 +From: "Simon Riggs" +To: "Jim C. Nasby" +Cc: , "Mark Cotner" , + "Christopher Browne" +Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres -- merge tables +Date: Wed, 15 Sep 2004 00:32:11 +0100 +Message-ID: +MIME-Version: 1.0 +Content-Type: text/plain; + charset="us-ascii" +Content-Transfer-Encoding: 7bit +X-Priority: 3 (Normal) +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) +In-Reply-To: <20040914223333.GL56059@decibel.org> +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 +Importance: Normal +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/129 +X-Sequence-Number: 8257 + +> Jim C. Nasby +> On Mon, Sep 13, 2004 at 11:07:35PM +0100, Simon Riggs wrote: +> > PostgreSQL's functionality is in many ways similar to Oracle +> Partitioning. +> > +> > Loading up your data in many similar tables, then creating a view like: +> > +> > CREATE VIEW BIGTABLE (idate, col1, col2, col3...) AS +> > SELECT 200409130800, col1, col2, col3... FROM table200409130800 +> > UNION ALL +> > SELECT 200409131000, col1, col2, col3... FROM table200409131000 +> > UNION ALL +> > SELECT 200409131200, col1, col2, col3... FROM table200409131200 +> > ...etc... +> > +> > will allow the PostgreSQL optimizer to eliminate partitions +> from the query +> > when you run queries which include a predicate on the +> partitioning_col, e.g. +> > +> > select count(*) from bigtable where idate >= 200409131000 +> > +> > will scan the last two partitions only... +> > +> > There are a few other ways of creating the view that return the +> same answer, +> > but only using constants in that way will allow the partitions to be +> > eliminated from the query, and so run for much longer. +> +> Is there by any chance a set of functions to manage adding and removing +> partitions? Certainly this can be done by hand, but having a set of +> tools would make life much easier. I just looked but didn't see anything +> on GBorg. + +Well, its fairly straightforward to auto-generate the UNION ALL view, and +important as well, since it needs to be re-specified each time a new +partition is loaded or an old one is cleared down. The main point is that +the constant placed in front of each table must in some way relate to the +data, to make it useful in querying. If it is just a unique constant, chosen +at random, it won't do much for partition elimination. So, that tends to +make the creation of the UNION ALL view an application/data specific thing. + +The "partitions" are just tables, so no need for other management tools. +Oracle treats the partitions as sub-tables, so you need a range of commands +to add, swap etc the partitions of the main table. + +I guess a set of tools that emulates that functionality would be generically +a good thing, if you can see a way to do that. + +Oracle partitions were restricted in only allowing a single load statement +into a single partition at any time, whereas multiple COPY statements can +access a single partition table on PostgreSQL. + +BTW, multi-dimensional partitioning is also possible using the same general +scheme.... + +Best Regards, Simon Riggs + + +From pgsql-performance-owner@postgresql.org Thu Sep 16 05:20:39 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 3AE54329EB7 + for ; + Wed, 15 Sep 2004 00:37:11 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 76786-09 + for ; + Tue, 14 Sep 2004 23:36:54 +0000 (GMT) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by svr1.postgresql.org (Postfix) with ESMTP id 4CC4E329EAB + for ; + Wed, 15 Sep 2004 00:36:56 +0100 (BST) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by news.hub.org (8.12.9/8.12.9) with ESMTP id i8ENarCn081111 + for ; Tue, 14 Sep 2004 23:36:53 GMT + (envelope-from news@news.hub.org) +Received: (from news@localhost) + by news.hub.org (8.12.9/8.12.9/Submit) id i8ENWjwD080089 + for pgsql-performance@postgresql.org; Tue, 14 Sep 2004 23:32:45 GMT +From: Mischa Sandberg +Reply-To: ischamay.andbergsay@activestateway.com +User-Agent: Mozilla Thunderbird 0.7.3 (X11/20040803) +X-Accept-Language: en-us, en +MIME-Version: 1.0 +X-Newsgroups: comp.databases.postgresql.performance +Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres -- merge tables +References: <20040914223333.GL56059@decibel.org> + +In-Reply-To: +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit +Lines: 47 +Message-ID: +Date: Tue, 14 Sep 2004 23:32:48 GMT +To: pgsql-performance@postgresql.org +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, + hits=1.1 tagged_above=0.0 required=5.0 tests=NO_DNS_FOR_FROM +X-Spam-Level: * +X-Archive-Number: 200409/152 +X-Sequence-Number: 8280 + +Simon Riggs wrote: +>>Jim C. Nasby +>>On Mon, Sep 13, 2004 at 11:07:35PM +0100, Simon Riggs wrote: +>> +>>>PostgreSQL's functionality is in many ways similar to Oracle +>>Partitioning. +>> +>>>Loading up your data in many similar tables, then creating a view like: +>>> +>>>CREATE VIEW BIGTABLE (idate, col1, col2, col3...) AS +>>>SELECT 200409130800, col1, col2, col3... FROM table200409130800 +>>>UNION ALL +>>>SELECT 200409131000, col1, col2, col3... FROM table200409131000 +>>>UNION ALL +>>>SELECT 200409131200, col1, col2, col3... FROM table200409131200 +>>>...etc... +>>> +>>>will allow the PostgreSQL optimizer to eliminate partitions +>>from the query +>>>when you run queries which include a predicate on the +>>partitioning_col, e.g. +>> +>>>select count(*) from bigtable where idate >= 200409131000 +> +> The "partitions" are just tables, so no need for other management tools. +> Oracle treats the partitions as sub-tables, so you need a range of commands +> to add, swap etc the partitions of the main table. + +A few years ago I wrote a federated query engine (wrapped as an ODBC +driver) that had to handle thousands of contributors (partitions) to a +pseudotable / VIEWofUNIONs. Joins did require some special handling in +the optimizer, because of the huge number of crossproducts between +different tables. It was definitely worth the effort at the time, +because you need different strategies for: joining a partition to +another partition on the same subserver; joining two large partitions on +different servers; and joining a large partition on one server to a +small one on another. + +The differences may not be so great for a solitary server; +but they're still there, because of disparity in subtable sizes. The +simplistic query plans tend to let you down, when you're dealing with +honking warehouses. + +I'm guessing that Oracle keeps per-subtable AND cross-all-subtables +statistics, rather than building the latter from scratch in the course +of evaluating the query plan. That's the one limitation I see in +emulating their partitioned tables with Views. + +From pgsql-performance-owner@postgresql.org Wed Sep 15 02:02:43 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 26D79329D58 + for ; + Wed, 15 Sep 2004 02:02:40 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 01292-02 + for ; + Wed, 15 Sep 2004 01:02:27 +0000 (GMT) +Received: from laughter.local (unknown [61.197.227.146]) + by svr1.postgresql.org (Postfix) with ESMTP id 078EC329CD2 + for ; + Wed, 15 Sep 2004 02:02:29 +0100 (BST) +Received: from [127.0.0.1] (localhost [127.0.0.1]) + by laughter.local (Postfix) with ESMTP + id 3AE132DEBA7; Wed, 15 Sep 2004 10:01:58 +0900 (JST) +In-Reply-To: +References: +Mime-Version: 1.0 (Apple Message framework v619) +Content-Type: text/plain; charset=US-ASCII; format=flowed +Message-Id: +Content-Transfer-Encoding: 7bit +Cc: "Mark Cotner" , "Jim C. Nasby" , + , "Christopher Browne" +From: Michael Glaesemann +Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres -- merge tables +Date: Wed, 15 Sep 2004 10:01:57 +0900 +To: "Simon Riggs" +X-Mailer: Apple Mail (2.619) +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/130 +X-Sequence-Number: 8258 + + +On Sep 15, 2004, at 8:32 AM, Simon Riggs wrote: + +> The "partitions" are just tables, so no need for other management +> tools. +> Oracle treats the partitions as sub-tables, so you need a range of +> commands +> to add, swap etc the partitions of the main table. +> +> I guess a set of tools that emulates that functionality would be +> generically +> a good thing, if you can see a way to do that. +> +> Oracle partitions were restricted in only allowing a single load +> statement +> into a single partition at any time, whereas multiple COPY statements +> can +> access a single partition table on PostgreSQL. + +How does this compare to DB2 partitioning? + +Michael Glaesemann +grzm myrealbox com + + +From pgsql-general-owner@postgresql.org Wed Sep 15 02:52:30 2004 +X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 0A05B329ED7 + for ; + Wed, 15 Sep 2004 02:52:24 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 11286-08 + for ; + Wed, 15 Sep 2004 01:52:18 +0000 (GMT) +Received: from hosting.commandprompt.com (128.commandprompt.com + [207.173.200.128]) + by svr1.postgresql.org (Postfix) with ESMTP id 107A3329E58 + for ; + Wed, 15 Sep 2004 02:52:21 +0100 (BST) +Received: from [192.168.1.20] (clbb-248.saw.net [64.146.135.248]) + (authenticated) + by hosting.commandprompt.com (8.11.6/8.11.6) with ESMTP id i8F1qI722385; + Tue, 14 Sep 2004 18:52:18 -0700 +Message-ID: <41479FA1.1080001@commandprompt.com> +Date: Tue, 14 Sep 2004 18:49:21 -0700 +From: "Joshua D. Drake" +Organization: Command Prompt, Inc. +User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: "Jeffrey W. Baker" +Cc: Vivek Khera , pgsql-general@postgresql.org +Subject: Re: disk performance benchmarks +References: + + <1095185498.5792.12.camel@localhost.localdomain> +In-Reply-To: <1095185498.5792.12.camel@localhost.localdomain> +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/665 +X-Sequence-Number: 65871 + + +>You can see there's not much progress being made there. In the +>presence of a farily pathetic writeout, there's a tiny trickle of disk +>reads, userspace isn't making any progress, the kernel isn't busy, and +>few processes are in iowait. So what the heck is going on? +> +>This state of non-progress persists as long as the checkpoint subprocess +>is active. I'm sure there's some magic way to improve this but I +>haven't found it yet. +> +> +> +Hello, + +It is my experience that RAID 5 is not that great for heavy write +situations and that RAID 10 is better. +Also as you are on linux you may want to take a look at what file system +you are using. EXT3 for example is +known to be stable, if a very slow piggy. + +J + + + + + +>PS this is with Linux 2.6.7. +> +>Regards, +>jwb +> +>---------------------------(end of broadcast)--------------------------- +>TIP 3: if posting/reading through Usenet, please send an appropriate +> subscribe-nomail command to majordomo@postgresql.org so that your +> message can get through to the mailing list cleanly +> +> + + +-- +Command Prompt, Inc., home of Mammoth PostgreSQL - S/ODBC and S/JDBC +Postgresql support, programming shared hosting and dedicated hosting. ++1-503-667-4564 - jd@commandprompt.com - http://www.commandprompt.com +PostgreSQL Replicator -- production quality replication for PostgreSQL + + +From pgsql-general-owner@postgresql.org Wed Sep 15 03:20:50 2004 +X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 4928F329E91 + for ; + Wed, 15 Sep 2004 03:20:37 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 19174-04 + for ; + Wed, 15 Sep 2004 02:20:24 +0000 (GMT) +Received: from yertle.kcilink.com (yertle.kcilink.com [65.205.34.180]) + by svr1.postgresql.org (Postfix) with ESMTP id B7E0B329CDB + for ; + Wed, 15 Sep 2004 03:20:26 +0100 (BST) +Received: from [192.168.0.102] (pcp04418574pcs.nrockv01.md.comcast.net + [69.140.109.242]) + by yertle.kcilink.com (Postfix) with ESMTP id D24022178A + for ; + Tue, 14 Sep 2004 22:20:26 -0400 (EDT) +Mime-Version: 1.0 (Apple Message framework v619) +In-Reply-To: <41479FA1.1080001@commandprompt.com> +References: + + <1095185498.5792.12.camel@localhost.localdomain> + <41479FA1.1080001@commandprompt.com> +Content-Type: multipart/signed; micalg=sha1; boundary=Apple-Mail-1-943506309; + protocol="application/pkcs7-signature" +Message-Id: +From: Vivek Khera +Subject: Re: disk performance benchmarks +Date: Tue, 14 Sep 2004 22:20:23 -0400 +To: pgsql-general@postgresql.org +X-Mailer: Apple Mail (2.619) +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/667 +X-Sequence-Number: 65873 + +--Apple-Mail-1-943506309 +Content-Transfer-Encoding: 7bit +Content-Type: text/plain; + charset=US-ASCII; + format=flowed + + +On Sep 14, 2004, at 9:49 PM, Joshua D. Drake wrote: + +> It is my experience that RAID 5 is not that great for heavy write +> situations and that RAID 10 is better. +> +It is my experience that this depends entirely on how many spindles you +have in your RAID. For 4 or 5 spindles, I find RAID10 faster. With 14 +spindles, it was more or less a toss-up for me. + + +--Apple-Mail-1-943506309 +Content-Transfer-Encoding: base64 +Content-Type: application/pkcs7-signature; + name=smime.p7s +Content-Disposition: attachment; + filename=smime.p7s + +MIAGCSqGSIb3DQEHAqCAMIACAQExCzAJBgUrDgMCGgUAMIAGCSqGSIb3DQEH +AQAAoIIGhzCCAz8wggKooAMCAQICAQ0wDQYJKoZIhvcNAQEFBQAwgdExCzAJ +BgNVBAYTAlpBMRUwEwYDVQQIEwxXZXN0ZXJuIENhcGUxEjAQBgNVBAcTCUNh +cGUgVG93bjEaMBgGA1UEChMRVGhhd3RlIENvbnN1bHRpbmcxKDAmBgNVBAsT +H0NlcnRpZmljYXRpb24gU2VydmljZXMgRGl2aXNpb24xJDAiBgNVBAMTG1Ro +YXd0ZSBQZXJzb25hbCBGcmVlbWFpbCBDQTErMCkGCSqGSIb3DQEJARYccGVy +c29uYWwtZnJlZW1haWxAdGhhd3RlLmNvbTAeFw0wMzA3MTcwMDAwMDBaFw0x +MzA3MTYyMzU5NTlaMGIxCzAJBgNVBAYTAlpBMSUwIwYDVQQKExxUaGF3dGUg +Q29uc3VsdGluZyAoUHR5KSBMdGQuMSwwKgYDVQQDEyNUaGF3dGUgUGVyc29u +YWwgRnJlZW1haWwgSXNzdWluZyBDQTCBnzANBgkqhkiG9w0BAQEFAAOBjQAw +gYkCgYEAxKY8VXNV+065yplaHmjAdQRwnd/p/6Me7L3N9VvyGna9fww6YfK/ +Uc4B1OVQCjDXAmNaLIkVcI7dyfArhVqqP3FWy688Cwfn8R+RNiQqE88r1fOC +dz0Dviv+uxg+B79AgAJk16emu59l0cUqVIUPSAR/p7bRPGEEQB5kGXJgt/sC +AwEAAaOBlDCBkTASBgNVHRMBAf8ECDAGAQH/AgEAMEMGA1UdHwQ8MDowOKA2 +oDSGMmh0dHA6Ly9jcmwudGhhd3RlLmNvbS9UaGF3dGVQZXJzb25hbEZyZWVt +YWlsQ0EuY3JsMAsGA1UdDwQEAwIBBjApBgNVHREEIjAgpB4wHDEaMBgGA1UE +AxMRUHJpdmF0ZUxhYmVsMi0xMzgwDQYJKoZIhvcNAQEFBQADgYEASIzRUIPq +Cy7MDaNmrGcPf6+svsIXoUOWlJ1/TCG4+DYfqi2fNi/A9BxQIJNwPP2t4WFi +w9k6GX6EsZkbAMUaC4J0niVQlGLH2ydxVyWN3amcOY6MIE9lX5Xa9/eH1sYI +Tq726jTlEBpbNU1341YheILcIRk13iSx0x1G/11fZU8wggNAMIICqaADAgEC +AgMMB/4wDQYJKoZIhvcNAQEEBQAwYjELMAkGA1UEBhMCWkExJTAjBgNVBAoT +HFRoYXd0ZSBDb25zdWx0aW5nIChQdHkpIEx0ZC4xLDAqBgNVBAMTI1RoYXd0 +ZSBQZXJzb25hbCBGcmVlbWFpbCBJc3N1aW5nIENBMB4XDTA0MDMzMDIwNDIx +MVoXDTA1MDMzMDIwNDIxMVowgYoxHzAdBgNVBAMTFlRoYXd0ZSBGcmVlbWFp +bCBNZW1iZXIxHjAcBgkqhkiG9w0BCQEWD3ZpdmVrQGtoZXJhLm9yZzEgMB4G +CSqGSIb3DQEJARYRa2hlcmFAa2NpbGluay5jb20xJTAjBgkqhkiG9w0BCQEW +FnZpdmVrQG1haWxlcm1haWxlci5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IB +DwAwggEKAoIBAQDBSjHPUwN+eaM5uwCtKXo+khMQU4oD9GC4XhNNrVzqx2Jg +x/ep985wo5jxHZ2VJ9wKBt6MuKav8Q6H60oMRot3gW3FYPX5k7GkuMIoThjV +0GzixL/utq5OacDiO8dupSH7CT13AxNfNGFSW3Q6O/PaJ0b2pupL7X+EHY3+ +lpzKV8+OMwcRUW71tI3sZghipVuiUeWZhrJQsuuxxZLM7IyGD0uepCQT3hCI +iClpzJTGDygwW7nBPRuXI2tMAU4wFYZG34BH+JVRYKfm4WH99/9IH7Fz55u0 +qNsvPL7FhZakIDA0QjEprv35zbO9uFSu/PY4Yj91Vaih8PtKkLi+rCVnAgMB +AAGjVzBVMEUGA1UdEQQ+MDyBD3ZpdmVrQGtoZXJhLm9yZ4ERa2hlcmFAa2Np +bGluay5jb22BFnZpdmVrQG1haWxlcm1haWxlci5jb20wDAYDVR0TAQH/BAIw +ADANBgkqhkiG9w0BAQQFAAOBgQA696KzrXtGrERiiN3zJBHZxIox5mVn1Bt/ +RL6JO8PRw4CFuFvLI77Vf9yCiduWd+J7ijfhCmEj3m/W9KmWP4XEArbhIBBO +1lBa2lyHd7LUNnhUTzruAbHdyc4e25PpS3TM3YbFX7e+wdrcdZYWZgiYDb1l +x60aJ4MtJ5+msGQeazGCAucwggLjAgEBMGkwYjELMAkGA1UEBhMCWkExJTAj +BgNVBAoTHFRoYXd0ZSBDb25zdWx0aW5nIChQdHkpIEx0ZC4xLDAqBgNVBAMT +I1RoYXd0ZSBQZXJzb25hbCBGcmVlbWFpbCBJc3N1aW5nIENBAgMMB/4wCQYF +Kw4DAhoFAKCCAVMwGAYJKoZIhvcNAQkDMQsGCSqGSIb3DQEHATAcBgkqhkiG +9w0BCQUxDxcNMDQwOTE1MDIyMDIzWjAjBgkqhkiG9w0BCQQxFgQUcZdbVOLi +2jn3uz7+tU6NBRzgTq4weAYJKwYBBAGCNxAEMWswaTBiMQswCQYDVQQGEwJa +QTElMCMGA1UEChMcVGhhd3RlIENvbnN1bHRpbmcgKFB0eSkgTHRkLjEsMCoG +A1UEAxMjVGhhd3RlIFBlcnNvbmFsIEZyZWVtYWlsIElzc3VpbmcgQ0ECAwwH +/jB6BgsqhkiG9w0BCRACCzFroGkwYjELMAkGA1UEBhMCWkExJTAjBgNVBAoT +HFRoYXd0ZSBDb25zdWx0aW5nIChQdHkpIEx0ZC4xLDAqBgNVBAMTI1RoYXd0 +ZSBQZXJzb25hbCBGcmVlbWFpbCBJc3N1aW5nIENBAgMMB/4wDQYJKoZIhvcN +AQEBBQAEggEAkiXJMJo36qNwkN/HVW5Ujm3F8fSzSZt3+dKxTy06ubVMJS71 +foG1mnAFtrlVPdQBF/wjE7ARmeTsLFDvlzU3EMLIPh2Yw0rlhM7+ySj9HlPx +QqUtlXrvD6LfTOx7735T7Tk3XRV2GJeZJf13WGVTqHyYCLr+1mRADdYtbMrP +eM2aau+BIR9ieAU9/bR+/iIjwXyfhH2n4fMQNWEM4m1QF1fihO/nsJswU9hM +wBqXwZCIsYPvtxb4+tS8KGpD3JvjRhuCDwiQynpLkALaBzPelbuVppdej21j +o3S9kym4OWDutt06ohpejp+7rMqVqxOaU/vjyqXmYz8re74SS6UQjAAAAAAA +AA== + +--Apple-Mail-1-943506309-- + + +From pgsql-performance-owner@postgresql.org Wed Sep 15 04:37:35 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id AD903329EC9 + for ; + Wed, 15 Sep 2004 04:37:12 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 40418-01 + for ; + Wed, 15 Sep 2004 03:37:03 +0000 (GMT) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by svr1.postgresql.org (Postfix) with ESMTP id 8F083329E0E + for ; + Wed, 15 Sep 2004 04:37:03 +0100 (BST) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by news.hub.org (8.12.9/8.12.9) with ESMTP id i8F3axCp040972 + for ; Wed, 15 Sep 2004 03:37:02 GMT + (envelope-from news@news.hub.org) +Received: (from news@localhost) + by news.hub.org (8.12.9/8.12.9/Submit) id i8F3A2En034488 + for pgsql-performance@postgresql.org; Wed, 15 Sep 2004 03:10:02 GMT +From: Chris Browne +X-Newsgroups: comp.databases.postgresql.performance +Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres -- merge tables +Date: Tue, 14 Sep 2004 22:34:53 -0400 +Organization: cbbrowne Computing Inc +Lines: 44 +Message-ID: <60k6uw1cqa.fsf@dev6.int.libertyrms.info> +References: <20040914223333.GL56059@decibel.org> + +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Complaints-To: usenet@news.hub.org +User-Agent: Gnus/5.110003 (No Gnus v0.3) XEmacs/21.4 (Security Through + Obscurity, linux) +Cancel-Lock: sha1:xNOHt2irSyfawKIfv8BLb47jKKU= +To: pgsql-performance@postgresql.org +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/132 +X-Sequence-Number: 8260 + +simon@2ndquadrant.com ("Simon Riggs") writes: +> Well, its fairly straightforward to auto-generate the UNION ALL view, and +> important as well, since it needs to be re-specified each time a new +> partition is loaded or an old one is cleared down. The main point is that +> the constant placed in front of each table must in some way relate to the +> data, to make it useful in querying. If it is just a unique constant, chosen +> at random, it won't do much for partition elimination. So, that tends to +> make the creation of the UNION ALL view an application/data specific thing. + +Ah, that's probably a good thought. + +When we used big "UNION ALL" views, it was with logging tables, where +there wasn't really any meaningful distinction between partitions. + +So you say that if the VIEW contains, within it, meaningful constraint +information, that can get applied to chop out irrelevant bits? + +That suggests a way of resurrecting the idea... + +Might we set up the view as: + +create view combination_of_logs as + select * from table_1 where txn_date between 'this' and 'that' + union all + select * from table_2 where txn_date between 'this2' and 'that2' + union all + select * from table_3 where txn_date between 'this3' and 'that3' + union all + select * from table_4 where txn_date between 'this4' and 'that4' + union all + ... ad infinitum + union all + select * from table_n where txn_date > 'start_of_partition_n'; + +and expect that to help, as long as the query that hooks up to this +has date constraints? + +We'd have to regenerate the view with new fixed constants each time we +set up the tables, but that sounds like it could work... +-- +"cbbrowne","@","acm.org" +http://www3.sympatico.ca/cbbrowne/x.html +But what can you do with it? -- ubiquitous cry from Linux-user +partner. -- Andy Pearce, + +From pgsql-performance-owner@postgresql.org Wed Sep 15 04:37:21 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 7F1E3329E91 + for ; + Wed, 15 Sep 2004 04:37:12 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 40942-01 + for ; + Wed, 15 Sep 2004 03:37:03 +0000 (GMT) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by svr1.postgresql.org (Postfix) with ESMTP id 8EEFD329CDB + for ; + Wed, 15 Sep 2004 04:37:03 +0100 (BST) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by news.hub.org (8.12.9/8.12.9) with ESMTP id i8F3axCt040972 + for ; Wed, 15 Sep 2004 03:37:02 GMT + (envelope-from news@news.hub.org) +Received: (from news@localhost) + by news.hub.org (8.12.9/8.12.9/Submit) id i8F3Y9sM040341 + for pgsql-performance@postgresql.org; Wed, 15 Sep 2004 03:34:09 GMT +From: Christopher Browne +X-Newsgroups: comp.databases.postgresql.performance +Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres -- merge tables +Date: Tue, 14 Sep 2004 23:33:49 -0400 +Organization: cbbrowne Computing Inc +Lines: 27 +Message-ID: +References: <20040914223333.GL56059@decibel.org> + +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Complaints-To: usenet@news.hub.org +X-message-flag: Outlook is rather hackable, isn't it? +X-Home-Page: http://www.cbbrowne.com/info/ +X-Affero: http://svcs.affero.net/rm.php?r=cbbrowne +User-Agent: Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.4 (Security Through + Obscurity, + linux) +Cancel-Lock: sha1:UaTkqIHblGpHjV0yZ3T3QN7XDVw= +To: pgsql-performance@postgresql.org +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/131 +X-Sequence-Number: 8259 + +simon@2ndquadrant.com ("Simon Riggs") wrote: +> The main point is that the constant placed in front of each table +> must in some way relate to the data, to make it useful in +> querying. If it is just a unique constant, chosen at random, it +> won't do much for partition elimination. + +It just struck me - this is much the same notion as that of "cutting +planes" used in Integer Programming. + +The approach, there, is that you take a linear program, which can give +fractional results, and throw on as many additional constraints as you +need in order to force the likelihood of particular variable falling +on integer values. The constraints may appear redundant, but +declaring them allows the answers to be pushed in the right +directions. + +In this particular case, the (arguably redundant) constraints let the +query optimizer have criteria for throwing out unnecessary tables. +Thanks for pointing this out; it may turn a fowl into a feature, when +I can get some "round tuits" :-). That should allow me to turn an +81-way evil join into something that's 4-way at the worst. + +Cheers! +-- +"cbbrowne","@","linuxfinances.info" +http://linuxfinances.info/info/nonrdbms.html +Implementing systems is 95% boredom and 5% sheer terror. + +From pgsql-performance-owner@postgresql.org Wed Sep 15 05:30:29 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 7AA8C329E0E + for ; + Wed, 15 Sep 2004 05:30:27 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 53431-05 + for ; + Wed, 15 Sep 2004 04:30:25 +0000 (GMT) +Received: from joeconway.com (wsip-24-249-201-67.sd.sd.cox.net + [24.249.201.67]) + by svr1.postgresql.org (Postfix) with ESMTP id D2C10329D7A + for ; + Wed, 15 Sep 2004 05:30:24 +0100 (BST) +Received: from [192.168.4.3] (account jconway [192.168.4.3] verified) + by joeconway.com (CommuniGate Pro SMTP 4.1.8) + with ESMTP-TLS id 2185673; Tue, 14 Sep 2004 21:21:57 -0700 +Message-ID: <4147C560.9060702@joeconway.com> +Date: Tue, 14 Sep 2004 21:30:24 -0700 +From: Joe Conway +User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.2) Gecko/20040803 +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: Chris Browne +Cc: pgsql-performance@postgresql.org +Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres -- +References: <20040914223333.GL56059@decibel.org> + + <60k6uw1cqa.fsf@dev6.int.libertyrms.info> +In-Reply-To: <60k6uw1cqa.fsf@dev6.int.libertyrms.info> +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/133 +X-Sequence-Number: 8261 + +Chris Browne wrote: +> Might we set up the view as: +> +> create view combination_of_logs as +> select * from table_1 where txn_date between 'this' and 'that' +> union all +> select * from table_2 where txn_date between 'this2' and 'that2' +> union all +> select * from table_3 where txn_date between 'this3' and 'that3' +> union all +> select * from table_4 where txn_date between 'this4' and 'that4' +> union all +> ... ad infinitum +> union all +> select * from table_n where txn_date > 'start_of_partition_n'; +> +> and expect that to help, as long as the query that hooks up to this +> has date constraints? +> +> We'd have to regenerate the view with new fixed constants each time we +> set up the tables, but that sounds like it could work... + +That's exactly what we're doing, but using inherited tables instead of a +union view. With inheritance, there is no need to rebuild the view each +time a table is added or removed. Basically, in our application, tables +are partitioned by either month or week, depending on the type of data +involved, and queries are normally date qualified. + +We're not completely done with our data conversion (from a commercial +RDBMSi), but so far the results have been excellent. Similar to what +others have said in this thread, the conversion involved restructuring +the data to better suit Postgres, and the application (data +analysis/mining vs. the source system which is operational). As a result +we've compressed a > 1TB database down to ~0.4TB, and seen at least one +typical query reduced from ~9 minutes down to ~40 seconds. + +Joe + + +From pgsql-performance-owner@postgresql.org Wed Sep 15 05:54:30 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 7AF7D329C82 + for ; + Wed, 15 Sep 2004 05:54:29 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 58981-09 + for ; + Wed, 15 Sep 2004 04:54:20 +0000 (GMT) +Received: from millenium.mst.co.jp (unknown [210.230.185.241]) + by svr1.postgresql.org (Postfix) with ESMTP id 08AB7329C65 + for ; + Wed, 15 Sep 2004 05:54:19 +0100 (BST) +Received: from mst1x5r347kymb (lc12114 [192.168.1.114]) + by millenium.mst.co.jp (8.11.6p2/3.7W) with SMTP id i8F4sBq30841; + Wed, 15 Sep 2004 13:54:11 +0900 +Message-ID: <000e01c49ae0$0f189e80$7201a8c0@mst1x5r347kymb> +From: "Iain" +To: "Joe Conway" +Cc: +References: <20040914223333.GL56059@decibel.org> + + <60k6uw1cqa.fsf@dev6.int.libertyrms.info> + <4147C560.9060702@joeconway.com> +Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres -- +Date: Wed, 15 Sep 2004 13:54:18 +0900 +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 6.00.2800.1437 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/134 +X-Sequence-Number: 8262 + +Hi Joe, + +> That's exactly what we're doing, but using inherited tables instead of a +> union view. With inheritance, there is no need to rebuild the view each +> time a table is added or removed. Basically, in our application, tables +> are partitioned by either month or week, depending on the type of data +> involved, and queries are normally date qualified. + +That sounds interesting. I have to admit that I havn't touched iheritance in +pg at all yet so I find it hard to imagine how this would work. If you have +a chance, would you mind elaborating on it just a little? + +Regards +Iain + + +From pgsql-performance-owner@postgresql.org Wed Sep 15 06:02:46 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id DE21C329EC8 + for ; + Wed, 15 Sep 2004 06:02:43 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 62201-04 + for ; + Wed, 15 Sep 2004 05:02:41 +0000 (GMT) +Received: from gp.word-to-the-wise.com (gp.word-to-the-wise.com + [64.71.176.18]) + by svr1.postgresql.org (Postfix) with ESMTP id 540A6329D58 + for ; + Wed, 15 Sep 2004 06:02:41 +0100 (BST) +Received: by gp.word-to-the-wise.com (Postfix, from userid 500) + id 11910900014; Tue, 14 Sep 2004 22:10:04 -0700 (PDT) +Date: Tue, 14 Sep 2004 22:10:04 -0700 +From: Steve Atkins +To: pgsql-performance@postgresql.org +Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres -- merge tables +Message-ID: <20040915051003.GA32043@gp.word-to-the-wise.com> +References: + + <20040914223333.GL56059@decibel.org> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <20040914223333.GL56059@decibel.org> +User-Agent: Mutt/1.4.1i +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/135 +X-Sequence-Number: 8263 + +On Tue, Sep 14, 2004 at 05:33:33PM -0500, Jim C. Nasby wrote: +> On Mon, Sep 13, 2004 at 11:07:35PM +0100, Simon Riggs wrote: +> > PostgreSQL's functionality is in many ways similar to Oracle Partitioning. +> > +> > Loading up your data in many similar tables, then creating a view like: +> > +> > CREATE VIEW BIGTABLE (idate, col1, col2, col3...) AS +> > SELECT 200409130800, col1, col2, col3... FROM table200409130800 +> > UNION ALL +> > SELECT 200409131000, col1, col2, col3... FROM table200409131000 +> > UNION ALL +> > SELECT 200409131200, col1, col2, col3... FROM table200409131200 +> > ...etc... +[...] +> +> Is there by any chance a set of functions to manage adding and removing +> partitions? Certainly this can be done by hand, but having a set of +> tools would make life much easier. I just looked but didn't see anything +> on GBorg. + +I've done a similar thing with time-segregated data by inheriting +all the partition tables from an (empty) parent table. + +Adding a new partition is just a "create table tablefoo () inherits(bigtable)" +and removing a partition just "drop table tablefoo". + +Cheers, + Steve + + +From pgsql-general-owner@postgresql.org Wed Sep 15 07:07:24 2004 +X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 4800E329EC8 + for ; + Wed, 15 Sep 2004 07:07:22 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 74685-10 + for ; + Wed, 15 Sep 2004 06:07:12 +0000 (GMT) +Received: from stark.xeocode.com (gsstark.mtl.istop.com [66.11.160.162]) + by svr1.postgresql.org (Postfix) with ESMTP id 21EA1329EC7 + for ; + Wed, 15 Sep 2004 07:07:10 +0100 (BST) +Received: from localhost ([127.0.0.1] helo=stark.xeocode.com) + by stark.xeocode.com with smtp (Exim 3.36 #1 (Debian)) + id 1C7Swe-0003YT-00; Wed, 15 Sep 2004 02:07:08 -0400 +To: pgsql-general@postgresql.org +Subject: Re: disk performance benchmarks +References: + + <1095185498.5792.12.camel@localhost.localdomain> + <41479FA1.1080001@commandprompt.com> + +In-Reply-To: +From: Greg Stark +Organization: The Emacs Conspiracy; member since 1992 +Date: 15 Sep 2004 02:07:08 -0400 +Message-ID: <877jqwuktv.fsf@stark.xeocode.com> +Lines: 21 +User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/677 +X-Sequence-Number: 65883 + + +Vivek Khera writes: + +> On Sep 14, 2004, at 9:49 PM, Joshua D. Drake wrote: +> +> > It is my experience that RAID 5 is not that great for heavy write situations +> > and that RAID 10 is better. +> > +> It is my experience that this depends entirely on how many spindles you have in +> your RAID. For 4 or 5 spindles, I find RAID10 faster. With 14 spindles, it +> was more or less a toss-up for me. + +I think this depends massively on the hardware involved and the applications +involved. + +For write heavy application I would expect RAID5 to be a lose on any +software-raid based solution. Only with good hardware raid systems with very +large battery-backed cache would it begin to be effective. + +-- +greg + + +From pgsql-performance-owner@postgresql.org Wed Sep 15 08:07:10 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 05A16329E91 + for ; + Wed, 15 Sep 2004 08:07:08 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 96576-05 + for ; + Wed, 15 Sep 2004 07:07:01 +0000 (GMT) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by svr1.postgresql.org (Postfix) with ESMTP id 6244B329ECF + for ; + Wed, 15 Sep 2004 08:07:01 +0100 (BST) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by news.hub.org (8.12.9/8.12.9) with ESMTP id i8F76xCp097709 + for ; Wed, 15 Sep 2004 07:07:00 GMT + (envelope-from news@news.hub.org) +Received: (from news@localhost) + by news.hub.org (8.12.9/8.12.9/Submit) id i8F6o6ED092515 + for pgsql-performance@postgresql.org; Wed, 15 Sep 2004 06:50:06 GMT +From: Christopher Browne +X-Newsgroups: comp.databases.postgresql.performance +Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres -- +Date: Wed, 15 Sep 2004 02:15:08 -0400 +Organization: cbbrowne Computing Inc +Lines: 19 +Message-ID: +References: <20040914223333.GL56059@decibel.org> + + <60k6uw1cqa.fsf@dev6.int.libertyrms.info> + <4147C560.9060702@joeconway.com> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Complaints-To: usenet@news.hub.org +X-message-flag: Outlook is rather hackable, isn't it? +X-Home-Page: http://www.cbbrowne.com/info/ +X-Affero: http://svcs.affero.net/rm.php?r=cbbrowne +User-Agent: Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.4 (Security Through + Obscurity, + linux) +Cancel-Lock: sha1:leQavVXTFA3MVhkRH/tTHsl37po= +To: pgsql-performance@postgresql.org +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/137 +X-Sequence-Number: 8265 + +In the last exciting episode, mail@joeconway.com (Joe Conway) wrote: +> That's exactly what we're doing, but using inherited tables instead of +> a union view. With inheritance, there is no need to rebuild the view +> each time a table is added or removed. Basically, in our application, +> tables are partitioned by either month or week, depending on the type +> of data involved, and queries are normally date qualified. + +Sounds interesting, and possibly usable. + +Where does the constraint come in that'll allow most of the data to be +excluded? + +Or is this just that the entries are all part of "bigtable" so that +the self join is only 2-way? +-- +let name="cbbrowne" and tld="acm.org" in name ^ "@" ^ tld;; +http://linuxfinances.info/info/advocacy.html +"Be humble. A lot happened before you were born." - Life's Little +Instruction Book + +From pgsql-performance-owner@postgresql.org Wed Sep 15 07:51:15 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 9DC59329EC9 + for ; + Wed, 15 Sep 2004 07:51:13 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 89743-07 + for ; + Wed, 15 Sep 2004 06:51:11 +0000 (GMT) +Received: from usbb-lacimss2.unisys.com (usbb-lacimss2.unisys.com + [192.63.108.52]) + by svr1.postgresql.org (Postfix) with ESMTP id E5540329EC2 + for ; + Wed, 15 Sep 2004 07:51:10 +0100 (BST) +Received: from USBB-LACGW3.na.uis.unisys.com ([129.224.98.43]unverified) by + usbb-lacimss2 with InterScan Messaging Security Suite; + Wed, 15 Sep 2004 02:53:20 -0400 +Received: from USBB-LACGW3.na.uis.unisys.com ([129.224.98.44]) by + USBB-LACGW3.na.uis.unisys.com with Microsoft SMTPSVC(6.0.3790.0); + Wed, 15 Sep 2004 02:51:03 -0400 +Received: from gbmk-eugw1.eu.uis.unisys.com ([129.221.133.28]) by + USBB-LACGW3.na.uis.unisys.com with Microsoft SMTPSVC(6.0.3790.0); + Wed, 15 Sep 2004 02:51:03 -0400 +Received: from nlshl-exch1.eu.uis.unisys.com ([192.39.239.20]) by + gbmk-eugw1.eu.uis.unisys.com with Microsoft SMTPSVC(6.0.3790.47); + Wed, 15 Sep 2004 07:51:01 +0100 +X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0 +Content-class: urn:content-classes:message +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: quoted-printable +Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres -- +Date: Wed, 15 Sep 2004 08:51:00 +0200 +Message-ID: + +X-MS-Has-Attach: +X-MS-TNEF-Correlator: +Thread-Topic: [PERFORM] Data Warehouse Reevaluation - MySQL vs Postgres -- +Thread-Index: AcSabATY9muWzOU+Tx2Qqs/Xx6jUIwAhDSpQ +From: "Leeuw van der, Tim" +To: +Cc: "Steinar H. Gunderson" , + "PostgreSQL Performance List" +X-OriginalArrivalTime: 15 Sep 2004 06:51:01.0543 (UTC) + FILETIME=[5CF25370:01C49AF0] +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/136 +X-Sequence-Number: 8264 + +Hi, + +-----Original Message----- +From: pgsql-performance-owner@postgresql.org [mailto:pgsql-performance-owne= +r@postgresql.org]On Behalf Of Michael Kleiser +Sent: Tuesday, September 14, 2004 4:23 PM +To: Leeuw van der, Tim +Cc: Steinar H. Gunderson; PostgreSQL Performance List +Subject: Re: [PERFORM] Data Warehouse Reevaluation - MySQL vs Postgres -- + + +> What MySQl-table-type did you use? +> Was it "MyISAM" which don't supports transactions ? +> Yes I read about that bulk-inserts with this table-type are very fast. +> In Data Warehouse one often don't need transactions. + +Although totally beyond the scope of this thread, we used InnoDB tables wit= +h MySQL because of the transaction-support. + +regards, + +--Tim + +From pgsql-performance-owner@postgresql.org Wed Sep 15 10:12:17 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 8D481329ED1 + for ; + Wed, 15 Sep 2004 10:12:16 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 36609-01 + for ; + Wed, 15 Sep 2004 09:12:12 +0000 (GMT) +Received: from moutng.kundenserver.de (moutng.kundenserver.de + [212.227.126.187]) + by svr1.postgresql.org (Postfix) with ESMTP id 56C90329ECF + for ; + Wed, 15 Sep 2004 10:12:13 +0100 (BST) +Received: from [212.227.126.203] (helo=mrvnet.kundenserver.de) + by moutng.kundenserver.de with esmtp (Exim 3.35 #1) + id 1C7Vpb-0007Qa-00; Wed, 15 Sep 2004 11:12:03 +0200 +Received: from [172.23.4.144] (helo=config17.kundenserver.de) + by mrvnet.kundenserver.de with esmtp (Exim 3.35 #1) + id 1C7Vpa-0002Bs-00; Wed, 15 Sep 2004 11:12:02 +0200 +Received: from www-data by config17.kundenserver.de with local (Exim 3.35 #1 + (Debian)) id 1C7Vpa-0003YG-00; Wed, 15 Sep 2004 11:12:02 +0200 +To: =?iso-8859-1?Q?Joe_Conway?= +Subject: + =?iso-8859-1?Q?Re:_Re:__Data_Warehouse_Reevaluation_-_MySQL_vs_Postgres_--?= +From: +Cc: =?iso-8859-1?Q?Chris_Browne?= , + +Message-Id: <28292295$109523922141480635ce12a8.90913606@config17.schlund.de> +X-Binford: 6100 (more power) +X-Originating-From: 28292295 +X-Mailer: Webmail +X-Routing: UK +X-Received: from config17 by 193.23.116.11 with HTTP id 28292295 for + mail@joeconway.com; Wed, 15 Sep 2004 11:10:01 +0200 +Content-Type: text/plain; + charset="iso-8859-1" +Mime-Version: 1.0 +Content-Transfer-Encoding: 8bit +X-Priority: 3 +Date: Wed, 15 Sep 2004 11:10:01 +0200 +X-Provags-ID: kundenserver.de abuse@kundenserver.de ident:@172.23.4.144 +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.3 tagged_above=0.0 required=5.0 tests=NO_REAL_NAME +X-Spam-Level: +X-Archive-Number: 200409/138 +X-Sequence-Number: 8266 + + +Joe Conway wrote on 15.09.2004, 06:30:24: +> Chris Browne wrote: +> > Might we set up the view as: +> > +> > create view combination_of_logs as +> > select * from table_1 where txn_date between 'this' and 'that' +> > union all +> > select * from table_2 where txn_date between 'this2' and 'that2' +> > union all +> > select * from table_3 where txn_date between 'this3' and 'that3' +> > union all +> > select * from table_4 where txn_date between 'this4' and 'that4' +> > union all +> > ... ad infinitum +> > union all +> > select * from table_n where txn_date > 'start_of_partition_n'; +> > +> > and expect that to help, as long as the query that hooks up to this +> > has date constraints? +> > +> > We'd have to regenerate the view with new fixed constants each time we +> > set up the tables, but that sounds like it could work... +> +> That's exactly what we're doing, but using inherited tables instead of a +> union view. With inheritance, there is no need to rebuild the view each +> time a table is added or removed. Basically, in our application, tables +> are partitioned by either month or week, depending on the type of data +> involved, and queries are normally date qualified. +> +> We're not completely done with our data conversion (from a commercial +> RDBMSi), but so far the results have been excellent. Similar to what +> others have said in this thread, the conversion involved restructuring +> the data to better suit Postgres, and the application (data +> analysis/mining vs. the source system which is operational). As a result +> we've compressed a > 1TB database down to ~0.4TB, and seen at least one +> typical query reduced from ~9 minutes down to ~40 seconds. + +Sounds interesting. + +The performance gain comes from partition elimination of the inherited +tables under the root? + +I take it the compression comes from use of arrays, avoiding the need +for additional rows and key overhead? + +Best Regards, Simon Riggs + +From pgsql-performance-owner@postgresql.org Wed Sep 15 10:17:08 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id E279D329EB7 + for ; + Wed, 15 Sep 2004 10:17:04 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 34366-09 + for ; + Wed, 15 Sep 2004 09:16:53 +0000 (GMT) +Received: from mail.logi-track.com (www.logi-track.com [213.239.193.212]) + by svr1.postgresql.org (Postfix) with ESMTP id 91D2D329ECF + for ; + Wed, 15 Sep 2004 10:16:54 +0100 (BST) +Received: from kingfisher.intern.logi-track.com (G75f1.g.pppool.de + [80.185.117.241]) + by mail.logi-track.com (Postfix) with ESMTP id A9B8A304C6; + Wed, 15 Sep 2004 11:16:49 +0200 (CEST) +Received: from kingfisher.intern.logi-track.com (localhost [127.0.0.1]) + by kingfisher.intern.logi-track.com (Postfix) with SMTP id 50FA0AB2DE; + Wed, 15 Sep 2004 11:16:45 +0200 (CEST) +Date: Wed, 15 Sep 2004 11:16:44 +0200 +From: Markus Schaber +To: pgsql-performance@postgresql.org +Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres -- +Message-ID: <20040915111644.7cac2433@kingfisher.intern.logi-track.com> +In-Reply-To: <20040915051003.GA32043@gp.word-to-the-wise.com> +References: + + <20040914223333.GL56059@decibel.org> + <20040915051003.GA32043@gp.word-to-the-wise.com> +Organization: logi-track ag, =?ISO-8859-15?Q?z=FCrich?= +X-Mailer: Sylpheed-Claws 0.9.12a (GTK+ 1.2.10; i386-pc-linux-gnu) +X-Face: Nx5T&>Nj$VrVPv}sC3IL&)TqHHOKCz/|)R$i"*r@w0{*I6w; + UNU_hdl1J4NI_m{IMztq=>cmM}1gCLbAF+9\#CGkG8}Y{x%SuQ>1#t:; + Z(|\qdd[i]HStki~#w1$TPF}:0w-7"S\Ev|_a$K wrote: + +> > Is there by any chance a set of functions to manage adding and removing +> > partitions? Certainly this can be done by hand, but having a set of +> > tools would make life much easier. I just looked but didn't see anything +> > on GBorg. +>=20 +> I've done a similar thing with time-segregated data by inheriting +> all the partition tables from an (empty) parent table. +>=20 +> Adding a new partition is just a "create table tablefoo () inherits(bigta= +ble)" +> and removing a partition just "drop table tablefoo". + +But you have to add table constraints restricting the time after adding +the partition? + +Thanks, +Markus + +--=20 +markus schaber | dipl. informatiker +logi-track ag | rennweg 14-16 | ch 8001 z=FCrich +phone +41-43-888 62 52 | fax +41-43-888 62 53 +mailto:schabios@logi-track.com | www.logi-track.com + +From pgsql-general-owner@postgresql.org Wed Sep 15 10:40:02 2004 +X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 8128A329E94 + for ; + Wed, 15 Sep 2004 10:40:01 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 45170-06 + for ; + Wed, 15 Sep 2004 09:39:50 +0000 (GMT) +Received: from mail.gmx.net (mail.gmx.net [213.165.64.20]) + by svr1.postgresql.org (Postfix) with SMTP id 02100329EBD + for ; + Wed, 15 Sep 2004 10:39:51 +0100 (BST) +Received: (qmail 13088 invoked by uid 65534); 15 Sep 2004 09:39:51 -0000 +Received: from office01.emerion.com (EHLO zaphod) (83.64.50.26) + by mail.gmx.net (mp026) with SMTP; 15 Sep 2004 11:39:51 +0200 +X-Authenticated: #1946847 +Message-ID: <003801c49b07$f33b6990$ad01a8c0@zaphod> +From: "Michael Paesold" +To: "Jeffrey W. Baker" +Cc: +References: + + <1095185498.5792.12.camel@localhost.localdomain> +Subject: Re: disk performance benchmarks +Date: Wed, 15 Sep 2004 11:39:42 +0200 +MIME-Version: 1.0 +Content-Type: text/plain; + charset="Windows-1252" +Content-Transfer-Encoding: 7bit +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 6.00.2800.1437 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/681 +X-Sequence-Number: 65887 + +Jeffrey W. Baker wrote: + +> Current issue: +> +> A dual 64-bit Opteron 244 machine with 8GB main memory, two 4-disk RAID5 +> arrays (one for database, one for xlogs). PG's config is extremely +> generous, and in isolated benchmarks it's very fast. + +It depends on the controller, but usually I would expect a better +performance if xlogs are just on a two-disk mirror and the rest of the disks +for data (6 splindles instead of 4 then). + +I don't think RAID5 is a benefit for xlogs. + +Regards, +Michael Paesold + +> But, in reality, performance is abyssmal. There's something about what +> PG does inside commits and checkpoints that sends Linux into a catatonic +> state. For instance here's a snapshot of vmstat during a parallel heavy +> select/insert load: +... + + +From pgsql-performance-owner@postgresql.org Wed Sep 15 16:15:58 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 92C95329EA5 + for ; + Wed, 15 Sep 2004 16:15:56 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 71320-08 + for ; + Wed, 15 Sep 2004 15:15:53 +0000 (GMT) +Received: from joeconway.com (wsip-24-249-201-67.sd.sd.cox.net + [24.249.201.67]) + by svr1.postgresql.org (Postfix) with ESMTP id 753B0329EFD + for ; + Wed, 15 Sep 2004 16:15:51 +0100 (BST) +Received: from [192.168.4.3] (account jconway [192.168.4.3] verified) + by joeconway.com (CommuniGate Pro SMTP 4.1.8) + with ESMTP-TLS id 2186783; Wed, 15 Sep 2004 08:07:23 -0700 +Message-ID: <41485CA6.1080505@joeconway.com> +Date: Wed, 15 Sep 2004 08:15:50 -0700 +From: Joe Conway +User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.2) Gecko/20040803 +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: simon@2ndquadrant.com +Cc: Chris Browne , pgsql-performance@postgresql.org +Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres -- +References: <28292295$109523922141480635ce12a8.90913606@config17.schlund.de> +In-Reply-To: <28292295$109523922141480635ce12a8.90913606@config17.schlund.de> +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/140 +X-Sequence-Number: 8268 + +simon@2ndquadrant.com wrote: +> Joe Conway wrote on 15.09.2004, 06:30:24: +>>We're not completely done with our data conversion (from a commercial +>>RDBMSi), but so far the results have been excellent. Similar to what +>>others have said in this thread, the conversion involved restructuring +>>the data to better suit Postgres, and the application (data +>>analysis/mining vs. the source system which is operational). As a result +>>we've compressed a > 1TB database down to ~0.4TB, and seen at least one +>>typical query reduced from ~9 minutes down to ~40 seconds. +> +> Sounds interesting. +> +> The performance gain comes from partition elimination of the inherited +> tables under the root? +> +> I take it the compression comes from use of arrays, avoiding the need +> for additional rows and key overhead? + +Sorry, in trying to be concise I was not very clear. I'm using the term +compression very generally here. I'll try to give a bit more background, + +The original data source is a database schema designed for use by an +operational application that my company sells to provide enhanced +management of equipment that we also sell. The application needs to be +very flexible in exactly what data it stores in order to be useful +across a wide variety of equipment models and versions. In order to do +that there is a very large central "transaction" table that stores +name->value pairs in varchar columns. The name->value pairs come from +parsed output of the equipment, and as such there is a fair amount of +redundancy and unneeded data that ends up getting stored. At each +installation in the field this table can get very large (> billion +rows). Additionally the application prematerializes a variety of +summaries for use by the operators using the GUI. + +We collect the data exported from each of the systems in the field and +accumulate it in a single central database for data mining and analysis. +This is the database that is actually being converted. By compression I +really mean that unneeded and redundant data is being stripped out, and +data known to be of a certain datatype is stored in that type instead of +varchar (e.g. values known to be int are stored as int). Also the +summaries are not being converted (although we do some post processing +to create new materialized summaries). + +My points in telling this were: + - the use of inherited tables to partition this huge number of rows and + yet allow simple query access to it seems to work well, at least in + early validation tests + - had we simply taken the original database and "slammed" it into + Postgres with no further thought, we would not have seen the big + improvements, and thus the project might have been seen as a failure + (even though it saves substantial $) + +Hope that's a bit more clear. I'm hoping to write up a more detailed +case study once we've cut the Postgres system into production and the +dust settles a bit. + +Joe + +From pgsql-general-owner@postgresql.org Wed Sep 15 17:12:29 2004 +X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id CBBFB329E3D + for ; + Wed, 15 Sep 2004 17:12:28 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 95104-07 + for ; + Wed, 15 Sep 2004 16:12:22 +0000 (GMT) +Received: from gghcwest.com (adsl-64-164-133-219.dsl.snfc21.pacbell.net + [64.164.133.219]) + by svr1.postgresql.org (Postfix) with ESMTP id DEA81329E01 + for ; + Wed, 15 Sep 2004 17:12:21 +0100 (BST) +Received: from localhost.localdomain (toonses.gghcwest.com [192.168.168.115]) + by gghcwest.com (8.12.10/8.12.9) with ESMTP id i8FGCJst032176 + for ; Wed, 15 Sep 2004 09:12:19 -0700 +Received: from jwb by localhost.localdomain with local (Exim 4.34) + id 1C7cNd-00029Z-3H + for pgsql-general@postgresql.org; Wed, 15 Sep 2004 09:11:37 -0700 +Subject: Re: disk performance benchmarks +From: "Jeffrey W. Baker" +To: pgsql-general@postgresql.org +In-Reply-To: <003801c49b07$f33b6990$ad01a8c0@zaphod> +References: + + <1095185498.5792.12.camel@localhost.localdomain> + <003801c49b07$f33b6990$ad01a8c0@zaphod> +Content-Type: text/plain +Content-Transfer-Encoding: 7bit +Message-Id: <1095264696.8243.0.camel@localhost.localdomain> +Mime-Version: 1.0 +X-Mailer: Ximian Evolution 1.4.6 +Date: Wed, 15 Sep 2004 09:11:37 -0700 +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/701 +X-Sequence-Number: 65907 + +On Wed, 2004-09-15 at 02:39, Michael Paesold wrote: +> Jeffrey W. Baker wrote: +> +> > Current issue: +> > +> > A dual 64-bit Opteron 244 machine with 8GB main memory, two 4-disk RAID5 +> > arrays (one for database, one for xlogs). PG's config is extremely +> > generous, and in isolated benchmarks it's very fast. +> +> It depends on the controller, but usually I would expect a better +> performance if xlogs are just on a two-disk mirror and the rest of the disks +> for data (6 splindles instead of 4 then). +> +> I don't think RAID5 is a benefit for xlogs. + +All these replies are really interesting, but the point is not that my +RAIDs are too slow, or that my CPUs are too slow. My point is that, for +long stretches of time, by database doesn't come anywhere near using the +capacity of the hardware. And I think that's odd and would like to +config it to "false". + +-jwb + +From pgsql-performance-owner@postgresql.org Wed Sep 15 18:27:13 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id E2116329E90 + for ; + Wed, 15 Sep 2004 18:27:10 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 21986-09 + for ; + Wed, 15 Sep 2004 17:27:07 +0000 (GMT) +Received: from davinci.ethosmedia.com (server226.ethosmedia.com + [209.128.84.226]) + by svr1.postgresql.org (Postfix) with ESMTP id A9188329CF8 + for ; + Wed, 15 Sep 2004 18:27:07 +0100 (BST) +Received: from [64.81.245.111] (account josh@agliodbs.com HELO + temoku.sf.agliodbs.com) + by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.1.8) + with ESMTP id 6356345; Wed, 15 Sep 2004 10:28:26 -0700 +From: Josh Berkus +Reply-To: josh@agliodbs.com +Organization: Aglio Database Solutions +To: Joe Conway +Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres -- +Date: Wed, 15 Sep 2004 10:28:08 -0700 +User-Agent: KMail/1.6.2 +Cc: simon@2ndquadrant.com, Chris Browne , + pgsql-performance@postgresql.org +References: <28292295$109523922141480635ce12a8.90913606@config17.schlund.de> + <41485CA6.1080505@joeconway.com> +In-Reply-To: <41485CA6.1080505@joeconway.com> +MIME-Version: 1.0 +Content-Disposition: inline +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +Message-Id: <200409151028.08461.josh@agliodbs.com> +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/141 +X-Sequence-Number: 8269 + +Joe, + +> - the use of inherited tables to partition this huge number of rows and +> yet allow simple query access to it seems to work well, at least in +> early validation tests +> - had we simply taken the original database and "slammed" it into +> Postgres with no further thought, we would not have seen the big +> improvements, and thus the project might have been seen as a failure +> (even though it saves substantial $) + +Any further thoughts on developing this into true table partitioning? + +-- +--Josh + +Josh Berkus +Aglio Database Solutions +San Francisco + +From pgsql-performance-owner@postgresql.org Wed Sep 15 18:35:03 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 6934C329EAB + for ; + Wed, 15 Sep 2004 18:34:59 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 28350-04 + for ; + Wed, 15 Sep 2004 17:34:55 +0000 (GMT) +Received: from joeconway.com (wsip-24-249-201-67.sd.sd.cox.net + [24.249.201.67]) + by svr1.postgresql.org (Postfix) with ESMTP id AE12F329E8D + for ; + Wed, 15 Sep 2004 18:34:55 +0100 (BST) +Received: from [206.19.64.3] (account jconway HELO [172.16.1.115]) + by joeconway.com (CommuniGate Pro SMTP 4.1.8) + with ESMTP-TLS id 2187215; Wed, 15 Sep 2004 10:26:27 -0700 +Message-ID: <41487D3D.1040509@joeconway.com> +Date: Wed, 15 Sep 2004 10:34:53 -0700 +From: Joe Conway +User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.2) Gecko/20040803 +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: josh@agliodbs.com +Cc: simon@2ndquadrant.com, Chris Browne , + pgsql-performance@postgresql.org +Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres -- +References: <28292295$109523922141480635ce12a8.90913606@config17.schlund.de> + <41485CA6.1080505@joeconway.com> + <200409151028.08461.josh@agliodbs.com> +In-Reply-To: <200409151028.08461.josh@agliodbs.com> +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/142 +X-Sequence-Number: 8270 + +Josh Berkus wrote: +>> - the use of inherited tables to partition this huge number of rows and +>> yet allow simple query access to it seems to work well, at least in +>> early validation tests +>> - had we simply taken the original database and "slammed" it into +>> Postgres with no further thought, we would not have seen the big +>> improvements, and thus the project might have been seen as a failure +>> (even though it saves substantial $) +> +> +> Any further thoughts on developing this into true table partitioning? +> + +Just that I'd love to see it happen ;-) + +Maybe someday I'll be able to find the time to work on it myself, but +for the moment I'm satisfied with the workarounds we've made. + +Joe + +From pgsql-general-owner@postgresql.org Wed Sep 15 18:51:46 2004 +X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 27550329EBF + for ; + Wed, 15 Sep 2004 18:51:44 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 32970-05 + for ; + Wed, 15 Sep 2004 17:51:39 +0000 (GMT) +Received: from lorax.kcilink.com (lorax.kciLink.com [206.112.95.1]) + by svr1.postgresql.org (Postfix) with ESMTP id 8DE0A329EB1 + for ; + Wed, 15 Sep 2004 18:51:39 +0100 (BST) +Received: from localhost (localhost [127.0.0.1]) + by lorax.kcilink.com (Postfix) with ESMTP id DD0D53EEA + for ; + Wed, 15 Sep 2004 13:51:38 -0400 (EDT) +Received: from lorax.kcilink.com ([127.0.0.1]) + by localhost (lorax.kcilink.com [127.0.0.1]) (amavisd-new, port 10024) + with LMTP id 12410-04 for ; + Wed, 15 Sep 2004 13:51:38 -0400 (EDT) +Received: by lorax.kcilink.com (Postfix, from userid 8) + id 4A1963FF7; Wed, 15 Sep 2004 13:51:38 -0400 (EDT) +To: pgsql-general@postgresql.org +Path: not-for-mail +From: Vivek Khera +Newsgroups: ml.postgres.general +Subject: Re: disk performance benchmarks +Date: Wed, 15 Sep 2004 13:51:38 -0400 +Organization: Khera Communications, Inc., Rockville, MD +Lines: 16 +Message-ID: +References: + + <1095185498.5792.12.camel@localhost.localdomain> + <41479FA1.1080001@commandprompt.com> + + <877jqwuktv.fsf@stark.xeocode.com> +NNTP-Posting-Host: yertle.kcilink.com +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Trace: lorax.kcilink.com 1095270698 58397 65.205.34.180 (15 Sep 2004 + 17:51:38 GMT) +X-Complaints-To: daemon@kciLink.com +NNTP-Posting-Date: Wed, 15 Sep 2004 17:51:38 +0000 (UTC) +User-Agent: Gnus/5.1002 (Gnus v5.10.2) XEmacs/21.4 (Security Through + Obscurity, berkeley-unix) +Cancel-Lock: sha1:RGchyPqqcaZYzFY8v8AaSJT8bCE= +X-Virus-Scanned: by amavisd-new at kcilink.com +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/713 +X-Sequence-Number: 65919 + +>>>>> "GS" == Greg Stark writes: + +GS> For write heavy application I would expect RAID5 to be a lose on +GS> any software-raid based solution. Only with good hardware raid +GS> systems with very large battery-backed cache would it begin to be +GS> effective. + +Who in their right mind would run a 14 spindle RAID in software? :-) + +Battery backed write-back cache is definitely mandatory for performance. + +-- +=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +Vivek Khera, Ph.D. Khera Communications, Inc. +Internet: khera@kciLink.com Rockville, MD +1-301-869-4449 x806 +AIM: vivekkhera Y!: vivek_khera http://www.khera.org/~vivek/ + +From pgsql-general-owner@postgresql.org Wed Sep 15 18:53:27 2004 +X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id AFCFD329E8C + for ; + Wed, 15 Sep 2004 18:53:23 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 32970-08 + for ; + Wed, 15 Sep 2004 17:53:19 +0000 (GMT) +Received: from lorax.kcilink.com (lorax.kciLink.com [206.112.95.1]) + by svr1.postgresql.org (Postfix) with ESMTP id 3689B329EBF + for ; + Wed, 15 Sep 2004 18:53:20 +0100 (BST) +Received: from localhost (localhost [127.0.0.1]) + by lorax.kcilink.com (Postfix) with ESMTP id 059EA3FB9 + for ; + Wed, 15 Sep 2004 13:53:20 -0400 (EDT) +Received: from lorax.kcilink.com ([127.0.0.1]) + by localhost (lorax.kcilink.com [127.0.0.1]) (amavisd-new, port 10024) + with LMTP id 85169-01-4 for ; + Wed, 15 Sep 2004 13:53:19 -0400 (EDT) +Received: by lorax.kcilink.com (Postfix, from userid 8) + id 75ADC3EEA; Wed, 15 Sep 2004 13:53:19 -0400 (EDT) +To: pgsql-general@postgresql.org +Path: not-for-mail +From: Vivek Khera +Newsgroups: ml.postgres.general +Subject: Re: disk performance benchmarks +Date: Wed, 15 Sep 2004 13:53:18 -0400 +Organization: Khera Communications, Inc., Rockville, MD +Lines: 19 +Message-ID: +References: + + <1095185498.5792.12.camel@localhost.localdomain> + <003801c49b07$f33b6990$ad01a8c0@zaphod> + <1095264696.8243.0.camel@localhost.localdomain> +NNTP-Posting-Host: yertle.kcilink.com +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Trace: lorax.kcilink.com 1095270799 58397 65.205.34.180 (15 Sep 2004 + 17:53:19 GMT) +X-Complaints-To: daemon@kciLink.com +NNTP-Posting-Date: Wed, 15 Sep 2004 17:53:19 +0000 (UTC) +User-Agent: Gnus/5.1002 (Gnus v5.10.2) XEmacs/21.4 (Security Through + Obscurity, berkeley-unix) +Cancel-Lock: sha1:7d34YoPyCaS4ruW+u/HFtcMzPdE= +X-Virus-Scanned: by amavisd-new at kcilink.com +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/714 +X-Sequence-Number: 65920 + +>>>>> "JWB" == Jeffrey W Baker writes: + +JWB> All these replies are really interesting, but the point is not that my +JWB> RAIDs are too slow, or that my CPUs are too slow. My point is that, for +JWB> long stretches of time, by database doesn't come anywhere near using the +JWB> capacity of the hardware. And I think that's odd and would like to +JWB> config it to "false". + +Have you tried to increase your checkpoing_segments? I get the +suspicion that you're checkpointing every 3 minutes constantly. +You'll have to restart the postmaster for this setting to take effect, +I believe. + + +-- +=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +Vivek Khera, Ph.D. Khera Communications, Inc. +Internet: khera@kciLink.com Rockville, MD +1-301-869-4449 x806 +AIM: vivekkhera Y!: vivek_khera http://www.khera.org/~vivek/ + +From pgsql-performance-owner@postgresql.org Wed Sep 15 18:54:06 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 47312329D69 + for ; + Wed, 15 Sep 2004 18:54:03 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 32327-09 + for ; + Wed, 15 Sep 2004 17:53:59 +0000 (GMT) +Received: from silmaril.syscor.priv (h24-108-208-253.sbm.shawcable.net + [24.108.208.253]) + by svr1.postgresql.org (Postfix) with ESMTP id AD18A329C7B + for ; + Wed, 15 Sep 2004 18:53:58 +0100 (BST) +Received: from syscor.com (strider.syscor.priv [192.168.1.3]) + by silmaril.syscor.priv (8.12.8/8.12.8) with ESMTP id i8FHrxYe010473; + Wed, 15 Sep 2004 10:53:59 -0700 +Message-ID: <41488209.8020702@syscor.com> +Date: Wed, 15 Sep 2004 10:55:21 -0700 +From: Ron St-Pierre +User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; + rv:1.4) Gecko/20030624 +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: "Jeffrey W. Baker" , + pgsql-performance@postgresql.org +Subject: Re: [GENERAL] disk performance benchmarks +References: + + <1095185498.5792.12.camel@localhost.localdomain> + <003801c49b07$f33b6990$ad01a8c0@zaphod> + <1095264696.8243.0.camel@localhost.localdomain> +In-Reply-To: <1095264696.8243.0.camel@localhost.localdomain> +Content-Type: text/plain; charset=ISO-8859-1; format=flowed +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/143 +X-Sequence-Number: 8271 + +Jeffrey W. Baker wrote: + +>All these replies are really interesting, but the point is not that my +>RAIDs are too slow, or that my CPUs are too slow. My point is that, for +>long stretches of time, by database doesn't come anywhere near using the +>capacity of the hardware. And I think that's odd and would like to +>config it to "false". +> +> +What motherboard are you using, and what distro? Earlier you mentioned +that you're on linux 2.6.7 and +a 64-bit Opteron 244 machine with 8GB main memory, two 4-disk RAID5 +arrays (one for +database, one for xlogs). + +Also, did you have a chance to test performance before you implemented RAID? + +Ron + + + +From pgsql-general-owner@postgresql.org Wed Sep 15 19:37:10 2004 +X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id C934D329EAD + for ; + Wed, 15 Sep 2004 19:37:07 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 52269-03 + for ; + Wed, 15 Sep 2004 18:37:03 +0000 (GMT) +Received: from gghcwest.com (adsl-64-164-133-219.dsl.snfc21.pacbell.net + [64.164.133.219]) + by svr1.postgresql.org (Postfix) with ESMTP id 2EBBD329EA9 + for ; + Wed, 15 Sep 2004 19:37:02 +0100 (BST) +Received: from localhost.localdomain (toonses.gghcwest.com [192.168.168.115]) + by gghcwest.com (8.12.10/8.12.9) with ESMTP id i8FIb0st005292 + for ; Wed, 15 Sep 2004 11:37:01 -0700 +Received: from jwb by localhost.localdomain with local (Exim 4.34) + id 1C7ede-0002SU-Oi + for pgsql-general@postgresql.org; Wed, 15 Sep 2004 11:36:18 -0700 +Subject: Re: disk performance benchmarks +From: "Jeffrey W. Baker" +To: pgsql-general@postgresql.org +In-Reply-To: +References: + + <1095185498.5792.12.camel@localhost.localdomain> + <003801c49b07$f33b6990$ad01a8c0@zaphod> + <1095264696.8243.0.camel@localhost.localdomain> + +Content-Type: text/plain +Content-Transfer-Encoding: 7bit +Message-Id: <1095273378.9384.0.camel@localhost.localdomain> +Mime-Version: 1.0 +X-Mailer: Ximian Evolution 1.4.6 +Date: Wed, 15 Sep 2004 11:36:18 -0700 +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/722 +X-Sequence-Number: 65928 + +On Wed, 2004-09-15 at 10:53, Vivek Khera wrote: +> >>>>> "JWB" == Jeffrey W Baker writes: +> +> JWB> All these replies are really interesting, but the point is not that my +> JWB> RAIDs are too slow, or that my CPUs are too slow. My point is that, for +> JWB> long stretches of time, by database doesn't come anywhere near using the +> JWB> capacity of the hardware. And I think that's odd and would like to +> JWB> config it to "false". +> +> Have you tried to increase your checkpoing_segments? I get the +> suspicion that you're checkpointing every 3 minutes constantly. +> You'll have to restart the postmaster for this setting to take effect, +> I believe. + +I have checkpoint_segments set to 24, but I get the feeling that making +it larger may have the opposite effect of what I want, by extending the +period during which the DB makes no progress. + +-jwb + +From pgsql-general-owner@postgresql.org Wed Sep 15 19:47:51 2004 +X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 45AE0329EAD + for ; + Wed, 15 Sep 2004 19:47:49 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 55668-02 + for ; + Wed, 15 Sep 2004 18:47:44 +0000 (GMT) +Received: from mr2.surnet.cl (av2.surnet.cl [216.155.73.169]) + by svr1.postgresql.org (Postfix) with ESMTP id AE949329ED3 + for ; + Wed, 15 Sep 2004 19:47:45 +0100 (BST) +Received: from smtp2.surnet.cl (216.155.73.169) by mr2.surnet.cl (7.0.024) + id 413E2E5500141569; Wed, 15 Sep 2004 14:44:52 -0400 +Received: from av2.surnet.cl ([216.155.73.169]) + by smtp2.surnet.cl (MailMonitor for SMTP v1.2.2 ) ; + Wed, 15 Sep 2004 14:44:52 -0400 (CLT) +Received: from cluster.surnet.cl (216.155.73.165) by smtp2.surnet.cl (7.0.024) + id 413E2E53000FC597; Wed, 15 Sep 2004 14:44:52 -0400 +Received: from 216.155.88.75.dsl.surnet.cl (216.155.85.183) by + cluster.surnet.cl (7.0.024) (authenticated as alvherre@surnet.cl) + id 4134D322001B16EE; Wed, 15 Sep 2004 14:47:09 -0400 +Received: by 216.155.88.75.dsl.surnet.cl (Postfix, from userid 500) + id 555D01958B; Wed, 15 Sep 2004 14:47:39 -0400 (CLT) +Date: Wed, 15 Sep 2004 14:47:39 -0400 +From: Alvaro Herrera +To: "Jeffrey W. Baker" +Cc: pgsql-general@postgresql.org +Subject: Re: disk performance benchmarks +Message-ID: <20040915184739.GF4607@dcc.uchile.cl> +References: + + <1095185498.5792.12.camel@localhost.localdomain> + <003801c49b07$f33b6990$ad01a8c0@zaphod> + <1095264696.8243.0.camel@localhost.localdomain> + + <1095273378.9384.0.camel@localhost.localdomain> +Mime-Version: 1.0 +Content-Type: text/plain; charset=iso-8859-1 +Content-Disposition: inline +Content-Transfer-Encoding: 8bit +In-Reply-To: <1095273378.9384.0.camel@localhost.localdomain> +User-Agent: Mutt/1.5.6i +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/726 +X-Sequence-Number: 65932 + +On Wed, Sep 15, 2004 at 11:36:18AM -0700, Jeffrey W. Baker wrote: +> On Wed, 2004-09-15 at 10:53, Vivek Khera wrote: +> > >>>>> "JWB" == Jeffrey W Baker writes: +> > +> > JWB> All these replies are really interesting, but the point is not that my +> > JWB> RAIDs are too slow, or that my CPUs are too slow. My point is that, for +> > JWB> long stretches of time, by database doesn't come anywhere near using the +> > JWB> capacity of the hardware. And I think that's odd and would like to +> > JWB> config it to "false". +> > +> > Have you tried to increase your checkpoing_segments? I get the +> > suspicion that you're checkpointing every 3 minutes constantly. +> > You'll have to restart the postmaster for this setting to take effect, +> > I believe. +> +> I have checkpoint_segments set to 24, but I get the feeling that making +> it larger may have the opposite effect of what I want, by extending the +> period during which the DB makes no progress. + +It sounds strange that the DB stops doing anything while the checkpoint +is in progress. Have you tried poking at pg_locks during that interval? + +-- +Alvaro Herrera () +"La naturaleza, tan fr�gil, tan expuesta a la muerte... y tan viva" + + +From pgsql-general-owner@postgresql.org Wed Sep 15 20:14:13 2004 +X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 445C8329EAE + for ; + Wed, 15 Sep 2004 20:14:09 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 65176-03 + for ; + Wed, 15 Sep 2004 19:14:03 +0000 (GMT) +Received: from mproxy.gmail.com (rproxy.gmail.com [64.233.170.193]) + by svr1.postgresql.org (Postfix) with ESMTP id E66E3329E77 + for ; + Wed, 15 Sep 2004 20:14:03 +0100 (BST) +Received: by mproxy.gmail.com with SMTP id 74so109627rnl + for ; + Wed, 15 Sep 2004 12:13:54 -0700 (PDT) +Received: by 10.38.125.25 with SMTP id x25mr738436rnc; + Wed, 15 Sep 2004 12:13:54 -0700 (PDT) +Received: by 10.38.208.23 with HTTP; Wed, 15 Sep 2004 12:13:54 -0700 (PDT) +Message-ID: <96624965040915121338c85981@mail.gmail.com> +Date: Wed, 15 Sep 2004 12:13:54 -0700 +From: Marc Slemko +Reply-To: Marc Slemko +To: "Jeffrey W. Baker" +Subject: Re: disk performance benchmarks +Cc: pgsql-general@postgresql.org +In-Reply-To: <1095264696.8243.0.camel@localhost.localdomain> +Mime-Version: 1.0 +Content-Type: text/plain; charset=US-ASCII +Content-Transfer-Encoding: 7bit +References: + + <1095185498.5792.12.camel@localhost.localdomain> + <003801c49b07$f33b6990$ad01a8c0@zaphod> + <1095264696.8243.0.camel@localhost.localdomain> +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/731 +X-Sequence-Number: 65937 + +On Wed, 15 Sep 2004 09:11:37 -0700, Jeffrey W. Baker wrote: +> On Wed, 2004-09-15 at 02:39, Michael Paesold wrote: +> > Jeffrey W. Baker wrote: +> > +> > > Current issue: +> > > +> > > A dual 64-bit Opteron 244 machine with 8GB main memory, two 4-disk RAID5 +> > > arrays (one for database, one for xlogs). PG's config is extremely +> > > generous, and in isolated benchmarks it's very fast. +> > +> > It depends on the controller, but usually I would expect a better +> > performance if xlogs are just on a two-disk mirror and the rest of the disks +> > for data (6 splindles instead of 4 then). +> > +> > I don't think RAID5 is a benefit for xlogs. +> +> All these replies are really interesting, but the point is not that my +> RAIDs are too slow, or that my CPUs are too slow. My point is that, for +> long stretches of time, by database doesn't come anywhere near using the +> capacity of the hardware. And I think that's odd and would like to +> config it to "false". + +Umh, I don't think you have shown any numbers to show if the database +is using the capacity of the hardware or not... + +If this is a seek heavy operation, the raw throughput is irrelevant; +you are limited by the number of seeks your disks can do. Run some +iostats and look at the number of transactions per second. + +Using raid 5 can just destroy the number of write transactions per +second you can do, especially if it is software raid or a cheap raid +controller. + +You can't just say "the hardware is fine and not stressed so I don't +want to discuss that, but everything is too slow so please make it +faster". + +From pgsql-performance-owner@postgresql.org Thu Sep 16 07:10:52 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id DDACD329CF8 + for ; + Thu, 16 Sep 2004 07:10:47 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 55513-07 + for ; + Thu, 16 Sep 2004 06:10:37 +0000 (GMT) +Received: from pd3mo1so.prod.shaw.ca (shawidc-mo1.cg.shawcable.net + [24.71.223.10]) + by svr1.postgresql.org (Postfix) with ESMTP id 349B5329D15 + for ; + Thu, 16 Sep 2004 07:10:37 +0100 (BST) +Received: from pd4mr2so.prod.shaw.ca + (pd4mr2so-qfe3.prod.shaw.ca [10.0.141.213]) by l-daemon + (Sun ONE Messaging Server 6.0 HotFix 1.01 (built Mar 15 2004)) + with ESMTP id <0I4400L05EH7AU10@l-daemon> for + pgsql-performance@postgresql.org; Thu, 16 Sep 2004 00:10:19 -0600 (MDT) +Received: from pn2ml3so.prod.shaw.ca ([10.0.121.147]) + by pd4mr2so.prod.shaw.ca (Sun ONE Messaging Server 6.0 HotFix 1.01 + (built Mar + 15 2004)) with ESMTP id <0I4400CKNEH78V60@pd4mr2so.prod.shaw.ca> for + pgsql-performance@postgresql.org; Thu, 16 Sep 2004 00:10:19 -0600 (MDT) +Received: from mail.refractions.net (mail.refractions.net [24.68.236.214]) + by l-daemon (iPlanet Messaging Server 5.2 HotFix 1.18 (built Jul 28 + 2003)) with ESMTP id <0I4400L5GEH65U@l-daemon> for + pgsql-performance@postgresql.org; + Thu, 16 Sep 2004 00:10:18 -0600 (MDT) +Received: from lion.animals (lion [192.168.50.200]) + by mail.refractions.net (Postfix) with ESMTP id F1DA22BF46 for + ; + Wed, 15 Sep 2004 13:11:30 -0700 (PDT) +Received: by lion.animals (Postfix, from userid 88) id C5BB5E3BA; Wed, + 15 Sep 2004 13:11:30 -0700 (PDT) +Received: from [192.168.50.44] (unknown [192.168.50.44]) + by lion.animals (Postfix) with ESMTP id 0AF3AE3B7 for + ; + Wed, 15 Sep 2004 13:11:29 -0700 (PDT) +Date: Wed, 15 Sep 2004 13:08:30 -0700 +From: Kevin Neufeld +Subject: declared cursor uses slow plan +To: pgsql-performance@postgresql.org +Message-id: <4148A13E.4080207@refractions.net> +MIME-version: 1.0 +Content-type: text/plain; format=flowed; charset=ISO-8859-1 +Content-transfer-encoding: 7bit +X-Accept-Language: en-us, en +User-Agent: Mozilla Thunderbird 0.6 (Windows/20040502) +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.9 tagged_above=0.0 required=5.0 + tests=FAKE_HELO_SHAW_CA +X-Spam-Level: +X-Archive-Number: 200409/156 +X-Sequence-Number: 8284 + +Why would postgres use a different query plan for declared cursors than +without? + +I have a relatively simple query that takes about 150ms using explain +analyze. However, when I wrap the same query in a declared cursor +statement, the subsequent fetch statement takes almost 30seconds. For +some reason, the planner decided to do a nested loop left join instead +of a hash left join. Does anyone know why the planner would choose this +course? + +For those interested, the results of the planner are: + +EXPLAIN ANALYZE SELECT a.wb_id, a.group_code, a.area, a.type, a.source, +a.fcode, asbinary((a.the_geom), 'XDR'), c.name, b.gnis_id FROM +csn_waterbodies a LEFT JOIN (csn_named_waterbodies as b JOIN +all_gnis_info as c ON b.gnis_id = c.gnis_id) on a.wb_id = b.wb_id WHERE +the_geom && GeometryFromText('POLYGON ((998061.4211119856 +820217.228917891, 1018729.3748344192 820217.228917891, +1018729.3748344192 827989.3006519538, 998061.4211119856 +827989.3006519538, 998061.4211119856 820217.228917891))', 42102); + + +QUERY +PLAN + +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + +Hash Left Join (cost=1554.46..1611.26 rows=5 width=1048) (actual +time=144.620..150.277 rows=208 loops=1) + Hash Cond: ("outer".wb_id = "inner".wb_id) + -> Index Scan using csn_waterbodies_the_geom_idx on csn_waterbodies +a (cost=0.00..6.40 rows=5 width=1026) (actual time=0.192..2.838 +rows=208 loops=1) + Index Cond: (the_geom && 'SRID=42102;POLYGON((998061.421111986 +820217.228917891,1018729.37483442 820217.228917891,1018729.37483442 +827989.300651954,998061.421111986 827989.300651954,998061.421111986 +820217.228917891))'::geometry) + Filter: (the_geom && 'SRID=42102;POLYGON((998061.421111986 +820217.228917891,1018729.37483442 820217.228917891,1018729.37483442 +827989.300651954,998061.421111986 827989.300651954,998061.421111986 +820217.228917891))'::geometry) + -> Hash (cost=1535.13..1535.13 rows=7734 width=26) (actual +time=143.717..143.717 rows=0 loops=1) + -> Merge Join (cost=0.00..1535.13 rows=7734 width=26) (actual +time=6.546..134.906 rows=7203 loops=1) + Merge Cond: ("outer".gnis_id = "inner".gnis_id) + -> Index Scan using csn_named_waterbodies_gnis_id_idx on +csn_named_waterbodies b (cost=0.00..140.37 rows=7215 width=8) (actual +time=0.035..10.796 rows=7204 loops=1) + -> Index Scan using all_gnis_info_gnis_id_idx on +all_gnis_info c (cost=0.00..1210.19 rows=41745 width=22) (actual +time=0.014..60.387 rows=42757 loops=1) +Total runtime: 150.713 ms +(11 rows) + + +DECLARE thread_33000912 CURSOR FOR SELECT ... + + +QUERY +PLAN + +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + +Nested Loop Left Join (cost=0.00..8165.43 rows=5 width=1048) + Join Filter: ("outer".wb_id = "inner".wb_id) + -> Index Scan using csn_waterbodies_the_geom_idx on csn_waterbodies +a (cost=0.00..6.40 rows=5 width=1026) + Index Cond: (the_geom && 'SRID=42102;POLYGON((998061.421111986 +820217.228917891,1018729.37483442 820217.228917891,1018729.37483442 +827989.300651954,998061.421111986 827989.300651954,998061.421111986 +820217.228917891))'::geometry) + Filter: (the_geom && 'SRID=42102;POLYGON((998061.421111986 +820217.228917891,1018729.37483442 820217.228917891,1018729.37483442 +827989.300651954,998061.421111986 827989.300651954,998061.421111986 +820217.228917891))'::geometry) + -> Merge Join (cost=0.00..1535.13 rows=7734 width=26) + Merge Cond: ("outer".gnis_id = "inner".gnis_id) + -> Index Scan using csn_named_waterbodies_gnis_id_idx on +csn_named_waterbodies b (cost=0.00..140.37 rows=7215 width=8) + -> Index Scan using all_gnis_info_gnis_id_idx on all_gnis_info +c (cost=0.00..1210.19 rows=41745 width=22) +(9 rows) + + + +Cheers, +Kevin + +-- +Kevin Neufeld, +Refractions Research Inc., +kneufeld@refractions.net +Phone: (250) 383-3022 +Fax: (250) 383-2140 + + +From pgsql-performance-owner@postgresql.org Wed Sep 15 21:37:56 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 4623C329D30 + for ; + Wed, 15 Sep 2004 21:37:55 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 95218-09 + for ; + Wed, 15 Sep 2004 20:37:49 +0000 (GMT) +Received: from cmailm3.svr.pol.co.uk (cmailm3.svr.pol.co.uk [195.92.193.19]) + by svr1.postgresql.org (Postfix) with ESMTP id 48476329EFA + for ; + Wed, 15 Sep 2004 21:37:48 +0100 (BST) +Received: from modem-2838.llama.dialup.pol.co.uk ([217.135.187.22] + helo=happyplace) by cmailm3.svr.pol.co.uk with smtp (Exim 4.14) + id 1C7gXD-0007Eu-Os; Wed, 15 Sep 2004 21:37:48 +0100 +From: "Simon Riggs" +To: "Chris Browne" +Cc: "Pgsql-Performance@Postgresql. Org" +Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres -- merge tables? +Date: Wed, 15 Sep 2004 21:54:22 +0100 +Message-ID: +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +X-Priority: 3 (Normal) +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 +Importance: Normal +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/144 +X-Sequence-Number: 8272 + + +Chris Browne wrote on 15.09.2004, 04:34:53: +> simon@2ndquadrant.com ("Simon Riggs") writes: +> > Well, its fairly straightforward to auto-generate the UNION ALL view, +and +> > important as well, since it needs to be re-specified each time a new +> > partition is loaded or an old one is cleared down. The main point is +that +> > the constant placed in front of each table must in some way relate to +the +> > data, to make it useful in querying. If it is just a unique constant, +chosen +> > at random, it won't do much for partition elimination. So, that tends to +> > make the creation of the UNION ALL view an application/data specific +thing. +> +> Ah, that's probably a good thought. +> +> When we used big "UNION ALL" views, it was with logging tables, where +> there wasn't really any meaningful distinction between partitions. +> +> So you say that if the VIEW contains, within it, meaningful constraint +> information, that can get applied to chop out irrelevant bits? +> +> That suggests a way of resurrecting the idea... +> +> Might we set up the view as: +> +> create view combination_of_logs as +> select * from table_1 where txn_date between 'this' and 'that' +> union all +> select * from table_2 where txn_date between 'this2' and 'that2' +> union all +> select * from table_3 where txn_date between 'this3' and 'that3' +> union all +> select * from table_4 where txn_date between 'this4' and 'that4' +> union all +> ... ad infinitum +> union all +> select * from table_n where txn_date > 'start_of_partition_n'; +> +> and expect that to help, as long as the query that hooks up to this +> has date constraints? +> + +That way of phrasing the view can give you the right answer to the +query, but does not exclude partitions. + +With the above way of doing things, you end up with predicate phrases of +the form ((PARTLIMITLO < partcol) AND (PARTLIMITHI > partcol) AND +(partcol > QUERYLIMITLO) AND (partcol < QUERYLIMITHI)) +...if the values in capitals are constants, then this should evaluate to +a true or false value for each partition table. The optimizer doesn't +yet do this.... + +If you specify the view the way I showed, then the predicate query +becomes a comparison of constants, which DOES get evaluated prior to +full execution....you will see this as a "one time test: false" in the +EXPLAIN. + +The way you've phrased the view is the more obvious way to phrase it, +and I'd spent a few days trying to work out how to solve the algebra +above in code....but that was wasted effort. + +Anyway, if you use constants you can still specify ranges and betweens +and have them work... hence my example showed date-like integers - but +I don't think it just applies to one datatype. + +Best Regards, Simon Riggs + + +From pgsql-performance-owner@postgresql.org Wed Sep 15 21:56:26 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 7BF2E329EF6 + for ; + Wed, 15 Sep 2004 21:56:25 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 05069-03 + for ; + Wed, 15 Sep 2004 20:56:18 +0000 (GMT) +Received: from joeconway.com (wsip-24-249-201-67.sd.sd.cox.net + [24.249.201.67]) + by svr1.postgresql.org (Postfix) with ESMTP id BCACD329D30 + for ; + Wed, 15 Sep 2004 21:56:19 +0100 (BST) +Received: from [206.19.64.3] (account jconway HELO [172.16.1.115]) + by joeconway.com (CommuniGate Pro SMTP 4.1.8) + with ESMTP-TLS id 2187599; Wed, 15 Sep 2004 13:47:51 -0700 +Message-ID: <4148AC71.80908@joeconway.com> +Date: Wed, 15 Sep 2004 13:56:17 -0700 +From: Joe Conway +User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.2) Gecko/20040803 +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: Simon Riggs +Cc: Chris Browne , pgsql-performance@postgresql.org +Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres -- +References: +In-Reply-To: +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/146 +X-Sequence-Number: 8274 + +Simon Riggs wrote: +> Joe, +> +> Your application is very interesting. I've just read your OSCON paper. I'd +> like to talk more about that. Very similar to Kalido. +> +> ...but back to partitioning momentarily: Does the performance gain come from +> partition elimination of the inherited tables under the root? + +I think the major part of the peformance gain comes from the fact that +the source database has different needs in terms of partitioning +criteria because of it's different purpose. The data is basically +partitioned by customer installation instead of by date. Our converted +scheme partitions by date, which is in line with the analytical queries +run at the corporate office. Again, this is an argument in favor of not +simply porting what you're handed. + +We might get similar query performance with a single large table and +multiple partial indexes (e.g. one per month), but there would be one +tradeoff and one disadvantage to that: +1) The indexes would need to be generated periodically -- this is a +tradeoff since we currently need to create inherited tables at the same +periodicity +2) It would be much more difficult to "roll off" a month's worth of data +when needed. The general idea is that each month we create a new monthly +table, then archive and drop the oldest monthly table. If all the data +were in one big table we would have to delete many millions of rows from +a (possibly) multibillion row table, and then vacuum that table -- no +thanks ;-) + +Joe + +From pgsql-performance-owner@postgresql.org Wed Sep 15 21:42:43 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 180B0329E83 + for ; + Wed, 15 Sep 2004 21:42:41 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 99837-05 + for ; + Wed, 15 Sep 2004 20:42:34 +0000 (GMT) +Received: from cmailm4.svr.pol.co.uk (cmailm4.svr.pol.co.uk [195.92.193.211]) + by svr1.postgresql.org (Postfix) with ESMTP id 65481329D30 + for ; + Wed, 15 Sep 2004 21:42:36 +0100 (BST) +Received: from modem-2838.llama.dialup.pol.co.uk ([217.135.187.22] + helo=happyplace) by cmailm4.svr.pol.co.uk with smtp (Exim 4.14) + id 1C7gbp-0005cL-O2; Wed, 15 Sep 2004 21:42:33 +0100 +From: "Simon Riggs" +To: "Joe Conway" +Cc: "Chris Browne" , + +Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres -- +Date: Wed, 15 Sep 2004 21:59:06 +0100 +Message-ID: +MIME-Version: 1.0 +Content-Type: text/plain; + charset="us-ascii" +Content-Transfer-Encoding: 7bit +X-Priority: 3 (Normal) +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) +In-Reply-To: <41485CA6.1080505@joeconway.com> +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 +Importance: Normal +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/145 +X-Sequence-Number: 8273 + + +Joe, + +Your application is very interesting. I've just read your OSCON paper. I'd +like to talk more about that. Very similar to Kalido. + +...but back to partitioning momentarily: Does the performance gain come from +partition elimination of the inherited tables under the root? + +Best Regards, Simon Riggs + + + + +From pgsql-performance-owner@postgresql.org Wed Sep 15 22:09:51 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 03E46329ECF + for ; + Wed, 15 Sep 2004 22:09:39 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 09893-03 + for ; + Wed, 15 Sep 2004 21:09:32 +0000 (GMT) +Received: from mx1.neopolitan.us (mx1.neopolitan.us [65.87.16.224]) + by svr1.postgresql.org (Postfix) with ESMTP id E7EDB329F01 + for ; + Wed, 15 Sep 2004 22:09:32 +0100 (BST) +Received: from [65.87.16.98] (HELO vulture.corp.neopolitan.com) + by mx1.neopolitan.us (CommuniGate Pro SMTP 4.1.8) + with ESMTP-TLS id 5871740 for pgsql-performance@postgresql.org; + Wed, 15 Sep 2004 14:09:32 -0700 +Subject: Partitioning +From: "J. Andrew Rogers" +To: pgsql-performance@postgresql.org +In-Reply-To: <4147C560.9060702@joeconway.com> +References: <20040914223333.GL56059@decibel.org> + + <60k6uw1cqa.fsf@dev6.int.libertyrms.info> + <4147C560.9060702@joeconway.com> +Content-Type: text/plain +Organization: +Message-Id: <1095282571.25123.181.camel@vulture.corp.neopolitan.com> +Mime-Version: 1.0 +X-Mailer: Ximian Evolution 1.2.2 (1.2.2-5) +Date: 15 Sep 2004 14:09:31 -0700 +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/147 +X-Sequence-Number: 8275 + +On Tue, 2004-09-14 at 21:30, Joe Conway wrote: +> That's exactly what we're doing, but using inherited tables instead of a +> union view. With inheritance, there is no need to rebuild the view each +> time a table is added or removed. Basically, in our application, tables +> are partitioned by either month or week, depending on the type of data +> involved, and queries are normally date qualified. + + + +We do something very similar, also using table inheritance and a lot of +triggers to automatically generate partitions and so forth. It works +pretty well, but it is a custom job every time I want to implement a +partitioned table. You can save a lot on speed and space if you use it +to break up large tables with composite indexes, since you can drop +columns from the table depending on how you use it. A big part of +performance gain is that the resulting partitions end up being more +well-ordered than the non-partitioned version, since inserts are hashed +to different partition according to the key and hash function. It is +kind of like a cheap and dirty real-time CLUSTER operation. It also +lets you truncate, lock, and generally be heavy-handed with subsets of +the table without affecting the rest of the table. + + +I think generic table partitioning could pretty much be built on top of +existing capabilities with a small number of tweaks. + +The main difference would be the ability to associate a partitioning +hash function with a table (probably defined inline at CREATE TABLE +time). Something with syntax like: + + ...PARTITION ON 'date_trunc(''hour'',ts)'... + +There would also probably need to be some type of metadata table to +associate specific hashes with partition table names. Other than that, +the capabilities largely already exist, and managing the partition +hashing and association is the ugly part when rolling your own. +Intercepting DML when necessary and making it behave correctly is +already pretty easy, but could probably be streamlined. + + +j. andrew rogers + + + + +From pgsql-performance-owner@postgresql.org Thu Sep 16 04:55:36 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 6D5D9329D7A + for ; + Thu, 16 Sep 2004 04:55:33 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 16924-09 + for ; + Thu, 16 Sep 2004 03:55:28 +0000 (GMT) +Received: from stark.xeocode.com (gsstark.mtl.istop.com [66.11.160.162]) + by svr1.postgresql.org (Postfix) with ESMTP id 24A78329D69 + for ; + Thu, 16 Sep 2004 04:55:27 +0100 (BST) +Received: from localhost ([127.0.0.1] helo=stark.xeocode.com) + by stark.xeocode.com with smtp (Exim 3.36 #1 (Debian)) + id 1C7nMi-0007Jm-00; Wed, 15 Sep 2004 23:55:24 -0400 +To: "J. Andrew Rogers" +Cc: pgsql-performance@postgresql.org +Subject: Re: Partitioning +References: <20040914223333.GL56059@decibel.org> + + <60k6uw1cqa.fsf@dev6.int.libertyrms.info> + <4147C560.9060702@joeconway.com> + <1095282571.25123.181.camel@vulture.corp.neopolitan.com> +In-Reply-To: <1095282571.25123.181.camel@vulture.corp.neopolitan.com> +From: Greg Stark +Organization: The Emacs Conspiracy; member since 1992 +Date: 15 Sep 2004 23:55:24 -0400 +Message-ID: <87y8jarhoz.fsf@stark.xeocode.com> +Lines: 86 +User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/148 +X-Sequence-Number: 8276 + + +"J. Andrew Rogers" writes: + +> We do something very similar, also using table inheritance + +I have a suspicion postgres's table inheritance will end up serving as a good +base for a partitioned table feature. Is it currently possible to query which +subtable a record came from though? + +> A big part of performance gain is that the resulting partitions end up being +> more well-ordered than the non-partitioned version, since inserts are hashed +> to different partition according to the key and hash function. It is kind of +> like a cheap and dirty real-time CLUSTER operation. + +There is also one particular performance gain that cannot be obtained via +other means: A query that accesses a large percentage of a single partition +can use a sequential table scan of just that partition. This can be several +times faster than using an index scan which is the only option if all the data +is stored in a single large table. + +This isn't an uncommon occurrence. Consider an accounting table partitioned by +accounting period. Any aggregate reports for a single accounting period fall +into this category. If you define your partitions well that can often by most +or all of your reports. + +Of course this applies equally if the query is accessing a small number of +partitions. A further refinement is to leverage the partitioning in GROUP BY +or ORDER BY clauses. If you're grouping by the partition key you can avoid a +large sort without having to resort to an index scan or even a hash. And of +course it's tempting to think about parallelization of such queries, +especially if the partitions are stored in separate table spaces on different +drives. + +> It also lets you truncate, lock, and generally be heavy-handed with subsets +> of the table without affecting the rest of the table. + +The biggest benefit by far is this management ability of being able to swap in +and out partitions in a single atomic transaction that doesn't require +extensive i/o. + +In the application we used them on Oracle 8i they were an absolute life-saver. +They took a huge batch job that took several days to run in off-peak hours and +turned it into a single quick cron job that could run at peak hours. We were +able to cut the delay for our OLTP data showing up in the data warehouse from +about a week after extensive manual work to hours after a daily cron job. + +> ...PARTITION ON 'date_trunc(''hour'',ts)'... +> +> There would also probably need to be some type of metadata table to +> associate specific hashes with partition table names. Other than that, +> the capabilities largely already exist, and managing the partition +> hashing and association is the ugly part when rolling your own. +> Intercepting DML when necessary and making it behave correctly is +> already pretty easy, but could probably be streamlined. + +I would suggest you look at the Oracle syntax to handle this. They've already +gone through several iterations of implementations. The original Oracle 7 +implementation was much as people have been describing where you had to define +a big UNION ALL view and enable an option to have the optimizer look for such +views and attempt to eliminate partitions. + +In Oracle 8i they introduced first class partitions with commands to define +and manipulate them. You defined a high bound for each partition. + +In Oracle 9 (or thereabouts, sometime after 8i at any rate) they introduced a +new form where you specify a specific constant value for each partition. This +seems to be more akin to how you're thinking about things. + +The optimizer has several plan nodes specific for partitioned tables. It can +select a single known partition based on information present in the query. It +can also detect cases where it can be sure the query will only access a single +partition but won't be able to determine which until execution time based on +placeholder parameters for cases like "WHERE partition_key = ?". It can also +detect cases like "WHERE partition_key between ? and ?" and "WHERE +partition_key IN (?,?,?)" Or join clauses on partitions. It can also do some +magic things with "GROUP BY partition_key" and "ORDER BY partition_key". + +The work in the optimizer will be the most challenging part. In an ideal world +if the optimizer is very solid it will be possible to bring some partitions to +slow or even near-line storage media. As long as no live queries accidentally +access the wrong partitions the rest of the database need never know that the +data isn't readily available. + + +-- +greg + + +From pgsql-performance-owner@postgresql.org Thu Sep 16 05:07:42 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 2CA62329DF7 + for ; + Thu, 16 Sep 2004 05:07:41 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 20101-05 + for ; + Thu, 16 Sep 2004 04:07:35 +0000 (GMT) +Received: from joeconway.com (wsip-24-249-201-67.sd.sd.cox.net + [24.249.201.67]) + by svr1.postgresql.org (Postfix) with ESMTP id C088B329D9D + for ; + Thu, 16 Sep 2004 05:07:34 +0100 (BST) +Received: from [192.168.4.3] (account jconway [192.168.4.3] verified) + by joeconway.com (CommuniGate Pro SMTP 4.1.8) + with ESMTP-TLS id 2188306; Wed, 15 Sep 2004 20:59:06 -0700 +Message-ID: <41491186.1060708@joeconway.com> +Date: Wed, 15 Sep 2004 21:07:34 -0700 +From: Joe Conway +User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.2) Gecko/20040803 +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: Iain +Cc: pgsql-performance@postgresql.org +Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres -- +References: <20040914223333.GL56059@decibel.org> + + <60k6uw1cqa.fsf@dev6.int.libertyrms.info> + <4147C560.9060702@joeconway.com> + <000e01c49ae0$0f189e80$7201a8c0@mst1x5r347kymb> +In-Reply-To: <000e01c49ae0$0f189e80$7201a8c0@mst1x5r347kymb> +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/149 +X-Sequence-Number: 8277 + +Iain wrote: +>>That's exactly what we're doing, but using inherited tables instead of a +>>union view. With inheritance, there is no need to rebuild the view each +>>time a table is added or removed. Basically, in our application, tables +>>are partitioned by either month or week, depending on the type of data +>>involved, and queries are normally date qualified. +> +> That sounds interesting. I have to admit that I havn't touched iheritance in +> pg at all yet so I find it hard to imagine how this would work. If you have +> a chance, would you mind elaborating on it just a little? + +OK, see below: +===================== + +create table foo(f1 int, f2 date, f3 float8); + +create table foo_2004_01() inherits (foo); +create table foo_2004_02() inherits (foo); +create table foo_2004_03() inherits (foo); + +create index foo_2004_01_idx1 on foo_2004_01(f2); +create index foo_2004_02_idx1 on foo_2004_02(f2); +create index foo_2004_03_idx1 on foo_2004_03(f2); + +insert into foo_2004_02 values(1,'2004-feb-15',3.14); + + + -- needed just for illustration since these are toy tables +set enable_seqscan to false; +explain analyze select * from foo where f2 = '2004-feb-15'; + +QUERY PLAN +------------------------------------------------------------------------------------------------------------------------------------------------ + Result (cost=100000000.00..100000061.32 rows=16 width=16) (actual +time=0.224..0.310 rows=1 loops=1) + -> Append (cost=100000000.00..100000061.32 rows=16 width=16) +(actual time=0.214..0.294 rows=1 loops=1) + -> Seq Scan on foo (cost=100000000.00..100000022.50 rows=5 +width=16) (actual time=0.004..0.004 rows=0 loops=1) + Filter: (f2 = '2004-02-15'::date) + -> Index Scan using foo_2004_01_idx1 on foo_2004_01 foo +(cost=0.00..17.07 rows=5 width=16) (actual time=0.101..0.101 rows=0 loops=1) + Index Cond: (f2 = '2004-02-15'::date) + -> Index Scan using foo_2004_02_idx1 on foo_2004_02 foo +(cost=0.00..4.68 rows=1 width=16) (actual time=0.095..0.101 rows=1 loops=1) + Index Cond: (f2 = '2004-02-15'::date) + -> Index Scan using foo_2004_03_idx1 on foo_2004_03 foo +(cost=0.00..17.07 rows=5 width=16) (actual time=0.066..0.066 rows=0 loops=1) + Index Cond: (f2 = '2004-02-15'::date) + Total runtime: 0.582 ms +(11 rows) + +create table foo_2004_04() inherits (foo); +create index foo_2004_04_idx1 on foo_2004_04(f2); + +explain analyze select * from foo where f2 = '2004-feb-15'; + +QUERY PLAN +------------------------------------------------------------------------------------------------------------------------------------------------ + Result (cost=100000000.00..100000078.38 rows=21 width=16) (actual +time=0.052..0.176 rows=1 loops=1) + -> Append (cost=100000000.00..100000078.38 rows=21 width=16) +(actual time=0.041..0.159 rows=1 loops=1) + -> Seq Scan on foo (cost=100000000.00..100000022.50 rows=5 +width=16) (actual time=0.004..0.004 rows=0 loops=1) + Filter: (f2 = '2004-02-15'::date) + -> Index Scan using foo_2004_01_idx1 on foo_2004_01 foo +(cost=0.00..17.07 rows=5 width=16) (actual time=0.012..0.012 rows=0 loops=1) + Index Cond: (f2 = '2004-02-15'::date) + -> Index Scan using foo_2004_02_idx1 on foo_2004_02 foo +(cost=0.00..4.68 rows=1 width=16) (actual time=0.016..0.022 rows=1 loops=1) + Index Cond: (f2 = '2004-02-15'::date) + -> Index Scan using foo_2004_03_idx1 on foo_2004_03 foo +(cost=0.00..17.07 rows=5 width=16) (actual time=0.008..0.008 rows=0 loops=1) + Index Cond: (f2 = '2004-02-15'::date) + -> Index Scan using foo_2004_04_idx1 on foo_2004_04 foo +(cost=0.00..17.07 rows=5 width=16) (actual time=0.095..0.095 rows=0 loops=1) + Index Cond: (f2 = '2004-02-15'::date) + Total runtime: 0.443 ms +(13 rows) + +For loading data, we COPY into foo, and have a trigger that redirects +the rows to the appropriate partition. + +Notice that the partitions which do not contain any data of interest are +still probed for data, but since they have none it is very quick. In a +real life example I got the following results just this afternoon: + + - aggregate row count = 471,849,665 + - total number inherited tables = 216 + (many are future dated and therefore contain no data) + - select one month's worth of data for one piece of equipment by serial + number (49,257 rows) = 526.015 ms + +Not too bad -- quick enough for my needs. BTW, this is using NFS mounted +storage (NetApp NAS). + +Joe + +From pgsql-performance-owner@postgresql.org Thu Sep 16 05:09:48 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 6B65E329D55 + for ; + Thu, 16 Sep 2004 05:09:47 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 19324-08 + for ; + Thu, 16 Sep 2004 04:09:42 +0000 (GMT) +Received: from gp.word-to-the-wise.com (gp.word-to-the-wise.com + [64.71.176.18]) + by svr1.postgresql.org (Postfix) with ESMTP id 5E9D5329D68 + for ; + Thu, 16 Sep 2004 05:09:41 +0100 (BST) +Received: by gp.word-to-the-wise.com (Postfix, from userid 500) + id 293479029F2; Wed, 15 Sep 2004 21:17:03 -0700 (PDT) +Date: Wed, 15 Sep 2004 21:17:03 -0700 +From: Steve Atkins +To: pgsql-performance@postgresql.org +Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres -- +Message-ID: <20040916041703.GA23118@gp.word-to-the-wise.com> +References: + + <20040914223333.GL56059@decibel.org> + <20040915051003.GA32043@gp.word-to-the-wise.com> + <20040915111644.7cac2433@kingfisher.intern.logi-track.com> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <20040915111644.7cac2433@kingfisher.intern.logi-track.com> +User-Agent: Mutt/1.4.1i +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/150 +X-Sequence-Number: 8278 + +On Wed, Sep 15, 2004 at 11:16:44AM +0200, Markus Schaber wrote: +> Hi, +> +> On Tue, 14 Sep 2004 22:10:04 -0700 +> Steve Atkins wrote: +> +> > > Is there by any chance a set of functions to manage adding and removing +> > > partitions? Certainly this can be done by hand, but having a set of +> > > tools would make life much easier. I just looked but didn't see anything +> > > on GBorg. +> > +> > I've done a similar thing with time-segregated data by inheriting +> > all the partition tables from an (empty) parent table. +> > +> > Adding a new partition is just a "create table tablefoo () inherits(bigtable)" +> > and removing a partition just "drop table tablefoo". +> +> But you have to add table constraints restricting the time after adding +> the partition? + +Uhm... unless I'm confused that's not a meaningful thing in this context. +There's no rule that's putting insertions into an inherited table - the +decision of which inherited table to insert into is made at application +level. + +As I was using it to segregate data based on creation timestamp the +application just inserts into the 'newest' inherited table until it's +full, then creates a new inherited table. + +I've no doubt you could set up rules to scatter inserted data across +a number of tables, but that's not something that's been applicaable +for the problems I tend to work with, so I've not looked at it. + +Cheers, + Steve + + +From pgsql-performance-owner@postgresql.org Thu Sep 16 05:31:36 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id A6A4E329E58 + for ; + Thu, 16 Sep 2004 05:26:02 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 29414-02 + for ; + Thu, 16 Sep 2004 04:25:56 +0000 (GMT) +Received: from houston.familyhealth.com.au (houston.au.fhnetwork.com + [203.22.197.21]) + by svr1.postgresql.org (Postfix) with ESMTP id A35AF329E0E + for ; + Thu, 16 Sep 2004 05:25:55 +0100 (BST) +Received: from houston.familyhealth.com.au (localhost [127.0.0.1]) + by houston.familyhealth.com.au (Postfix) with ESMTP id 8BA9D24FCE; + Thu, 16 Sep 2004 12:25:53 +0800 (WST) +Received: from [192.168.0.40] (work-40.internal [192.168.0.40]) + by houston.familyhealth.com.au (Postfix) with ESMTP id 6944924FCC; + Thu, 16 Sep 2004 12:25:53 +0800 (WST) +Message-ID: <41491690.6030901@familyhealth.com.au> +Date: Thu, 16 Sep 2004 12:29:04 +0800 +From: Christopher Kings-Lynne +User-Agent: Mozilla Thunderbird 0.8 (Windows/20040913) +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: ischamay.andbergsay@activestateway.com +Cc: pgsql-performance@postgresql.org +Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres -- +References: <20040912042442.49915.qmail@web41508.mail.yahoo.com> + + <20040914141452.002e5d4e@kingfisher.intern.logi-track.com> + <20040914143303.GR21419@ns.snowman.net> + +In-Reply-To: +Content-Type: text/plain; charset=ISO-8859-1; format=flowed +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/153 +X-Sequence-Number: 8281 + +>> insert into X +>> select a.keyA, +>> a.keyB, +>> a.colA, +>> a.colB +>> from Y a left join X b +>> using (keyA, keyB) +>> where b.keyA is NULL and +>> b.keyB is NULL; +>> +>> With the appropriate indexes, this is pretty fast but I think a merge +>> would be much faster. + +Problem is it's subject to race conditions if another process is +inserting stuff at the same time... + +Chris + +From pgsql-performance-owner@postgresql.org Thu Sep 16 06:08:45 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 8820D329DC4 + for ; + Thu, 16 Sep 2004 06:08:44 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 42063-05 + for ; + Thu, 16 Sep 2004 05:08:42 +0000 (GMT) +Received: from millenium.mst.co.jp (unknown [210.230.185.241]) + by svr1.postgresql.org (Postfix) with ESMTP id 80B41329DBE + for ; + Thu, 16 Sep 2004 06:08:41 +0100 (BST) +Received: from mst1x5r347kymb (lc12114 [192.168.1.114]) + by millenium.mst.co.jp (8.11.6p2/3.7W) with SMTP id i8G58bq02267; + Thu, 16 Sep 2004 14:08:37 +0900 +Message-ID: <00b301c49bab$38275070$7201a8c0@mst1x5r347kymb> +From: "Iain" +To: "Joe Conway" +Cc: +References: <20040914223333.GL56059@decibel.org> + + <60k6uw1cqa.fsf@dev6.int.libertyrms.info> + <4147C560.9060702@joeconway.com> + <000e01c49ae0$0f189e80$7201a8c0@mst1x5r347kymb> + <41491186.1060708@joeconway.com> +Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres -- +Date: Thu, 16 Sep 2004 14:08:34 +0900 +MIME-Version: 1.0 +Content-Type: text/plain; + charset="ISO-8859-1" +Content-Transfer-Encoding: 7bit +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 6.00.2800.1437 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/154 +X-Sequence-Number: 8282 + +Hi Joe, + +You went to quite a bit of effort, thanks I have the picture now. + +Using inheritence seems to be a useful refinement on top of the earlier +outlined aproach using the UNION ALL view with appropriate predicates on the +condition used to do the partitioning. Having the individual partitions +derived from a parent table makes a lot of sense. + +regards +Iain + + +----- Original Message ----- +From: "Joe Conway" +To: "Iain" +Cc: +Sent: Thursday, September 16, 2004 1:07 PM +Subject: Re: [PERFORM] Data Warehouse Reevaluation - MySQL vs Postgres -- + + +> Iain wrote: +> >>That's exactly what we're doing, but using inherited tables instead of a +> >>union view. With inheritance, there is no need to rebuild the view each +> >>time a table is added or removed. Basically, in our application, tables +> >>are partitioned by either month or week, depending on the type of data +> >>involved, and queries are normally date qualified. +> > +> > That sounds interesting. I have to admit that I havn't touched +iheritance in +> > pg at all yet so I find it hard to imagine how this would work. If you +have +> > a chance, would you mind elaborating on it just a little? +> +> OK, see below: +> ===================== +> +> create table foo(f1 int, f2 date, f3 float8); +> +> create table foo_2004_01() inherits (foo); +> create table foo_2004_02() inherits (foo); +> create table foo_2004_03() inherits (foo); +> +> create index foo_2004_01_idx1 on foo_2004_01(f2); +> create index foo_2004_02_idx1 on foo_2004_02(f2); +> create index foo_2004_03_idx1 on foo_2004_03(f2); +> +> insert into foo_2004_02 values(1,'2004-feb-15',3.14); +> +> +> -- needed just for illustration since these are toy tables +> set enable_seqscan to false; +> explain analyze select * from foo where f2 = '2004-feb-15'; +> +> QUERY PLAN +> -------------------------------------------------------------------------- +---------------------------------------------------------------------- +> Result (cost=100000000.00..100000061.32 rows=16 width=16) (actual +> time=0.224..0.310 rows=1 loops=1) +> -> Append (cost=100000000.00..100000061.32 rows=16 width=16) +> (actual time=0.214..0.294 rows=1 loops=1) +> -> Seq Scan on foo (cost=100000000.00..100000022.50 rows=5 +> width=16) (actual time=0.004..0.004 rows=0 loops=1) +> Filter: (f2 = '2004-02-15'::date) +> -> Index Scan using foo_2004_01_idx1 on foo_2004_01 foo +> (cost=0.00..17.07 rows=5 width=16) (actual time=0.101..0.101 rows=0 +loops=1) +> Index Cond: (f2 = '2004-02-15'::date) +> -> Index Scan using foo_2004_02_idx1 on foo_2004_02 foo +> (cost=0.00..4.68 rows=1 width=16) (actual time=0.095..0.101 rows=1 +loops=1) +> Index Cond: (f2 = '2004-02-15'::date) +> -> Index Scan using foo_2004_03_idx1 on foo_2004_03 foo +> (cost=0.00..17.07 rows=5 width=16) (actual time=0.066..0.066 rows=0 +loops=1) +> Index Cond: (f2 = '2004-02-15'::date) +> Total runtime: 0.582 ms +> (11 rows) +> +> create table foo_2004_04() inherits (foo); +> create index foo_2004_04_idx1 on foo_2004_04(f2); +> +> explain analyze select * from foo where f2 = '2004-feb-15'; +> +> QUERY PLAN +> -------------------------------------------------------------------------- +---------------------------------------------------------------------- +> Result (cost=100000000.00..100000078.38 rows=21 width=16) (actual +> time=0.052..0.176 rows=1 loops=1) +> -> Append (cost=100000000.00..100000078.38 rows=21 width=16) +> (actual time=0.041..0.159 rows=1 loops=1) +> -> Seq Scan on foo (cost=100000000.00..100000022.50 rows=5 +> width=16) (actual time=0.004..0.004 rows=0 loops=1) +> Filter: (f2 = '2004-02-15'::date) +> -> Index Scan using foo_2004_01_idx1 on foo_2004_01 foo +> (cost=0.00..17.07 rows=5 width=16) (actual time=0.012..0.012 rows=0 +loops=1) +> Index Cond: (f2 = '2004-02-15'::date) +> -> Index Scan using foo_2004_02_idx1 on foo_2004_02 foo +> (cost=0.00..4.68 rows=1 width=16) (actual time=0.016..0.022 rows=1 +loops=1) +> Index Cond: (f2 = '2004-02-15'::date) +> -> Index Scan using foo_2004_03_idx1 on foo_2004_03 foo +> (cost=0.00..17.07 rows=5 width=16) (actual time=0.008..0.008 rows=0 +loops=1) +> Index Cond: (f2 = '2004-02-15'::date) +> -> Index Scan using foo_2004_04_idx1 on foo_2004_04 foo +> (cost=0.00..17.07 rows=5 width=16) (actual time=0.095..0.095 rows=0 +loops=1) +> Index Cond: (f2 = '2004-02-15'::date) +> Total runtime: 0.443 ms +> (13 rows) +> +> For loading data, we COPY into foo, and have a trigger that redirects +> the rows to the appropriate partition. +> +> Notice that the partitions which do not contain any data of interest are +> still probed for data, but since they have none it is very quick. In a +> real life example I got the following results just this afternoon: +> +> - aggregate row count = 471,849,665 +> - total number inherited tables = 216 +> (many are future dated and therefore contain no data) +> - select one month's worth of data for one piece of equipment by serial +> number (49,257 rows) = 526.015 ms +> +> Not too bad -- quick enough for my needs. BTW, this is using NFS mounted +> storage (NetApp NAS). +> +> Joe + + +From pgsql-performance-owner@postgresql.org Thu Sep 16 06:17:50 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id B8668329DBE + for ; + Thu, 16 Sep 2004 06:17:49 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 46035-01 + for ; + Thu, 16 Sep 2004 05:17:47 +0000 (GMT) +Received: from joeconway.com (wsip-24-249-201-67.sd.sd.cox.net + [24.249.201.67]) + by svr1.postgresql.org (Postfix) with ESMTP id 4F6AC329D9D + for ; + Thu, 16 Sep 2004 06:17:45 +0100 (BST) +Received: from [192.168.4.3] (account jconway [192.168.4.3] verified) + by joeconway.com (CommuniGate Pro SMTP 4.1.8) + with ESMTP-TLS id 2188476; Wed, 15 Sep 2004 22:09:16 -0700 +Message-ID: <414921F9.400@joeconway.com> +Date: Wed, 15 Sep 2004 22:17:45 -0700 +From: Joe Conway +User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.2) Gecko/20040803 +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: Christopher Browne +Cc: pgsql-performance@postgresql.org +Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres -- +References: <20040914223333.GL56059@decibel.org> + + <60k6uw1cqa.fsf@dev6.int.libertyrms.info> + <4147C560.9060702@joeconway.com> + +In-Reply-To: +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/155 +X-Sequence-Number: 8283 + +Christopher Browne wrote: +> In the last exciting episode, mail@joeconway.com (Joe Conway) wrote: +>>That's exactly what we're doing, but using inherited tables instead of +>>a union view. With inheritance, there is no need to rebuild the view +>>each time a table is added or removed. Basically, in our application, +>>tables are partitioned by either month or week, depending on the type +>>of data involved, and queries are normally date qualified. + +> Where does the constraint come in that'll allow most of the data to be +> excluded? + +Not sure I follow this. + +> Or is this just that the entries are all part of "bigtable" so that +> the self join is only 2-way? + +We don't have a need for self-joins in our application. We do use a +crosstab function to materialize some transposed views of the data, +however. That allows us to avoid self-joins in the cases where we might +otherwise need them. + +Joe + +From pgsql-performance-owner@postgresql.org Thu Sep 16 09:00:10 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id E3C13329CDB + for ; + Thu, 16 Sep 2004 09:00:08 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 87978-08 + for ; + Thu, 16 Sep 2004 07:59:58 +0000 (GMT) +Received: from pd5mo3so.prod.shaw.ca (shawidc-mo1.cg.shawcable.net + [24.71.223.10]) + by svr1.postgresql.org (Postfix) with ESMTP id 6354A329CDD + for ; + Thu, 16 Sep 2004 08:59:58 +0100 (BST) +Received: from pd4mr2so.prod.shaw.ca + (pd4mr2so-qfe3.prod.shaw.ca [10.0.141.213]) by l-daemon + (iPlanet Messaging Server 5.2 HotFix 1.18 (built Jul 28 2003)) + with ESMTP id <0I4400K5GIP6RH@l-daemon> for + pgsql-performance@postgresql.org; + Thu, 16 Sep 2004 01:41:30 -0600 (MDT) +Received: from pn2ml10so.prod.shaw.ca ([10.0.121.80]) + by pd4mr2so.prod.shaw.ca (Sun ONE Messaging Server 6.0 HotFix 1.01 + (built Mar + 15 2004)) with ESMTP id <0I4400CJJIP68TA0@pd4mr2so.prod.shaw.ca> for + pgsql-performance@postgresql.org; Thu, 16 Sep 2004 01:41:30 -0600 (MDT) +Received: from [192.168.1.10] + (S01060050bac04c93.ed.shawcable.net [68.148.193.184]) + by l-daemon (iPlanet Messaging Server 5.2 HotFix 1.18 (built Jul 28 + 2003)) with ESMTP id <0I4400810IP63G@l-daemon> for + pgsql-performance@postgresql.org; + Thu, 16 Sep 2004 01:41:30 -0600 (MDT) +Date: Thu, 16 Sep 2004 01:41:37 -0600 +From: Patrick Clery +Subject: Comparing user attributes with bitwise operators +To: pgsql-performance@postgresql.org +Message-id: <200409160141.37604.patrick@phpforhire.com> +MIME-version: 1.0 +Content-type: text/plain; charset=us-ascii +Content-transfer-encoding: 7bit +Content-disposition: inline +User-Agent: KMail/1.6.2 +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.9 tagged_above=0.0 required=5.0 + tests=FAKE_HELO_SHAW_CA +X-Spam-Level: +X-Archive-Number: 200409/157 +X-Sequence-Number: 8285 + +I'm working on a dating/personals/match-making site, that has used many +different methods of "match-making", that all seem to be very slow. One I am +attempting now that seems to be an efficient method of storage, but not the +best for indexing, is using bitwise operators to compare one person's profile +to another's. + +This method seems to be very fast on a small scale, but I am dealing with a +large user-base here, in excess of 200,000 users that will be executing this +search function every time they login (the search results of their profile +will appear on the main page after they have logged in). I've opted to use +"label tables" for each possible set of answers. (i.e: Marital Status) + +For this table, the set of bits -- bit(5) -- are represented as such: + ++-----+------------+ +| Bit | Meaning | ++-----+------------+ +| 1 | single | +| 2 | separated | +| 3 | married | +| 4 | divorced | +| 5 | widowed | ++-----+------------+ + +Here's the structure of the marital status table: + +# \d marital_matrix +Table "public.marital_matrix" + Column | Type | Modifiers +-----------+----------------+----------------------------------------------------------------------- + member_id | integer | not null default +nextval('public.marital_matrix_member_id_seq'::text) + status | bit varying(5) | not null default (0)::bit(5) + p_status | bit varying(5) | not null default (0)::bit(5) +Indexes: + "marital_matrix_pkey" PRIMARY KEY, btree (member_id) + "idx_marital_matrix" btree ((status::"bit" & p_status::"bit")) + "idx_marital_matrix_single" btree ((status::"bit" & p_status::"bit")) + "idx_marital_p_status" btree (p_status) + "idx_marital_status" btree (status) +Foreign-key constraints: + "$1" FOREIGN KEY (member_id) REFERENCES members(member_id) ON DELETE +CASCADE DEFERRABLE INITIALLY DEFERRED + +To give you an idea of the selectivity (NOTE: there are only 50,000 rows, a +smaller sample than what I will actually be using): + +datingsite=> select count(*),status,p_status from marital_matrix group by +status,p_status; + count | status | p_status +-------+--------+---------- + 89 | 00001 | 00000 + 1319 | 00010 | 00000 + 2465 | 00100 | 00000 + 1 | 00100 | 11111 + 46117 | 10000 | 00000 + +here is the user I'll be comparing against, which has selected that he be +matched with any but married people: + +datingsite=> SELECT * FROM marital_matrix WHERE member_id = 21; + member_id | status | p_status +-----------+--------+---------- + 21 | 10000 | 11011 +(1 row) + + + + +Here are a few possible comparison methods I can think of (NOTE: tests were +run on a 2.4Ghz Intel CPU w/ 256M RAM on FreeBSD 4.10: + + +METHOD 1: Any bit that is set in p_status (prefered marital status) of the +searching user should be set in the potential match's marital status. This is +the method I'd like to improve, if possible. Running the query twice didn't +produce a different runtime. + +EXPLAIN ANALYZE +SELECT + m2.member_id +FROM + marital_matrix m1, marital_matrix m2 +WHERE + m1.member_id = 21 AND + m2.status & m1.p_status != B'00000'; + QUERY PLAN +--------------------------------------------------------------------------------------------------------------------------------------------- + Nested Loop (cost=0.00..2357.79 rows=49742 width=4) (actual +time=18.062..708.469 rows=47525 loops=1) + Join Filter: ((("inner".status)::"bit" & ("outer".p_status)::"bit") <> +B'00000'::"bit") + -> Index Scan using marital_matrix_pkey on marital_matrix m1 +(cost=0.00..5.01 rows=1 width=9) (actual time=0.035..0.045 rows=1 loops=1) + Index Cond: (member_id = 21) + -> Seq Scan on marital_matrix m2 (cost=0.00..1602.91 rows=49991 width=13) +(actual time=17.966..255.529 rows=49991 loops=1) + Total runtime: 905.694 ms +(6 rows) + + +METHOD 2: Specifying the value (I don't think this would make a difference, +but I'll post anyways): + +EXPLAIN ANALYZE +SELECT + member_id +FROM + marital_matrix +WHERE + status & B'11011' != B'00000'; + + QUERY PLAN +---------------------------------------------------------------------------------------------------------------------- + Seq Scan on marital_matrix (cost=0.00..1852.87 rows=49742 width=4) (actual +time=18.113..281.101 rows=47525 loops=1) + Filter: (((status)::"bit" & B'11011'::"bit") <> B'00000'::"bit") + Total runtime: 480.836 ms +(3 rows) + + +METHOD 3: Checking for one bit only. This is definitely not a "real world" +example and unacceptable since the p_status column can and will have multiple +bits. For categories other than "Marital Status", such as "Prefered Hair +Color", the users are likely to select multiple bits (they choose all that +apply). This query does use the index, but is still not very fast at all: + +EXPLAIN ANALYZE +SELECT + member_id +FROM + marital_matrix m1 +WHERE + status & B'10000' = B'10000'; + QUERY +PLAN +------------------------------------------------------------------------------------------------------------------------------------------------------- + Index Scan using idx_marital_matrix_single on marital_matrix m1 +(cost=0.00..903.59 rows=250 width=4) (actual time=0.042..258.907 rows=46117 +loops=1) + Index Cond: (((status)::"bit" & B'10000'::"bit") = B'10000'::"bit") + Total runtime: 451.162 ms +(3 rows) + +METHOD 4: Using an IN statement. This method seems to be very fussy about +using the index, and I have at some point made it use the index when there +are less than 3 possibilites. Also, for fields other than Marital Status, +users will be able to select many bits for their own profile, which means +there would be many permutations: + +EXPLAIN ANALYZE +SELECT + member_id +FROM + marital_matrix +WHERE + status & B'11011' IN (B'10000',B'01000'); + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ + Seq Scan on marital_matrix (cost=0.00..2602.73 rows=993 width=4) (actual +time=17.845..288.279 rows=47525 loops=1) + Filter: ((((status)::"bit" & B'11011'::"bit") = B'10000'::"bit") OR +(((status)::"bit" & B'11011'::"bit") = B'01000'::"bit") OR (((status)::"bit" +& B'11011'::"bit") = B'00010'::"bit") OR (((status)::"bit" & B'11011'::"bit") += B'00001'::"bit")) + Total runtime: 488.651 ms +(3 rows) + + +Method 3 is the only one that used the index, but the only really acceptable +method here is Method 1. + +My questions are... +- Is there any hope in getting this to use an efficient index? +- Any mathmaticians know if there is a way to reorder my bitwise comparison to +have the operator use = and not an != (perhaps to force an index)? (AFAIK, +the answer to the second question is no) + +If anyone could offer any performance tips here I'd really appreciate it. I +imagine that having this schema wouldn't last an hour with the amount of CPU +cycles it would be consuming on math operations. + +Also, I have read the thread that was posted here by Daniel in August: +http://archives.postgresql.org/pgsql-performance/2004-08/msg00328.php + +I have spoke with Daniel on this issue and we both agree it's very difficult +to find a solution that can scale to very large sites. + +I would very much appreciate any advice that some experienced users may have +to offer me for such a situation. TIA + +Patrick + +From pgsql-performance-owner@postgresql.org Thu Sep 16 09:08:04 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 9E6D9329C65 + for ; + Thu, 16 Sep 2004 09:08:03 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 95734-01 + for ; + Thu, 16 Sep 2004 08:07:52 +0000 (GMT) +Received: from houston.familyhealth.com.au (houston.au.fhnetwork.com + [203.22.197.21]) + by svr1.postgresql.org (Postfix) with ESMTP id DD11A329F0E + for ; + Thu, 16 Sep 2004 09:07:51 +0100 (BST) +Received: from houston.familyhealth.com.au (localhost [127.0.0.1]) + by houston.familyhealth.com.au (Postfix) with ESMTP id ACE6024FCE; + Thu, 16 Sep 2004 16:07:48 +0800 (WST) +Received: from [192.168.0.40] (work-40.internal [192.168.0.40]) + by houston.familyhealth.com.au (Postfix) with ESMTP id 1E12124FCC; + Thu, 16 Sep 2004 16:07:43 +0800 (WST) +Message-ID: <41494A94.5080800@familyhealth.com.au> +Date: Thu, 16 Sep 2004 16:11:00 +0800 +From: Christopher Kings-Lynne +User-Agent: Mozilla Thunderbird 0.8 (Windows/20040913) +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: Patrick Clery +Cc: pgsql-performance@postgresql.org +Subject: Re: Comparing user attributes with bitwise operators +References: <200409160141.37604.patrick@phpforhire.com> +In-Reply-To: <200409160141.37604.patrick@phpforhire.com> +Content-Type: text/plain; charset=ISO-8859-1; format=flowed +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/158 +X-Sequence-Number: 8286 + +Sounds like you want a many-to-many table that maps user_ids to match_ids + +Then you can put an index over (user_id, match_id) and the search will +be very fast. + +Chris + +Patrick Clery wrote: +> I'm working on a dating/personals/match-making site, that has used many +> different methods of "match-making", that all seem to be very slow. One I am +> attempting now that seems to be an efficient method of storage, but not the +> best for indexing, is using bitwise operators to compare one person's profile +> to another's. +> +> This method seems to be very fast on a small scale, but I am dealing with a +> large user-base here, in excess of 200,000 users that will be executing this +> search function every time they login (the search results of their profile +> will appear on the main page after they have logged in). I've opted to use +> "label tables" for each possible set of answers. (i.e: Marital Status) +> +> For this table, the set of bits -- bit(5) -- are represented as such: +> +> +-----+------------+ +> | Bit | Meaning | +> +-----+------------+ +> | 1 | single | +> | 2 | separated | +> | 3 | married | +> | 4 | divorced | +> | 5 | widowed | +> +-----+------------+ +> +> Here's the structure of the marital status table: +> +> # \d marital_matrix +> Table "public.marital_matrix" +> Column | Type | Modifiers +> -----------+----------------+----------------------------------------------------------------------- +> member_id | integer | not null default +> nextval('public.marital_matrix_member_id_seq'::text) +> status | bit varying(5) | not null default (0)::bit(5) +> p_status | bit varying(5) | not null default (0)::bit(5) +> Indexes: +> "marital_matrix_pkey" PRIMARY KEY, btree (member_id) +> "idx_marital_matrix" btree ((status::"bit" & p_status::"bit")) +> "idx_marital_matrix_single" btree ((status::"bit" & p_status::"bit")) +> "idx_marital_p_status" btree (p_status) +> "idx_marital_status" btree (status) +> Foreign-key constraints: +> "$1" FOREIGN KEY (member_id) REFERENCES members(member_id) ON DELETE +> CASCADE DEFERRABLE INITIALLY DEFERRED +> +> To give you an idea of the selectivity (NOTE: there are only 50,000 rows, a +> smaller sample than what I will actually be using): +> +> datingsite=> select count(*),status,p_status from marital_matrix group by +> status,p_status; +> count | status | p_status +> -------+--------+---------- +> 89 | 00001 | 00000 +> 1319 | 00010 | 00000 +> 2465 | 00100 | 00000 +> 1 | 00100 | 11111 +> 46117 | 10000 | 00000 +> +> here is the user I'll be comparing against, which has selected that he be +> matched with any but married people: +> +> datingsite=> SELECT * FROM marital_matrix WHERE member_id = 21; +> member_id | status | p_status +> -----------+--------+---------- +> 21 | 10000 | 11011 +> (1 row) +> +> +> +> +> Here are a few possible comparison methods I can think of (NOTE: tests were +> run on a 2.4Ghz Intel CPU w/ 256M RAM on FreeBSD 4.10: +> +> +> METHOD 1: Any bit that is set in p_status (prefered marital status) of the +> searching user should be set in the potential match's marital status. This is +> the method I'd like to improve, if possible. Running the query twice didn't +> produce a different runtime. +> +> EXPLAIN ANALYZE +> SELECT +> m2.member_id +> FROM +> marital_matrix m1, marital_matrix m2 +> WHERE +> m1.member_id = 21 AND +> m2.status & m1.p_status != B'00000'; +> QUERY PLAN +> --------------------------------------------------------------------------------------------------------------------------------------------- +> Nested Loop (cost=0.00..2357.79 rows=49742 width=4) (actual +> time=18.062..708.469 rows=47525 loops=1) +> Join Filter: ((("inner".status)::"bit" & ("outer".p_status)::"bit") <> +> B'00000'::"bit") +> -> Index Scan using marital_matrix_pkey on marital_matrix m1 +> (cost=0.00..5.01 rows=1 width=9) (actual time=0.035..0.045 rows=1 loops=1) +> Index Cond: (member_id = 21) +> -> Seq Scan on marital_matrix m2 (cost=0.00..1602.91 rows=49991 width=13) +> (actual time=17.966..255.529 rows=49991 loops=1) +> Total runtime: 905.694 ms +> (6 rows) +> +> +> METHOD 2: Specifying the value (I don't think this would make a difference, +> but I'll post anyways): +> +> EXPLAIN ANALYZE +> SELECT +> member_id +> FROM +> marital_matrix +> WHERE +> status & B'11011' != B'00000'; +> +> QUERY PLAN +> ---------------------------------------------------------------------------------------------------------------------- +> Seq Scan on marital_matrix (cost=0.00..1852.87 rows=49742 width=4) (actual +> time=18.113..281.101 rows=47525 loops=1) +> Filter: (((status)::"bit" & B'11011'::"bit") <> B'00000'::"bit") +> Total runtime: 480.836 ms +> (3 rows) +> +> +> METHOD 3: Checking for one bit only. This is definitely not a "real world" +> example and unacceptable since the p_status column can and will have multiple +> bits. For categories other than "Marital Status", such as "Prefered Hair +> Color", the users are likely to select multiple bits (they choose all that +> apply). This query does use the index, but is still not very fast at all: +> +> EXPLAIN ANALYZE +> SELECT +> member_id +> FROM +> marital_matrix m1 +> WHERE +> status & B'10000' = B'10000'; +> QUERY +> PLAN +> ------------------------------------------------------------------------------------------------------------------------------------------------------- +> Index Scan using idx_marital_matrix_single on marital_matrix m1 +> (cost=0.00..903.59 rows=250 width=4) (actual time=0.042..258.907 rows=46117 +> loops=1) +> Index Cond: (((status)::"bit" & B'10000'::"bit") = B'10000'::"bit") +> Total runtime: 451.162 ms +> (3 rows) +> +> METHOD 4: Using an IN statement. This method seems to be very fussy about +> using the index, and I have at some point made it use the index when there +> are less than 3 possibilites. Also, for fields other than Marital Status, +> users will be able to select many bits for their own profile, which means +> there would be many permutations: +> +> EXPLAIN ANALYZE +> SELECT +> member_id +> FROM +> marital_matrix +> WHERE +> status & B'11011' IN (B'10000',B'01000'); +> QUERY PLAN +> ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ +> Seq Scan on marital_matrix (cost=0.00..2602.73 rows=993 width=4) (actual +> time=17.845..288.279 rows=47525 loops=1) +> Filter: ((((status)::"bit" & B'11011'::"bit") = B'10000'::"bit") OR +> (((status)::"bit" & B'11011'::"bit") = B'01000'::"bit") OR (((status)::"bit" +> & B'11011'::"bit") = B'00010'::"bit") OR (((status)::"bit" & B'11011'::"bit") +> = B'00001'::"bit")) +> Total runtime: 488.651 ms +> (3 rows) +> +> +> Method 3 is the only one that used the index, but the only really acceptable +> method here is Method 1. +> +> My questions are... +> - Is there any hope in getting this to use an efficient index? +> - Any mathmaticians know if there is a way to reorder my bitwise comparison to +> have the operator use = and not an != (perhaps to force an index)? (AFAIK, +> the answer to the second question is no) +> +> If anyone could offer any performance tips here I'd really appreciate it. I +> imagine that having this schema wouldn't last an hour with the amount of CPU +> cycles it would be consuming on math operations. +> +> Also, I have read the thread that was posted here by Daniel in August: +> http://archives.postgresql.org/pgsql-performance/2004-08/msg00328.php +> +> I have spoke with Daniel on this issue and we both agree it's very difficult +> to find a solution that can scale to very large sites. +> +> I would very much appreciate any advice that some experienced users may have +> to offer me for such a situation. TIA +> +> Patrick +> +> ---------------------------(end of broadcast)--------------------------- +> TIP 4: Don't 'kill -9' the postmaster + +From pgsql-performance-owner@postgresql.org Thu Sep 16 09:45:15 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 19D67329E5F + for ; + Thu, 16 Sep 2004 09:45:06 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 04088-10 + for ; + Thu, 16 Sep 2004 08:44:55 +0000 (GMT) +Received: from stark.xeocode.com (gsstark.mtl.istop.com [66.11.160.162]) + by svr1.postgresql.org (Postfix) with ESMTP id CC008329F01 + for ; + Thu, 16 Sep 2004 09:44:32 +0100 (BST) +Received: from localhost ([127.0.0.1] helo=stark.xeocode.com) + by stark.xeocode.com with smtp (Exim 3.36 #1 (Debian)) + id 1C7rsT-0008Es-00; Thu, 16 Sep 2004 04:44:29 -0400 +To: Patrick Clery +Cc: pgsql-performance@postgresql.org +Subject: Re: Comparing user attributes with bitwise operators +References: <200409160141.37604.patrick@phpforhire.com> +In-Reply-To: <200409160141.37604.patrick@phpforhire.com> +From: Greg Stark +Organization: The Emacs Conspiracy; member since 1992 +Date: 16 Sep 2004 04:44:29 -0400 +Message-ID: <87llfappqq.fsf@stark.xeocode.com> +Lines: 32 +User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/159 +X-Sequence-Number: 8287 + + +Patrick Clery writes: + +> Method 3 is the only one that used the index, but the only really acceptable +> method here is Method 1. +> +> My questions are... +> - Is there any hope in getting this to use an efficient index? +> - Any mathmaticians know if there is a way to reorder my bitwise comparison to +> have the operator use = and not an != (perhaps to force an index)? (AFAIK, +> the answer to the second question is no) + +The only kind of index that is capable of indexing this type of data structure +for arbitrary searches would be a GiST index. I'm not aware of any +implementation for bitfields, though it would be an appropriate use. + +What there is now is the contrib/intarray package. You would have to store +more than just the bitfields, you would have to store an array of integer +flags. That might be denser actually if you end up with many flags few of +which are set. + +GiST indexes allow you to search arbitrary combinations of set and unset +flags. using the "@@" operator + + int[] @@ query_int - returns TRUE if array satisfies query (like '1&(2|3)') + +You might be able to look at the code there and adapt it to apply to bit +fields. If so I think it would be a useful tool. But GiST indexing is pretty +esoteric stuff. + +-- +greg + + +From pgsql-performance-owner@postgresql.org Thu Sep 16 09:54:02 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 51E16329C65 + for ; + Thu, 16 Sep 2004 09:54:01 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 11081-03 + for ; + Thu, 16 Sep 2004 08:53:50 +0000 (GMT) +Received: from stark.xeocode.com (gsstark.mtl.istop.com [66.11.160.162]) + by svr1.postgresql.org (Postfix) with ESMTP id 228E6329EFF + for ; + Thu, 16 Sep 2004 09:53:51 +0100 (BST) +Received: from localhost ([127.0.0.1] helo=stark.xeocode.com) + by stark.xeocode.com with smtp (Exim 3.36 #1 (Debian)) + id 1C7s1V-0008Ff-00; Thu, 16 Sep 2004 04:53:49 -0400 +To: Patrick Clery +Cc: pgsql-performance@postgresql.org +Subject: Re: Comparing user attributes with bitwise operators +References: <200409160141.37604.patrick@phpforhire.com> +In-Reply-To: <200409160141.37604.patrick@phpforhire.com> +From: Greg Stark +Organization: The Emacs Conspiracy; member since 1992 +Date: 16 Sep 2004 04:53:49 -0400 +Message-ID: <87fz5ippb6.fsf@stark.xeocode.com> +Lines: 35 +User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/160 +X-Sequence-Number: 8288 + + +Patrick Clery writes: + +> Here's the structure of the marital status table: + +Also I find it very odd that you have a "marital status table". marital status +is just one attribute of member. Do you expect to have more than one marital +status bitfield per member? How would you distinguish which one to use? + +It's going to make it very hard to combine criteria against other attributes +even if you do manage to get a GiST index to work against marital status and +you do the same with the other, then postgres will have to do some sort of +merge join between them. It also means you'll have to write the same code over +and over for each of these tables. + +I think you're much more likely to want to merge all these attributes into a +single "member_attributes" table, or even into the member table itself. Then +your goal would be to match all the member_attribute bits against all the +member_preferred bits in the right way. + +The more conventional approach is to break them out into a fact separate +table: + +member_id, attribute_id + +And then just have a list of pairs that apply. This kind of normalized data is +much more flexible for writing all kinds of queries against. But like you've +found, it's hard to optimize this to be fast enough for transactional use. + +I think the normal approach with dating sites is to leave this for a batch job +that populates a match table for everyone and just have the web site display +the contents out of that table. + +-- +greg + + +From pgsql-performance-owner@postgresql.org Thu Sep 16 10:08:56 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 8BFFD329F01 + for ; + Thu, 16 Sep 2004 10:08:54 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 18630-04 + for ; + Thu, 16 Sep 2004 09:08:51 +0000 (GMT) +Received: from millenium.mst.co.jp (unknown [210.230.185.241]) + by svr1.postgresql.org (Postfix) with ESMTP id 3C63D329EF9 + for ; + Thu, 16 Sep 2004 10:08:50 +0100 (BST) +Received: from mst1x5r347kymb (lc12114 [192.168.1.114]) + by millenium.mst.co.jp (8.11.6p2/3.7W) with SMTP id i8G98hq03203; + Thu, 16 Sep 2004 18:08:43 +0900 +Message-ID: <00fb01c49bcc$c08dd210$7201a8c0@mst1x5r347kymb> +From: "Iain" +To: "Joe Conway" , "Christopher Browne" +Cc: +References: <20040914223333.GL56059@decibel.org> + + <60k6uw1cqa.fsf@dev6.int.libertyrms.info> + <4147C560.9060702@joeconway.com> + <414921F9.400@joeconway.com> +Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres -- +Date: Thu, 16 Sep 2004 18:08:37 +0900 +MIME-Version: 1.0 +Content-Type: text/plain; + charset="ISO-8859-1" +Content-Transfer-Encoding: 7bit +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 6.00.2800.1437 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/161 +X-Sequence-Number: 8289 + +Joe, Christopher, + +Joe's example wasn't excluding partions, as he didn't use a predicated UNION +ALL view to select from. His queries use an indexed column that allow the +various partitions to be probed at low cost, and he was satisfied wth that. + +My point in my previous post was that you could still do all that that if +you wanted to, by building the predicated view with UNION ALL of each of the +child tables. + +regards +Iain +----- Original Message ----- +From: "Joe Conway" +To: "Christopher Browne" +Cc: +Sent: Thursday, September 16, 2004 2:17 PM +Subject: Re: [PERFORM] Data Warehouse Reevaluation - MySQL vs Postgres -- + + +> Christopher Browne wrote: +> > In the last exciting episode, mail@joeconway.com (Joe Conway) wrote: +> >>That's exactly what we're doing, but using inherited tables instead of +> >>a union view. With inheritance, there is no need to rebuild the view +> >>each time a table is added or removed. Basically, in our application, +> >>tables are partitioned by either month or week, depending on the type +> >>of data involved, and queries are normally date qualified. +> +> > Where does the constraint come in that'll allow most of the data to be +> > excluded? +> +> Not sure I follow this. +> +> > Or is this just that the entries are all part of "bigtable" so that +> > the self join is only 2-way? +> +> We don't have a need for self-joins in our application. We do use a +> crosstab function to materialize some transposed views of the data, +> however. That allows us to avoid self-joins in the cases where we might +> otherwise need them. +> +> Joe +> +> ---------------------------(end of broadcast)--------------------------- +> TIP 2: you can get off all lists at once with the unregister command +> (send "unregister YourEmailAddressHere" to majordomo@postgresql.org) + + +From pgsql-performance-owner@postgresql.org Thu Sep 16 11:39:22 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 3176F329F06 + for ; + Thu, 16 Sep 2004 11:39:20 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 53467-01 + for ; + Thu, 16 Sep 2004 10:39:06 +0000 (GMT) +Received: from mail.logi-track.com (www.logi-track.com [213.239.193.212]) + by svr1.postgresql.org (Postfix) with ESMTP id B6395329C65 + for ; + Thu, 16 Sep 2004 11:39:07 +0100 (BST) +Received: from kingfisher.intern.logi-track.com (p5088EAFC.dip0.t-ipconnect.de + [80.136.234.252]) + by mail.logi-track.com (Postfix) with ESMTP id D6268305A0; + Thu, 16 Sep 2004 12:39:08 +0200 (CEST) +Received: from kingfisher.intern.logi-track.com (localhost [127.0.0.1]) + by kingfisher.intern.logi-track.com (Postfix) with SMTP id 7A846AB2F3; + Thu, 16 Sep 2004 12:39:04 +0200 (CEST) +Date: Thu, 16 Sep 2004 12:39:04 +0200 +From: Markus Schaber +To: ischamay.andbergsay@activestateway.com +Cc: pgsql-performance@postgresql.org +Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres -- +Message-ID: <20040916123904.3ddb8cd6@kingfisher.intern.logi-track.com> +In-Reply-To: +References: <20040912042442.49915.qmail@web41508.mail.yahoo.com> + + <20040914141452.002e5d4e@kingfisher.intern.logi-track.com> + <20040914143303.GR21419@ns.snowman.net> + +Organization: logi-track ag, =?ISO-8859-15?Q?z=FCrich?= +X-Mailer: Sylpheed-Claws 0.9.12a (GTK+ 1.2.10; i386-pc-linux-gnu) +X-Face: Nx5T&>Nj$VrVPv}sC3IL&)TqHHOKCz/|)R$i"*r@w0{*I6w; + UNU_hdl1J4NI_m{IMztq=>cmM}1gCLbAF+9\#CGkG8}Y{x%SuQ>1#t:; + Z(|\qdd[i]HStki~#w1$TPF}:0w-7"S\Ev|_a$K wrote: + +> Googling 'upsert' (an Oraclism, I believe) will get you hits on Oracle=20 +> and DB2's implementation of MERGE, which does what AMOUNTS to what is +> described below (one mass UPDATE...FROM, one mass INSERT...WHERE NOT=20 +> EXISTS). +>=20 +> No, you shouldn't iterate row-by-row through the temp table. +> Whenever possible, try to do updates in one single (mass) operation. +> Doing it that way gives the optimizer the best chance at amortizing +> fixed costs, and batching operations. + +But when every updated row has a different value for the column(s) to be +updated, then I still have to use one update statement per row, which I +expect to be faster when done via a stored procedure than having the +whole client-server roundtrip including parsing every time. Or did I +miss some nice SQL statement? + + +Have a nice day, +Markus +--=20 +markus schaber | dipl. informatiker +logi-track ag | rennweg 14-16 | ch 8001 z=FCrich +phone +41-43-888 62 52 | fax +41-43-888 62 53 +mailto:schabios@logi-track.com | www.logi-track.com + +From pgsql-performance-owner@postgresql.org Thu Sep 16 11:58:48 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 1B61C329CB7 + for ; + Thu, 16 Sep 2004 11:58:48 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 54172-07 + for ; + Thu, 16 Sep 2004 10:58:36 +0000 (GMT) +Received: from mproxy.gmail.com (rproxy.gmail.com [64.233.170.205]) + by svr1.postgresql.org (Postfix) with ESMTP id F33FD329C63 + for ; + Thu, 16 Sep 2004 11:58:35 +0100 (BST) +Received: by mproxy.gmail.com with SMTP id 77so362084rnk + for ; + Thu, 16 Sep 2004 03:58:32 -0700 (PDT) +Received: by 10.38.14.78 with SMTP id 78mr592173rnn; + Thu, 16 Sep 2004 03:58:32 -0700 (PDT) +Received: by 10.38.126.6 with HTTP; Thu, 16 Sep 2004 03:58:32 -0700 (PDT) +Message-ID: +Date: Thu, 16 Sep 2004 06:58:32 -0400 +From: Mike Rylander +Reply-To: Mike Rylander +To: Greg Stark +Subject: Re: Partitioning +Cc: pgsql-performance@postgresql.org +In-Reply-To: <87y8jarhoz.fsf@stark.xeocode.com> +Mime-Version: 1.0 +Content-Type: text/plain; charset=US-ASCII +Content-Transfer-Encoding: 7bit +References: <20040914223333.GL56059@decibel.org> + + <60k6uw1cqa.fsf@dev6.int.libertyrms.info> + <4147C560.9060702@joeconway.com> + <1095282571.25123.181.camel@vulture.corp.neopolitan.com> + <87y8jarhoz.fsf@stark.xeocode.com> +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/163 +X-Sequence-Number: 8291 + +On 15 Sep 2004 23:55:24 -0400, Greg Stark wrote: +> +> "J. Andrew Rogers" writes: +> +> > We do something very similar, also using table inheritance +> +> I have a suspicion postgres's table inheritance will end up serving as a good +> base for a partitioned table feature. Is it currently possible to query which +> subtable a record came from though? + + From the docs on http://www.postgresql.org/docs/7.4/static/ddl-inherit.html : + +... In some cases you may wish to know which table a particular row +originated from. There is a system column called TABLEOID in each +table which can tell you the originating table: + +SELECT c.tableoid, c.name, c.altitude +FROM cities c +WHERE c.altitude > 500; + +which returns: + + tableoid | name | altitude +----------+-----------+---------- + 139793 | Las Vegas | 2174 + 139793 | Mariposa | 1953 + 139798 | Madison | 845 + +(If you try to reproduce this example, you will probably get different +numeric OIDs.) By doing a join with pg_class you can see the actual +table names: + +SELECT p.relname, c.name, c.altitude +FROM cities c, pg_class p +WHERE c.altitude > 500 and c.tableoid = p.oid; + +which returns: + + relname | name | altitude +----------+-----------+---------- + cities | Las Vegas | 2174 + cities | Mariposa | 1953 + capitals | Madison | 845 + +--miker + +From pgsql-performance-owner@postgresql.org Thu Sep 16 14:38:35 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 0C438329D04 + for ; + Thu, 16 Sep 2004 14:38:34 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 13564-07 + for ; + Thu, 16 Sep 2004 13:38:21 +0000 (GMT) +Received: from mail.logi-track.com (www.logi-track.com [213.239.193.212]) + by svr1.postgresql.org (Postfix) with ESMTP id E999A329D27 + for ; + Thu, 16 Sep 2004 14:38:24 +0100 (BST) +Received: from kingfisher.intern.logi-track.com (G7ec9.g.pppool.de + [80.185.126.201]) + by mail.logi-track.com (Postfix) with ESMTP id BED1B305A0; + Thu, 16 Sep 2004 15:38:27 +0200 (CEST) +Received: from kingfisher.intern.logi-track.com (localhost [127.0.0.1]) + by kingfisher.intern.logi-track.com (Postfix) with SMTP id D2159AB2F3; + Thu, 16 Sep 2004 15:38:22 +0200 (CEST) +Date: Thu, 16 Sep 2004 15:38:21 +0200 +From: Markus Schaber +To: PostgreSQL Performance List +Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres -- +Message-ID: <20040916153821.1d5716ca@kingfisher.intern.logi-track.com> +In-Reply-To: <20040916041703.GA23118@gp.word-to-the-wise.com> +References: + + <20040914223333.GL56059@decibel.org> + <20040915051003.GA32043@gp.word-to-the-wise.com> + <20040915111644.7cac2433@kingfisher.intern.logi-track.com> + <20040916041703.GA23118@gp.word-to-the-wise.com> +Organization: logi-track ag, =?ISO-8859-15?Q?z=FCrich?= +X-Mailer: Sylpheed-Claws 0.9.12a (GTK+ 1.2.10; i386-pc-linux-gnu) +X-Face: Nx5T&>Nj$VrVPv}sC3IL&)TqHHOKCz/|)R$i"*r@w0{*I6w; + UNU_hdl1J4NI_m{IMztq=>cmM}1gCLbAF+9\#CGkG8}Y{x%SuQ>1#t:; + Z(|\qdd[i]HStki~#w1$TPF}:0w-7"S\Ev|_a$K wrote: + +> On Wed, Sep 15, 2004 at 11:16:44AM +0200, Markus Schaber wrote: +> > But you have to add table constraints restricting the time after adding +> > the partition? +>=20 +> Uhm... unless I'm confused that's not a meaningful thing in this context. +> There's no rule that's putting insertions into an inherited table - the +> decision of which inherited table to insert into is made at application +> level. + +I thought of the query optimizer. I thought it could use the table +constraints to drop tables when creating the union. But now I think that +an index gives enough win, because the tree-based indices are rather +quick at returning zero rows when the queried value is out of the +indexed range. + +Greetings, +Markus + + +--=20 +markus schaber | dipl. informatiker +logi-track ag | rennweg 14-16 | ch 8001 z=FCrich +phone +41-43-888 62 52 | fax +41-43-888 62 53 +mailto:schabios@logi-track.com | www.logi-track.com + +From pgsql-performance-owner@postgresql.org Thu Sep 16 16:36:46 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 0A0C4329D7F + for ; + Thu, 16 Sep 2004 16:36:41 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 64721-06 + for ; + Thu, 16 Sep 2004 15:36:34 +0000 (GMT) +Received: from joeconway.com (wsip-24-249-201-67.sd.sd.cox.net + [24.249.201.67]) + by svr1.postgresql.org (Postfix) with ESMTP id 3469B329D4D + for ; + Thu, 16 Sep 2004 16:36:33 +0100 (BST) +Received: from [206.19.64.3] (account jconway HELO [172.16.1.115]) + by joeconway.com (CommuniGate Pro SMTP 4.1.8) + with ESMTP-TLS id 2189316; Thu, 16 Sep 2004 08:28:03 -0700 +Message-ID: <4149B2FF.6030808@joeconway.com> +Date: Thu, 16 Sep 2004 08:36:31 -0700 +From: Joe Conway +User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.2) Gecko/20040803 +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: Iain +Cc: Christopher Browne , + pgsql-performance@postgresql.org +Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres -- +References: <20040914223333.GL56059@decibel.org> + + <60k6uw1cqa.fsf@dev6.int.libertyrms.info> + <4147C560.9060702@joeconway.com> + <414921F9.400@joeconway.com> + <00fb01c49bcc$c08dd210$7201a8c0@mst1x5r347kymb> +In-Reply-To: <00fb01c49bcc$c08dd210$7201a8c0@mst1x5r347kymb> +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/165 +X-Sequence-Number: 8293 + +Iain wrote: +> Joe's example wasn't excluding partions, as he didn't use a predicated UNION +> ALL view to select from. His queries use an indexed column that allow the +> various partitions to be probed at low cost, and he was satisfied wth that. + +Right. + +> My point in my previous post was that you could still do all that that if +> you wanted to, by building the predicated view with UNION ALL of each of the +> child tables. + +Right. It doesn't look that much different: + +create or replace view foo_vw as +select * from foo_2004_01 where f2 >= '2004-jan-01' and f2 <= '2004-jan-31' +union all +select * from foo_2004_02 where f2 >= '2004-feb-01' and f2 <= '2004-feb-29' +union all +select * from foo_2004_03 where f2 >= '2004-mar-01' and f2 <= '2004-mar-31' +; + + -- needed just for illustration since these are toy tables +set enable_seqscan to false; + +explain analyze select * from foo_vw where f2 = '2004-feb-15'; + QUERY PLAN +---------------------------------------------------------------------------------- + Subquery Scan foo_vw (cost=0.00..14.54 rows=3 width=16) (actual +time=0.022..0.027 rows=1 loops=1) + -> Append (cost=0.00..14.51 rows=3 width=16) (actual +time=0.019..0.022 rows=1 loops=1) + -> Subquery Scan "*SELECT* 1" (cost=0.00..4.84 rows=1 +width=16) (actual time=0.004..0.004 rows=0 loops=1) + -> Index Scan using foo_2004_01_idx2 on foo_2004_01 +(cost=0.00..4.83 rows=1 width=16) (actual time=0.003..0.003 rows=0 loops=1) + Index Cond: ((f2 >= '2004-01-01'::date) AND (f2 <= +'2004-01-31'::date) AND (f2 = '2004-02-15'::date)) + -> Subquery Scan "*SELECT* 2" (cost=0.00..4.84 rows=1 +width=16) (actual time=0.013..0.015 rows=1 loops=1) + -> Index Scan using foo_2004_02_idx2 on foo_2004_02 +(cost=0.00..4.83 rows=1 width=16) (actual time=0.009..0.010 rows=1 loops=1) + Index Cond: ((f2 >= '2004-02-01'::date) AND (f2 <= +'2004-02-29'::date) AND (f2 = '2004-02-15'::date)) + -> Subquery Scan "*SELECT* 3" (cost=0.00..4.84 rows=1 +width=16) (actual time=0.001..0.001 rows=0 loops=1) + -> Index Scan using foo_2004_03_idx2 on foo_2004_03 +(cost=0.00..4.83 rows=1 width=16) (actual time=0.001..0.001 rows=0 loops=1) + Index Cond: ((f2 >= '2004-03-01'::date) AND (f2 <= +'2004-03-31'::date) AND (f2 = '2004-02-15'::date)) + Total runtime: 0.188 ms +(12 rows) + +regression=# explain analyze select * from foo where f2 = '2004-feb-15'; + QUERY PLAN +---------------------------------------------------------------------------------- + Result (cost=100000000.00..100000073.70 rows=20 width=16) (actual +time=0.059..0.091 rows=1 loops=1) + -> Append (cost=100000000.00..100000073.70 rows=20 width=16) +(actual time=0.055..0.086 rows=1 loops=1) + -> Seq Scan on foo (cost=100000000.00..100000022.50 rows=5 +width=16) (actual time=0.001..0.001 rows=0 loops=1) + Filter: (f2 = '2004-02-15'::date) + -> Index Scan using foo_2004_01_idx2 on foo_2004_01 foo +(cost=0.00..17.07 rows=5 width=16) (actual time=0.045..0.045 rows=0 loops=1) + Index Cond: (f2 = '2004-02-15'::date) + -> Index Scan using foo_2004_02_idx2 on foo_2004_02 foo +(cost=0.00..17.07 rows=5 width=16) (actual time=0.008..0.009 rows=1 loops=1) + Index Cond: (f2 = '2004-02-15'::date) + -> Index Scan using foo_2004_03_idx2 on foo_2004_03 foo +(cost=0.00..17.07 rows=5 width=16) (actual time=0.029..0.029 rows=0 loops=1) + Index Cond: (f2 = '2004-02-15'::date) + Total runtime: 0.191 ms +(11 rows) + + +The main difference being that the view needs to be recreated every time +a table is added or dropped, whereas with the inherited tables method +that isn't needed. + +Joe + +From pgsql-performance-owner@postgresql.org Thu Sep 16 17:46:56 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 70A2E329CE3 + for ; + Thu, 16 Sep 2004 17:46:54 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 93447-04 + for ; + Thu, 16 Sep 2004 16:46:44 +0000 (GMT) +Received: from omnis-mail.omnis.com (omnis-mail.omnis.com [216.239.128.28]) + by svr1.postgresql.org (Postfix) with ESMTP id 68010329D69 + for ; + Thu, 16 Sep 2004 17:46:44 +0100 (BST) +Received: from [216.239.128.141] (daniel.omnis.com [216.239.128.141]) + by omnis-mail.omnis.com (Postfix) with ESMTP id A1A791BFD7 + for ; + Thu, 16 Sep 2004 09:46:43 -0700 (PDT) +Message-ID: <4149C373.6040808@omnis.com> +Date: Thu, 16 Sep 2004 09:46:43 -0700 +From: Daniel Ceregatti +Organization: Omnis Network +User-Agent: Mozilla Thunderbird 0.7.1 (X11/20040626) +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: pgsql-performance@postgresql.org +Subject: Re: Comparing user attributes with bitwise operators +References: <200409160141.37604.patrick@phpforhire.com> + <41494A94.5080800@familyhealth.com.au> +In-Reply-To: <41494A94.5080800@familyhealth.com.au> +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/166 +X-Sequence-Number: 8294 + +Christopher Kings-Lynne wrote: + +> Sounds like you want a many-to-many table that maps user_ids to match_ids +> +> Then you can put an index over (user_id, match_id) and the search will +> be very fast. +> +> Chris +> +If I understand you correctly, I believe I've tried this approach. While +matching on a single attribute and a single value was indeed very fast +and used an index, as soon as I tried to match on more than one value +(where valueid in (1, 2, 3)) the index was no longer used. Since my +approach used ints, I used in(), which is effectively "or", which is +presumably why the index is no longer used. With the bit, one would do a +bitwise "or" (where value & search = value). This cannot be easily +indexed, afaik. + +The other problem I had with a 1:many table, where there was a row for +every person's attributes (~20M rows) was that somehow time was lost in +either sorting or somewhere else. Individual queries against a single +attribute would be very fast, but as soon as I tried to join another +attribute, the query times got really bad. See http://sh.nu/w/email.txt +line 392 (Don't worry, there are line numbers in the page). + +So far I've stuck with my original plan, which is to maintain a 1:1 +table of people:attributes where each attribute is in its own column. +Still, no index is used, but it's been the best performer up to now. + +I'm still looking for a better plan though. + +Daniel + +-- + +Daniel Ceregatti - Programmer +Omnis Network, LLC + +You are fighting for survival in your own sweet and gentle way. + + +From pgsql-performance-owner@postgresql.org Thu Sep 16 18:49:44 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 95EB9329C63; + Thu, 16 Sep 2004 18:49:42 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 08737-10; Thu, 16 Sep 2004 17:49:32 +0000 (GMT) +Received: from davinci.ethosmedia.com (server226.ethosmedia.com + [209.128.84.226]) + by svr1.postgresql.org (Postfix) with ESMTP id 49850329C67; + Thu, 16 Sep 2004 18:49:32 +0100 (BST) +Received: from [64.81.245.111] (account josh@agliodbs.com HELO + temoku.sf.agliodbs.com) + by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.1.8) + with ESMTP id 6361749; Thu, 16 Sep 2004 10:50:52 -0700 +From: Josh Berkus +Reply-To: josh@agliodbs.com +Organization: Aglio Database Solutions +To: ricardo@sqlmagazine.com.br +Subject: Article about PostgreSQL and RAID in Brazil +Date: Thu, 16 Sep 2004 10:50:33 -0700 +User-Agent: KMail/1.6.2 +Cc: pgsql-performance@postgresql.org, br@postgresql.org +MIME-Version: 1.0 +Content-Disposition: inline +Content-Type: text/plain; + charset="us-ascii" +Content-Transfer-Encoding: 7bit +Message-Id: <200409161050.33289.josh@agliodbs.com> +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/167 +X-Sequence-Number: 8295 + +Ricardo, + +Hello. I've moved your query to a more appropriate mailing list; on +PERFORMANCE we discuss RAID all the time. If you don't mind wading through a +host of opinions, you'll get plenty here. I've also cc'd our Brazillian +PostgreSQL community. + +Everyone, please note that Ricardo is NOT subscribed so cc him on your +responses. + +Here's Ricardo's question. My response is below it. + +=============================================== +Let me introduce, I'm Ricardo Rezende and I'm SQL Magazine subeditor, from +Brazil (http://www.sqlmagazine.com.br.). + +My goal in this first contact is to solve a doubt about PostgreSQL RDBMS. + +I'm writing an article about redundant storage technology, called RAID. +The first part of the article can be found in +http://www.sqlmagazine.com.br/colunistas.asp?artigo=Colunistas/RicardoRezende/06_Raid_P1.asp + +My ideia is to put, in the end of the article, a note about the better +configuration of RAID to use with PostgreSQL and the reasons, including +the reference to the autor/link to this information. + +Could you send me this information? + +Our magazine is being a reference between DBAs and Database Developers in +Brazil and that is the reason to write "oficial" papers about PostgreSQL + +Thank you very much and I'm waiting for a return of this e-mail. +========================================================= + +The first and most important step for RAID performance with PostgreSQL is to +get a card with onboard battery back-up and enable the write cache for the +card. You do not want to enable the write cache *without* battery back-up +because of the risk of data corruption after a power failure. + +If you can't afford this hardware, I would advise using software RAID over +using a cheaper (< $300US) RAID card. + +The second step is to have lots of disks; 5 drives is a minimum for really +good performance. 3-drive RAID5, in particular, is a poor performer for +PostgreSQL, often resulting in I/O that is 40% or less as efficient as a +single disk due to extremely slow random seeks and little parallelization. + +Once you have 6 drives or more, opinions are divided on whether RAID 10 or +RAID 5 is better. I think it partly depends on your access pattern. + +-- +--Josh + +Josh Berkus +Aglio Database Solutions +San Francisco + +From pgsql-performance-owner@postgresql.org Thu Sep 16 19:07:57 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 7F871329CD9 + for ; + Thu, 16 Sep 2004 19:07:53 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 19206-07 + for ; + Thu, 16 Sep 2004 18:07:43 +0000 (GMT) +Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) + by svr1.postgresql.org (Postfix) with ESMTP id A23BD329CD2 + for ; + Thu, 16 Sep 2004 19:07:44 +0100 (BST) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i8GI7hTh029149; + Thu, 16 Sep 2004 14:07:43 -0400 (EDT) +To: Kevin Neufeld +Cc: pgsql-performance@postgresql.org +Subject: Re: declared cursor uses slow plan +In-reply-to: <4148A13E.4080207@refractions.net> +References: <4148A13E.4080207@refractions.net> +Comments: In-reply-to Kevin Neufeld + message dated "Wed, 15 Sep 2004 13:08:30 -0700" +Date: Thu, 16 Sep 2004 14:07:43 -0400 +Message-ID: <29148.1095358063@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/168 +X-Sequence-Number: 8296 + +Kevin Neufeld writes: +> I have a relatively simple query that takes about 150ms using explain +> analyze. However, when I wrap the same query in a declared cursor +> statement, the subsequent fetch statement takes almost 30seconds. For +> some reason, the planner decided to do a nested loop left join instead +> of a hash left join. Does anyone know why the planner would choose this +> course? + +Plans for cursors are optimized partly for startup speed as opposed to +total time, on the assumption that you'd rather get some of the rows +sooner so you can crunch on them. + +Probably there should be a knob you can fool with to adjust the strength +of the effect, but at present I think it's hard-wired. + +The real problem here of course is that the total cost of the nestloop +is being underestimated so badly (the estimate is only 5x more than the +hash join where reality is 200x more). It looks like this is mainly +because the number of matching rows from csn_waterbodies is badly +underestimated, which comes from the fact that we have no useful +statistics for geometric operators :-(. I think that the PostGIS crew +is working that problem but I have no idea how far along they are... + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Thu Sep 16 19:10:25 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 1AC94329D41 + for ; + Thu, 16 Sep 2004 19:10:24 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 22820-02 + for ; + Thu, 16 Sep 2004 18:10:14 +0000 (GMT) +Received: from omnis-mail.omnis.com (omnis-mail.omnis.com [216.239.128.28]) + by svr1.postgresql.org (Postfix) with ESMTP id 16E32329C67 + for ; + Thu, 16 Sep 2004 19:10:14 +0100 (BST) +Received: from [216.239.128.141] (daniel.omnis.com [216.239.128.141]) + by omnis-mail.omnis.com (Postfix) with ESMTP + id E68981BD16; Thu, 16 Sep 2004 11:10:13 -0700 (PDT) +Message-ID: <4149D705.7050900@omnis.com> +Date: Thu, 16 Sep 2004 11:10:13 -0700 +From: Daniel Ceregatti +Organization: Omnis Network +User-Agent: Mozilla Thunderbird 0.7.1 (X11/20040626) +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: pgsql-performance@postgresql.org +Cc: ricardo@sqlmagazine.com.br +Subject: Re: Article about PostgreSQL and RAID in Brazil +References: <200409161050.33289.josh@agliodbs.com> +In-Reply-To: <200409161050.33289.josh@agliodbs.com> +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/169 +X-Sequence-Number: 8297 + + +>The first part of the article can be found in +>http://www.sqlmagazine.com.br/colunistas.asp?artigo=Colunistas/RicardoRezende/06_Raid_P1.asp +> +> +The site seems to be down. I was looking forward to reading it. :( + +>The first and most important step for RAID performance with PostgreSQL is to +>get a card with onboard battery back-up and enable the write cache for the +>card. You do not want to enable the write cache *without* battery back-up +>because of the risk of data corruption after a power failure. +> +> +Here is a small example of the performance difference with write cache: + +http://sh.nu/bonnie.txt + +-- + +Daniel Ceregatti - Programmer +Omnis Network, LLC + +A little suffering is good for the soul. + -- Kirk, "The Corbomite Maneuver", stardate 1514.0 + + +From pgsql-performance-owner@postgresql.org Thu Sep 16 19:57:53 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 4FE3C329CBC + for ; + Thu, 16 Sep 2004 19:57:51 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 36138-05 + for ; + Thu, 16 Sep 2004 18:57:43 +0000 (GMT) +Received: from trofast.sesse.net (trofast.sesse.net [129.241.93.32]) + by svr1.postgresql.org (Postfix) with ESMTP id 35C2C329CD2 + for ; + Thu, 16 Sep 2004 19:57:42 +0100 (BST) +Received: from sesse by trofast.sesse.net with local (Exim 3.36 #1 (Debian)) + id 1C81Rk-0005hJ-00 + for ; Thu, 16 Sep 2004 20:57:32 +0200 +Date: Thu, 16 Sep 2004 20:57:32 +0200 +From: "Steinar H. Gunderson" +To: pgsql-performance@postgresql.org +Subject: Re: Article about PostgreSQL and RAID in Brazil +Message-ID: <20040916185732.GA21874@uio.no> +Mail-Followup-To: pgsql-performance@postgresql.org +References: <200409161050.33289.josh@agliodbs.com> + <4149D705.7050900@omnis.com> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <4149D705.7050900@omnis.com> +X-Operating-System: Linux 2.6.6 on a i686 +User-Agent: Mutt/1.5.6+20040818i +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/170 +X-Sequence-Number: 8298 + +On Thu, Sep 16, 2004 at 11:10:13AM -0700, Daniel Ceregatti wrote: +> Here is a small example of the performance difference with write cache: +> +> http://sh.nu/bonnie.txt + +Am I missing something here? I can't find any tests with the same machine +showing the difference between writeback and write-through -- one machine +always uses write-through and the other always uses writeback. (Yes, the +hardware looks more or less the same, but the kernels and systems are way +different.) + +/* Steinar */ +-- +Homepage: http://www.sesse.net/ + +From pgsql-performance-owner@postgresql.org Thu Sep 16 19:59:42 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id B052D329CBC + for ; + Thu, 16 Sep 2004 19:59:40 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 32144-08 + for ; + Thu, 16 Sep 2004 18:59:30 +0000 (GMT) +Received: from davinci.ethosmedia.com (server226.ethosmedia.com + [209.128.84.226]) + by svr1.postgresql.org (Postfix) with ESMTP id 0CECC329D83 + for ; + Thu, 16 Sep 2004 19:59:30 +0100 (BST) +Received: from [64.81.245.111] (account josh@agliodbs.com HELO + temoku.sf.agliodbs.com) + by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.1.8) + with ESMTP id 6361990; Thu, 16 Sep 2004 12:00:50 -0700 +From: Josh Berkus +Reply-To: josh@agliodbs.com +Organization: Aglio Database Solutions +To: Daniel Ceregatti +Subject: Re: Article about PostgreSQL and RAID in Brazil +Date: Thu, 16 Sep 2004 12:00:32 -0700 +User-Agent: KMail/1.6.2 +Cc: pgsql-performance@postgresql.org +References: <200409161050.33289.josh@agliodbs.com> + <4149D705.7050900@omnis.com> +In-Reply-To: <4149D705.7050900@omnis.com> +MIME-Version: 1.0 +Content-Disposition: inline +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +Message-Id: <200409161200.32427.josh@agliodbs.com> +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/171 +X-Sequence-Number: 8299 + +Primer, + +> The site seems to be down. I was looking forward to reading it. :( + +I didn't have a problem. The site *is* in Portuguese, though. + +-- +--Josh + +Josh Berkus +Aglio Database Solutions +San Francisco + +From pgsql-performance-owner@postgresql.org Thu Sep 16 20:02:01 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 06513329CBC + for ; + Thu, 16 Sep 2004 20:01:59 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 32146-10 + for ; + Thu, 16 Sep 2004 19:01:43 +0000 (GMT) +Received: from mail.3gstech.com (ns1.mcdownloads.com [216.239.132.98]) + by svr1.postgresql.org (Postfix) with ESMTP id E369F329C67 + for ; + Thu, 16 Sep 2004 20:01:43 +0100 (BST) +Received: from localhost (localhost.localdomain [127.0.0.1]) + by mail.3gstech.com (Postfix) with ESMTP id 88B6F9E76C4 + for ; + Thu, 16 Sep 2004 12:01:42 -0700 (PDT) +Received: from mail.3gstech.com ([127.0.0.1]) + by localhost (fungus [127.0.0.1]) (amavisd-new, port 10024) with ESMTP + id 09788-02 for ; + Thu, 16 Sep 2004 12:01:42 -0700 (PDT) +Received: from [216.239.128.141] (daniel.omnis.com [216.239.128.141]) + by mail.3gstech.com (Postfix) with ESMTP id 6F3369E76C2 + for ; + Thu, 16 Sep 2004 12:01:42 -0700 (PDT) +Message-ID: <4149E316.2050602@omnis.com> +Date: Thu, 16 Sep 2004 12:01:42 -0700 +From: Daniel Ceregatti +Organization: Omnis Network +User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; + rv:1.7.3) Gecko/20040916 MultiZilla/1.6.3.1a +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: pgsql-performance@postgresql.org +Subject: Re: Article about PostgreSQL and RAID in Brazil +References: <200409161050.33289.josh@agliodbs.com> + <4149D705.7050900@omnis.com> + <200409161200.32427.josh@agliodbs.com> +In-Reply-To: <200409161200.32427.josh@agliodbs.com> +X-Enigmail-Version: 0.86.0.0 +X-Enigmail-Supports: pgp-inline, pgp-mime +Content-Type: multipart/alternative; + boundary="------------040104000802060103090301" +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=1.4 tagged_above=0.0 required=5.0 tests=HTML_30_40, + HTML_MESSAGE, HTML_TITLE_EMPTY +X-Spam-Level: * +X-Archive-Number: 200409/172 +X-Sequence-Number: 8300 + +This is a multi-part message in MIME format. +--------------040104000802060103090301 +Content-Type: text/plain; charset=us-ascii +Content-Transfer-Encoding: 7bit + +Josh Berkus wrote: + +>Primer, +> +> +> +>>The site seems to be down. I was looking forward to reading it. :( +>> +>> +> +>I didn't have a problem. The site *is* in Portuguese, though. +> +> +> +Yes, it came up finally. Fortunately I'm Brazilian. :) + +-- + +Daniel Ceregatti - Programmer +Omnis Network, LLC + +Too clever is dumb. + -- Ogden Nash + + +--------------040104000802060103090301 +Content-Type: text/html; charset=us-ascii +Content-Transfer-Encoding: 7bit + + + + + + + + +Josh Berkus wrote: +
+
Primer,
+
+  
+
+
The site seems to be down. I was looking forward to reading it. :(
+    
+
+

+I didn't have a problem.   The site *is* in Portuguese, though.
+
+  
+
+Yes, it came up finally. Fortunately I'm Brazilian. :)
+
-- 
+
+Daniel Ceregatti - Programmer
+Omnis Network, LLC
+
+Too clever is dumb.
+		-- Ogden Nash
+
+ + + +--------------040104000802060103090301-- + +From pgsql-performance-owner@postgresql.org Sat Sep 18 15:11:29 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 44AD2329CE3 + for ; + Thu, 16 Sep 2004 21:11:10 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 65575-05 + for ; + Thu, 16 Sep 2004 20:10:46 +0000 (GMT) +Received: from leo.supplyfx.com (h-67-100-199-42.lsanca54.covad.net + [67.100.199.42]) + by svr1.postgresql.org (Postfix) with ESMTP id 04A3E329C6B + for ; + Thu, 16 Sep 2004 21:10:41 +0100 (BST) +Received: from [10.0.100.21] (leo6.supplyfx.com [10.0.100.21]) + by leo.supplyfx.com (Postfix) with ESMTP id B8F6E384FBF + for ; + Thu, 16 Sep 2004 13:10:40 -0700 (PDT) +Mime-Version: 1.0 (Apple Message framework v619) +In-Reply-To: <200409161200.32427.josh@agliodbs.com> +References: <200409161050.33289.josh@agliodbs.com> + <4149D705.7050900@omnis.com> + <200409161200.32427.josh@agliodbs.com> +Content-Type: text/plain; charset=US-ASCII; format=flowed +Message-Id: <7AFD0C05-081C-11D9-B278-000A95AB8896@supplyfx.com> +Content-Transfer-Encoding: 7bit +From: Qing Zhao +Subject: CPU maximized out! +Date: Thu, 16 Sep 2004 13:10:39 -0700 +To: 'Postgresql Performance' +X-Mailer: Apple Mail (2.619) +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/191 +X-Sequence-Number: 8319 + +Hi, there, + +I am running PostgreSQL 7.3.4 on MAC OS X G5 with dual processors and +8GB memory. The shared buffer was set as 512MB. + +The database has been running great until about 10 days ago when our +developers decided to add some indexes to some tables to speed up +certain uploading ops. + +Now the CPU usage reaches 100% constantly when there are a few users +accessing their information by SELECT tables in databases. If I REINEX +all the indexes, the database performance improves a bit but before +long, +it goes back to bad again. + +My suspicion is that since now a few indexes are added, every ops are +run by PostgreSQL with the indexes being used when calculating cost. +This leads to the downgrade of performance. + +What do you think of this? What is the possible solution? + +Thanks! + +Qing + +The following is the output from TOP command: + +Processes: 92 total, 4 running, 88 sleeping... 180 threads +13:09:18 +Load Avg: 2.81, 2.73, 2.50 CPU usage: 95.2% user, 4.8% sys, 0.0% +idle +SharedLibs: num = 116, resident = 11.5M code, 1.66M data, 4.08M +LinkEdit +MemRegions: num = 12132, resident = 148M + 2.82M private, 403M shared +PhysMem: 435M wired, 5.04G active, 2.22G inactive, 7.69G used, 316M +free +VM: 32.7G + 81.5M 5281127(13) pageins, 8544145(0) pageouts + + PID COMMAND %CPU TIME #TH #PRTS #MREGS RPRVT RSHRD RSIZE +VSIZE +27314 postgres 92.2% 2:14.75 1 9 49 12.8M+ 396M 75.0M+ +849M +26099 postgres 91.1% 19:28.04 1 9 67 15.9M+ 396M 298M+ +850M +24754 top 2.8% 4:48.33 1 29 26 272K 404K 648K +27.1M + 0 kernel_tas 1.9% 2:12:05 40 2 8476 67.1M 0K 281M +1.03G + 294 hwmond 0.5% 2:26:34 8 75 57 240K 544K 1.09M +31.0M + 347 lookupd 0.3% 1:52:28 2 35 73 3.05M 648K 3.14M +33.6M + 89 configd 0.1% 53:05.16 3 126 151 304K 644K 832K +29.2M +26774 servermgrd 0.1% 0:02.93 1 10 40 344K- 1.17M+ 1.86M +28.2M + 170 coreservic 0.1% 0:09.04 1 40 93 152K 532K 2.64M +28.5M + 223 DirectoryS 0.1% 19:42.47 8 84 135 880K+ 1.44M 4.60M+ +37.1M+ + 125 dynamic_pa 0.0% 0:26.79 1 12 17 16K 292K 28K +17.7M + 87 kextd 0.0% 0:01.23 2 17 21 0K 292K 36K +28.2M + 122 update 0.0% 14:27.71 1 9 15 16K 300K 44K +17.6M + 1 init 0.0% 0:00.03 1 12 16 28K 320K 76K +17.6M + 2 mach_init 0.0% 3:36.18 2 95 18 76K 320K 148K +18.2M + 81 syslogd 0.0% 0:19.96 1 10 17 96K 320K 148K +17.7M + + +From pgsql-performance-owner@postgresql.org Thu Sep 16 21:40:25 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 3B620329D7C + for ; + Thu, 16 Sep 2004 21:40:03 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 81419-05 + for ; + Thu, 16 Sep 2004 20:39:52 +0000 (GMT) +Received: from flake.decibel.org (flake.decibel.org [66.143.173.58]) + by svr1.postgresql.org (Postfix) with ESMTP id 81A31329D69 + for ; + Thu, 16 Sep 2004 21:39:52 +0100 (BST) +Received: by flake.decibel.org (Postfix, from userid 1001) + id 1F6F11C8B6; Thu, 16 Sep 2004 15:39:51 -0500 (CDT) +Date: Thu, 16 Sep 2004 15:39:51 -0500 +From: "Jim C. Nasby" +To: "J. Andrew Rogers" +Cc: pgsql-performance@postgresql.org +Subject: Re: Partitioning +Message-ID: <20040916203951.GE56059@decibel.org> +References: <20040914223333.GL56059@decibel.org> + + <60k6uw1cqa.fsf@dev6.int.libertyrms.info> + <4147C560.9060702@joeconway.com> + <1095282571.25123.181.camel@vulture.corp.neopolitan.com> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <1095282571.25123.181.camel@vulture.corp.neopolitan.com> +X-Operating-System: FreeBSD 4.10-RELEASE-p2 i386 +X-Distributed: Join the Effort! http://www.distributed.net +User-Agent: Mutt/1.5.6i +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/173 +X-Sequence-Number: 8301 + +On Wed, Sep 15, 2004 at 02:09:31PM -0700, J. Andrew Rogers wrote: +> On Tue, 2004-09-14 at 21:30, Joe Conway wrote: +> > That's exactly what we're doing, but using inherited tables instead of a +> > union view. With inheritance, there is no need to rebuild the view each +> > time a table is added or removed. Basically, in our application, tables +> > are partitioned by either month or week, depending on the type of data +> > involved, and queries are normally date qualified. +> +> +> +> We do something very similar, also using table inheritance and a lot of +> triggers to automatically generate partitions and so forth. It works +> pretty well, but it is a custom job every time I want to implement a +> partitioned table. You can save a lot on speed and space if you use it +> to break up large tables with composite indexes, since you can drop +> columns from the table depending on how you use it. A big part of + +Forgive my ignorance, but I didn't think you could have a table that +inherits from a parent not have all the columns. Or is that not what you +mean by 'you can drop columns from the table...'? + +This is one advantage I see to a big UNION ALL view; if you're doing +partitioning based on unique values, you don't actually have to store +that value in the partition tables. For example, +http://stats.distributed.net has a table that details how much work each +participant did each day for each project. Storing project_id in that +table is an extra 4 bytes... doesn't sound like much until you consider +that the table has over 130M rows right now. So it would be nice to have +an easy way to partition the table based on unique project_id's and not +waste space in the partition tables on a field that will be the same for +every row (in each partition). +-- +Jim C. Nasby, Database Consultant decibel@decibel.org +Give your computer some brain candy! www.distributed.net Team #1828 + +Windows: "Where do you want to go today?" +Linux: "Where do you want to go tomorrow?" +FreeBSD: "Are you guys coming, or what?" + +From pgsql-performance-owner@postgresql.org Thu Sep 16 21:44:17 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 3A739329D20 + for ; + Thu, 16 Sep 2004 21:44:09 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 84360-03 + for ; + Thu, 16 Sep 2004 20:43:58 +0000 (GMT) +Received: from leo.supplyfx.com (h-67-100-199-42.lsanca54.covad.net + [67.100.199.42]) + by svr1.postgresql.org (Postfix) with ESMTP id CA55E329D68 + for ; + Thu, 16 Sep 2004 21:43:58 +0100 (BST) +Received: from [10.0.100.21] (leo6.supplyfx.com [10.0.100.21]) + by leo.supplyfx.com (Postfix) with ESMTP id 037E53850F9 + for ; + Thu, 16 Sep 2004 13:43:58 -0700 (PDT) +Mime-Version: 1.0 (Apple Message framework v619) +In-Reply-To: <200409161200.32427.josh@agliodbs.com> +References: <200409161050.33289.josh@agliodbs.com> + <4149D705.7050900@omnis.com> + <200409161200.32427.josh@agliodbs.com> +Content-Type: text/plain; charset=US-ASCII; format=flowed +Message-Id: <224B107D-0821-11D9-B278-000A95AB8896@supplyfx.com> +Content-Transfer-Encoding: 7bit +From: Qing Zhao +Subject: Re: Article about PostgreSQL and RAID in Brazil +Date: Thu, 16 Sep 2004 13:43:58 -0700 +To: 'Postgresql Performance' +X-Mailer: Apple Mail (2.619) +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/174 +X-Sequence-Number: 8302 + + +Hi, there, + +I am running PostgreSQL 7.3.4 on MAC OS X G5 with dual processors and +8GB memory. The shared buffer was set as 512MB. + +The database has been running great until about 10 days ago when our +developers decided to add some indexes to some tables to speed up +certain uploading ops. + +Now the CPU usage reaches 100% constantly when there are a few users +accessing their information by SELECT tables in databases. If I REINEX +all the indexes, the database performance improves a bit but before +long, +it goes back to bad again. + +My suspicion is that since now a few indexes are added, every ops are +run by PostgreSQL with the indexes being used when calculating cost. +This leads to the downgrade of performance. + +What do you think of this? What is the possible solution? + +Thanks! + +Qing + +The following is the output from TOP command: + +Processes: 92 total, 4 running, 88 sleeping... 180 threads +13:09:18 +Load Avg: 2.81, 2.73, 2.50 CPU usage: 95.2% user, 4.8% sys, 0.0% +idle +SharedLibs: num = 116, resident = 11.5M code, 1.66M data, 4.08M +LinkEdit +MemRegions: num = 12132, resident = 148M + 2.82M private, 403M shared +PhysMem: 435M wired, 5.04G active, 2.22G inactive, 7.69G used, 316M +free +VM: 32.7G + 81.5M 5281127(13) pageins, 8544145(0) pageouts + + PID COMMAND %CPU TIME #TH #PRTS #MREGS RPRVT RSHRD RSIZE +VSIZE +27314 postgres 92.2% 2:14.75 1 9 49 12.8M+ 396M 75.0M+ +849M +26099 postgres 91.1% 19:28.04 1 9 67 15.9M+ 396M 298M+ +850M +24754 top 2.8% 4:48.33 1 29 26 272K 404K 648K +27.1M + 0 kernel_tas 1.9% 2:12:05 40 2 8476 67.1M 0K 281M +1.03G + 294 hwmond 0.5% 2:26:34 8 75 57 240K 544K 1.09M +31.0M + 347 lookupd 0.3% 1:52:28 2 35 73 3.05M 648K 3.14M +33.6M + 89 configd 0.1% 53:05.16 3 126 151 304K 644K 832K +29.2M +26774 servermgrd 0.1% 0:02.93 1 10 40 344K- 1.17M+ 1.86M +28.2M + 170 coreservic 0.1% 0:09.04 1 40 93 152K 532K 2.64M +28.5M + 223 DirectoryS 0.1% 19:42.47 8 84 135 880K+ 1.44M 4.60M+ +37.1M+ + 125 dynamic_pa 0.0% 0:26.79 1 12 17 16K 292K 28K +17.7M + 87 kextd 0.0% 0:01.23 2 17 21 0K 292K 36K +28.2M + 122 update 0.0% 14:27.71 1 9 15 16K 300K 44K +17.6M + 1 init 0.0% 0:00.03 1 12 16 28K 320K 76K +17.6M + 2 mach_init 0.0% 3:36.18 2 95 18 76K 320K 148K +18.2M + 81 syslogd 0.0% 0:19.96 1 10 17 96K 320K 148K +17.7M + + + + + +From pgsql-performance-owner@postgresql.org Thu Sep 16 21:49:14 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 019F9329D95; + Thu, 16 Sep 2004 21:49:04 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 87395-01; Thu, 16 Sep 2004 20:48:52 +0000 (GMT) +Received: from flake.decibel.org (flake.decibel.org [66.143.173.58]) + by svr1.postgresql.org (Postfix) with ESMTP id 65ADF329D83; + Thu, 16 Sep 2004 21:48:54 +0100 (BST) +Received: by flake.decibel.org (Postfix, from userid 1001) + id C97E71C8B7; Thu, 16 Sep 2004 15:48:53 -0500 (CDT) +Date: Thu, 16 Sep 2004 15:48:53 -0500 +From: "Jim C. Nasby" +To: Josh Berkus +Cc: ricardo@sqlmagazine.com.br, pgsql-performance@postgresql.org, + br@postgresql.org +Subject: Re: Article about PostgreSQL and RAID in Brazil +Message-ID: <20040916204853.GF56059@decibel.org> +References: <200409161050.33289.josh@agliodbs.com> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <200409161050.33289.josh@agliodbs.com> +X-Operating-System: FreeBSD 4.10-RELEASE-p2 i386 +X-Distributed: Join the Effort! http://www.distributed.net +User-Agent: Mutt/1.5.6i +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/175 +X-Sequence-Number: 8303 + +On Thu, Sep 16, 2004 at 10:50:33AM -0700, Josh Berkus wrote: +> The second step is to have lots of disks; 5 drives is a minimum for really +> good performance. 3-drive RAID5, in particular, is a poor performer for +> PostgreSQL, often resulting in I/O that is 40% or less as efficient as a +> single disk due to extremely slow random seeks and little parallelization. +> +> Once you have 6 drives or more, opinions are divided on whether RAID 10 or +> RAID 5 is better. I think it partly depends on your access pattern. + +What about benefits from putting WAL and pg_temp on seperate drives? +Specifically, we have a box with 8 drives, 2 in a mirror with the OS and +WAL and pg_temp; the rest in a raid10 with the database on it. Do you +think it would have been better to make one big raid10? What if it was +raid5? And what if it was only 6 drives total? +-- +Jim C. Nasby, Database Consultant decibel@decibel.org +Give your computer some brain candy! www.distributed.net Team #1828 + +Windows: "Where do you want to go today?" +Linux: "Where do you want to go tomorrow?" +FreeBSD: "Are you guys coming, or what?" + +From pgsql-performance-owner@postgresql.org Thu Sep 16 22:04:36 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id B77DA329D27 + for ; + Thu, 16 Sep 2004 22:04:33 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 91020-04 + for ; + Thu, 16 Sep 2004 21:04:25 +0000 (GMT) +Received: from davinci.ethosmedia.com (server226.ethosmedia.com + [209.128.84.226]) + by svr1.postgresql.org (Postfix) with ESMTP id 91E7A329D15 + for ; + Thu, 16 Sep 2004 22:04:27 +0100 (BST) +Received: from [64.81.245.111] (account josh@agliodbs.com HELO + temoku.sf.agliodbs.com) + by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.1.8) + with ESMTP id 6362549; Thu, 16 Sep 2004 14:05:47 -0700 +From: Josh Berkus +Reply-To: josh@agliodbs.com +Organization: Aglio Database Solutions +To: Qing Zhao +Subject: Re: Question about PG on OSX +Date: Thu, 16 Sep 2004 14:05:28 -0700 +User-Agent: KMail/1.6.2 +Cc: 'Postgresql Performance' +References: <200409161050.33289.josh@agliodbs.com> + <200409161200.32427.josh@agliodbs.com> + <224B107D-0821-11D9-B278-000A95AB8896@supplyfx.com> +In-Reply-To: <224B107D-0821-11D9-B278-000A95AB8896@supplyfx.com> +MIME-Version: 1.0 +Content-Disposition: inline +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +Message-Id: <200409161405.28778.josh@agliodbs.com> +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/176 +X-Sequence-Number: 8304 + +Qing, + +Please don't start a new question by replying to someone else's e-mail. It +confuses people and makes it unlikely for you to get help. + +> My suspicion is that since now a few indexes are added, every ops are +> run by PostgreSQL with the indexes being used when calculating cost. +> This leads to the downgrade of performance. + +That seems rather unlikely to me. Unless you've *really* complex queries +and some unusual settings, you can't swamp the CPU through query planning. + +On the other hand, your mention of REINDEX indicates that the table is being +updated very frequently. If that's the case, then the solution is probably +for you to cut back on the number of indexes. + +-- +--Josh + +Josh Berkus +Aglio Database Solutions +San Francisco + +From pgsql-performance-owner@postgresql.org Thu Sep 16 22:06:47 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 70FB7329D68; + Thu, 16 Sep 2004 22:06:45 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 88175-10; Thu, 16 Sep 2004 21:06:34 +0000 (GMT) +Received: from davinci.ethosmedia.com (server226.ethosmedia.com + [209.128.84.226]) + by svr1.postgresql.org (Postfix) with ESMTP id 05BD4329D15; + Thu, 16 Sep 2004 22:06:35 +0100 (BST) +Received: from [64.81.245.111] (account josh@agliodbs.com HELO + temoku.sf.agliodbs.com) + by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.1.8) + with ESMTP id 6362562; Thu, 16 Sep 2004 14:07:56 -0700 +From: Josh Berkus +Reply-To: josh@agliodbs.com +Organization: Aglio Database Solutions +To: "Jim C. Nasby" +Subject: Re: Article about PostgreSQL and RAID in Brazil +Date: Thu, 16 Sep 2004 14:07:37 -0700 +User-Agent: KMail/1.6.2 +Cc: ricardo@sqlmagazine.com.br, pgsql-performance@postgresql.org, + br@postgresql.org +References: <200409161050.33289.josh@agliodbs.com> + <20040916204853.GF56059@decibel.org> +In-Reply-To: <20040916204853.GF56059@decibel.org> +MIME-Version: 1.0 +Content-Disposition: inline +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +Message-Id: <200409161407.37669.josh@agliodbs.com> +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/177 +X-Sequence-Number: 8305 + +Jim, + +> What about benefits from putting WAL and pg_temp on seperate drives? +> Specifically, we have a box with 8 drives, 2 in a mirror with the OS and +> WAL and pg_temp; the rest in a raid10 with the database on it. Do you +> think it would have been better to make one big raid10? What if it was +> raid5? And what if it was only 6 drives total? + +OSDL's finding was that even with a large RAID array, it still benefits you to +have WAL on a seperate disk resource ... substantially, like 10% total +performance. However, your setup doesn't get the full possible benefit, +since WAL is sharing the array with other resources. + +-- +--Josh + +Josh Berkus +Aglio Database Solutions +San Francisco + +From pgsql-performance-owner@postgresql.org Thu Sep 16 22:20:43 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 7AB8E329D8C + for ; + Thu, 16 Sep 2004 22:20:40 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 96057-05 + for ; + Thu, 16 Sep 2004 21:20:29 +0000 (GMT) +Received: from leo.supplyfx.com (h-67-100-199-42.lsanca54.covad.net + [67.100.199.42]) + by svr1.postgresql.org (Postfix) with ESMTP id 5104B329D7C + for ; + Thu, 16 Sep 2004 22:20:30 +0100 (BST) +Received: from [10.0.100.21] (leo6.supplyfx.com [10.0.100.21]) + by leo.supplyfx.com (Postfix) with ESMTP + id 060673852A8; Thu, 16 Sep 2004 14:20:30 -0700 (PDT) +In-Reply-To: <200409161405.28778.josh@agliodbs.com> +References: <200409161050.33289.josh@agliodbs.com> + <200409161200.32427.josh@agliodbs.com> + <224B107D-0821-11D9-B278-000A95AB8896@supplyfx.com> + <200409161405.28778.josh@agliodbs.com> +Mime-Version: 1.0 (Apple Message framework v619) +Content-Type: text/plain; charset=US-ASCII; format=flowed +Message-Id: <3C40F514-0826-11D9-B278-000A95AB8896@supplyfx.com> +Content-Transfer-Encoding: 7bit +Cc: 'Postgresql Performance' +From: Qing Zhao +Subject: indexes make other queries slow! +Date: Thu, 16 Sep 2004 14:20:29 -0700 +To: josh@agliodbs.com +X-Mailer: Apple Mail (2.619) +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/178 +X-Sequence-Number: 8306 + +Josh: + +Sorry for the reply to the existing subject! + +The newly added indexes have made all other queries much slower except +the uploading ops. +As a result, all the CPU's are running crazy but not much is getting +finished and our Application +Server waits for certain time and then times out. Customers thought the +system hung. + +My guess is that all the queries that involves the columns that are +being indexed need to +be rewritten to use the newly created indexes to avoid the performance +issues. The reason +is that REINDEX does not help either. Does it make sense? + +Thanks! + +Qing + +On Sep 16, 2004, at 2:05 PM, Josh Berkus wrote: + +> Qing, +> +> Please don't start a new question by replying to someone else's +> e-mail. It +> confuses people and makes it unlikely for you to get help. +> +>> My suspicion is that since now a few indexes are added, every ops are +>> run by PostgreSQL with the indexes being used when calculating cost. +>> This leads to the downgrade of performance. +> +> That seems rather unlikely to me. Unless you've *really* complex +> queries +> and some unusual settings, you can't swamp the CPU through query +> planning. +> +> On the other hand, your mention of REINDEX indicates that the table is +> being +> updated very frequently. If that's the case, then the solution is +> probably +> for you to cut back on the number of indexes. +> +> -- +> --Josh +> +> Josh Berkus +> Aglio Database Solutions +> San Francisco +> + + +From pgsql-performance-owner@postgresql.org Thu Sep 16 22:23:38 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 1815A329D15 + for ; + Thu, 16 Sep 2004 22:23:36 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 98914-02 + for ; + Thu, 16 Sep 2004 21:23:24 +0000 (GMT) +Received: from davinci.ethosmedia.com (server226.ethosmedia.com + [209.128.84.226]) + by svr1.postgresql.org (Postfix) with ESMTP id C57CF329D87 + for ; + Thu, 16 Sep 2004 22:23:25 +0100 (BST) +Received: from [64.81.245.111] (account josh@agliodbs.com HELO + temoku.sf.agliodbs.com) + by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.1.8) + with ESMTP id 6362637; Thu, 16 Sep 2004 14:24:46 -0700 +From: Josh Berkus +Reply-To: josh@agliodbs.com +Organization: Aglio Database Solutions +To: Qing Zhao +Subject: Re: indexes make other queries slow! +Date: Thu, 16 Sep 2004 14:24:28 -0700 +User-Agent: KMail/1.6.2 +Cc: 'Postgresql Performance' +References: <200409161050.33289.josh@agliodbs.com> + <200409161405.28778.josh@agliodbs.com> + <3C40F514-0826-11D9-B278-000A95AB8896@supplyfx.com> +In-Reply-To: <3C40F514-0826-11D9-B278-000A95AB8896@supplyfx.com> +MIME-Version: 1.0 +Content-Disposition: inline +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +Message-Id: <200409161424.28644.josh@agliodbs.com> +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/179 +X-Sequence-Number: 8307 + +Qing, + +> My guess is that all the queries that involves the columns that are +> being indexed need to +> be rewritten to use the newly created indexes to avoid the performance +> issues. The reason +> is that REINDEX does not help either. Does it make sense? + +What's the rate of updates on the newly indexed tables? If you have a lot +of updates, the work that the database does to keep the indexes current would +put a big load on your server. This is far more likely to be the cause of +your issues. + +-- +--Josh + +Josh Berkus +Aglio Database Solutions +San Francisco + +From pgsql-performance-owner@postgresql.org Thu Sep 16 22:37:04 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 6DB8B329D86 + for ; + Thu, 16 Sep 2004 22:37:02 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 99563-07 + for ; + Thu, 16 Sep 2004 21:36:46 +0000 (GMT) +Received: from ms-smtp-03.nyroc.rr.com (ms-smtp-03.nyroc.rr.com [24.24.2.57]) + by svr1.postgresql.org (Postfix) with ESMTP id 34C3F329DB3 + for ; + Thu, 16 Sep 2004 22:36:46 +0100 (BST) +Received: from jcoene2 (roc-66-66-153-192.rochester.rr.com [66.66.153.192]) + by ms-smtp-03.nyroc.rr.com (8.12.10/8.12.10) with ESMTP id + i8GLagv2015192; Thu, 16 Sep 2004 17:36:43 -0400 (EDT) +Message-Id: <200409162136.i8GLagv2015192@ms-smtp-03.nyroc.rr.com> +From: "Jason Coene" +To: "'Qing Zhao'" +Cc: "'Postgresql Performance'" +Subject: Re: indexes make other queries slow! +Date: Thu, 16 Sep 2004 17:36:46 -0400 +MIME-Version: 1.0 +Content-Type: text/plain; + charset="us-ascii" +Content-Transfer-Encoding: 7bit +X-Mailer: Microsoft Office Outlook, Build 11.0.5510 +In-Reply-To: <3C40F514-0826-11D9-B278-000A95AB8896@supplyfx.com> +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 +Thread-Index: AcScMzFxiaDg/rezQgS+W+tPMz4wawAAFyvA +X-Virus-Scanned: Symantec AntiVirus Scan Engine +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/180 +X-Sequence-Number: 8308 + +> My guess is that all the queries that involves the columns that are +> being indexed need to +> be rewritten to use the newly created indexes to avoid the performance +> issues. The reason +> is that REINDEX does not help either. Does it make sense? +> + +Qing, + +Generally, adding new indexes blindly will hurt performance, not help it. + +More indexes mean more work during INSERT/UPDATE. That could easily be +hampering your performance if you have a high INSERT/UPDATE volume. + +Run your queries through EXPLAIN ANALYZE to make sure they're using the +right indexes. Take a look at the pg_stat_user_indexes table to see what +indexes are simply not being used. + +Jason + + +From pgsql-performance-owner@postgresql.org Thu Sep 16 22:59:51 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id ECF14329E32 + for ; + Thu, 16 Sep 2004 22:59:25 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 09486-01 + for ; + Thu, 16 Sep 2004 21:59:14 +0000 (GMT) +Received: from mx1.neopolitan.us (mx1.neopolitan.us [65.87.16.224]) + by svr1.postgresql.org (Postfix) with ESMTP id 245A5329D41 + for ; + Thu, 16 Sep 2004 22:59:12 +0100 (BST) +Received: from [65.87.16.98] (HELO vulture.corp.neopolitan.com) + by mx1.neopolitan.us (CommuniGate Pro SMTP 4.1.8) + with ESMTP-TLS id 5881885; Thu, 16 Sep 2004 14:59:12 -0700 +Subject: Re: Partitioning +From: "J. Andrew Rogers" +To: "Jim C. Nasby" +Cc: pgsql-performance@postgresql.org +In-Reply-To: <20040916203951.GE56059@decibel.org> +References: <20040914223333.GL56059@decibel.org> + + <60k6uw1cqa.fsf@dev6.int.libertyrms.info> + <4147C560.9060702@joeconway.com> + <1095282571.25123.181.camel@vulture.corp.neopolitan.com> + <20040916203951.GE56059@decibel.org> +Content-Type: text/plain +Organization: +Message-Id: <1095371952.28387.73.camel@vulture.corp.neopolitan.com> +Mime-Version: 1.0 +X-Mailer: Ximian Evolution 1.2.2 (1.2.2-5) +Date: 16 Sep 2004 14:59:12 -0700 +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/181 +X-Sequence-Number: 8309 + +On Thu, 2004-09-16 at 13:39, Jim C. Nasby wrote: +> Forgive my ignorance, but I didn't think you could have a table that +> inherits from a parent not have all the columns. Or is that not what you +> mean by 'you can drop columns from the table...'? +> +> This is one advantage I see to a big UNION ALL view; if you're doing +> partitioning based on unique values, you don't actually have to store +> that value in the partition tables. For example, +> http://stats.distributed.net has a table that details how much work each +> participant did each day for each project. Storing project_id in that +> table is an extra 4 bytes... doesn't sound like much until you consider +> that the table has over 130M rows right now. So it would be nice to have +> an easy way to partition the table based on unique project_id's and not +> waste space in the partition tables on a field that will be the same for +> every row (in each partition). + + +Yeah, it is harder to do this automagically, though in theory it should +be possible. Since we have to roll our own partitioning anyway, we've +broken up composite primary keys so that one of the key columns hashes +to a partition, using the key itself in the partition table name rather +than replicating that value several million times. Ugly as sin, but you +can make it work in some cases. + +I do just enough work for our queries to behave correctly, and a lot of +times I actually hide the base table and its descendents underneath a +sort of metadata table that is grafted to the base tables by a lot of +rules/triggers/functions/etc, and then do queries against that or a view +of that. As I said, ugly as sin and probably not universal, but you need +a lot of abstraction to make it look halfway normal. I'm going to think +about this some more and see if I can't construct a generic solution. + + +cheers, + +j. andrew rogers + + + +From pgsql-performance-owner@postgresql.org Thu Sep 16 23:20:03 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 79B1E329D69; + Thu, 16 Sep 2004 23:19:57 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 13441-07; Thu, 16 Sep 2004 22:19:45 +0000 (GMT) +Received: from flake.decibel.org (flake.decibel.org [66.143.173.58]) + by svr1.postgresql.org (Postfix) with ESMTP id 00D96329D20; + Thu, 16 Sep 2004 23:19:44 +0100 (BST) +Received: by flake.decibel.org (Postfix, from userid 1001) + id AF89F1C8B6; Thu, 16 Sep 2004 17:19:43 -0500 (CDT) +Date: Thu, 16 Sep 2004 17:19:43 -0500 +From: "Jim C. Nasby" +To: Josh Berkus +Cc: ricardo@sqlmagazine.com.br, pgsql-performance@postgresql.org, + br@postgresql.org +Subject: Re: Article about PostgreSQL and RAID in Brazil +Message-ID: <20040916221943.GJ56059@decibel.org> +References: <200409161050.33289.josh@agliodbs.com> + <20040916204853.GF56059@decibel.org> + <200409161407.37669.josh@agliodbs.com> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <200409161407.37669.josh@agliodbs.com> +X-Operating-System: FreeBSD 4.10-RELEASE-p2 i386 +X-Distributed: Join the Effort! http://www.distributed.net +User-Agent: Mutt/1.5.6i +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/182 +X-Sequence-Number: 8310 + +On Thu, Sep 16, 2004 at 02:07:37PM -0700, Josh Berkus wrote: +> Jim, +> +> > What about benefits from putting WAL and pg_temp on seperate drives? +> > Specifically, we have a box with 8 drives, 2 in a mirror with the OS and +> > WAL and pg_temp; the rest in a raid10 with the database on it. Do you +> > think it would have been better to make one big raid10? What if it was +> > raid5? And what if it was only 6 drives total? +> +> OSDL's finding was that even with a large RAID array, it still benefits you to +> have WAL on a seperate disk resource ... substantially, like 10% total +> performance. However, your setup doesn't get the full possible benefit, +> since WAL is sharing the array with other resources. + +Yes, but if a 3 drive raid array is 40% slower than a single disk it +seems like the 10% benefit for having WAL on a seperate drive would +still be a losing proposition. + +BTW, my experience with our setup is that the raid10 is almost always +the IO bottleneck, and not the mirror with everything else on it. +-- +Jim C. Nasby, Database Consultant decibel@decibel.org +Give your computer some brain candy! www.distributed.net Team #1828 + +Windows: "Where do you want to go today?" +Linux: "Where do you want to go tomorrow?" +FreeBSD: "Are you guys coming, or what?" + +From pgsql-performance-owner@postgresql.org Fri Sep 17 00:00:44 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 8EABD329E39 + for ; + Fri, 17 Sep 2004 00:00:26 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 25620-05 + for ; + Thu, 16 Sep 2004 23:00:22 +0000 (GMT) +Received: from mail0.rawbw.com (mail0.rawbw.com [198.144.192.41]) + by svr1.postgresql.org (Postfix) with ESMTP id 6768B329E23 + for ; + Fri, 17 Sep 2004 00:00:23 +0100 (BST) +Received: (from www@localhost) + by mail0.rawbw.com (8.11.6p2/8.11.6) id i8GN0Jo27977; + Thu, 16 Sep 2004 16:00:19 -0700 (PDT) +Received: from cybs-gw.ic3.com (cybs-gw.ic3.com [66.185.177.10]) + by webmail.rawbw.com (IMP) with HTTP + for ; Thu, 16 Sep 2004 16:00:19 -0700 +Message-ID: <1095375619.414a1b034ba63@webmail.rawbw.com> +Date: Thu, 16 Sep 2004 16:00:19 -0700 +From: mudfoot@rawbw.com +To: josh@agliodbs.com +Cc: pgsql-performance@postgresql.org +Subject: Re: Article about PostgreSQL and RAID in Brazil +References: <200409161050.33289.josh@agliodbs.com> +In-Reply-To: <200409161050.33289.josh@agliodbs.com> +MIME-Version: 1.0 +Content-Type: text/plain; charset=ISO-8859-1 +Content-Transfer-Encoding: 8bit +User-Agent: Internet Messaging Program (IMP) 3.2.1 +X-Originating-IP: 66.185.177.10 +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.3 tagged_above=0.0 required=5.0 tests=NO_REAL_NAME +X-Spam-Level: +X-Archive-Number: 200409/183 +X-Sequence-Number: 8311 + +Quoting Josh Berkus : + +> The first and most important step for RAID performance with PostgreSQL is to +> +> get a card with onboard battery back-up and enable the write cache for the +> card. You do not want to enable the write cache *without* battery back-up +> + +I'm curious about this -- how do you avoid losing data if a cache stick dies? +Without redundancy, whatever hasn't been destaged to the physical media vanishes + Dual-controller external arrays (HDS, EMC, LSI, etc.) tend to mirror (though +algorithms vary) the cache in addition to battery backup. But do onboard arrays +tend to do this as well? + +Mark + +From pgsql-performance-owner@postgresql.org Fri Sep 17 02:51:35 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id ACDCD329DFC + for ; + Fri, 17 Sep 2004 02:51:25 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 64269-05 + for ; + Fri, 17 Sep 2004 01:51:13 +0000 (GMT) +Received: from mproxy.gmail.com (rproxy.gmail.com [64.233.170.201]) + by svr1.postgresql.org (Postfix) with ESMTP id 81CE9329DB1 + for ; + Fri, 17 Sep 2004 02:51:15 +0100 (BST) +Received: by mproxy.gmail.com with SMTP id v30so107836rnb + for ; + Thu, 16 Sep 2004 18:51:11 -0700 (PDT) +Received: by 10.38.8.54 with SMTP id 54mr202461rnh; + Thu, 16 Sep 2004 18:51:11 -0700 (PDT) +Received: by 10.38.8.79 with HTTP; Thu, 16 Sep 2004 18:51:11 -0700 (PDT) +Message-ID: <3f71fdf1040916185113e277e6@mail.gmail.com> +Date: Thu, 16 Sep 2004 20:51:11 -0500 +From: Stephen Crowley +Reply-To: Stephen Crowley +To: pgsql-performance@postgresql.org +Subject: Re: Large # of rows in query extremely slow, not using +Cc: =?ISO-8859-1?Q?Pierre-Fr=E9d=E9ric_Caillaud?= + +In-Reply-To: +Mime-Version: 1.0 +Content-Type: text/plain; charset=ISO-8859-1 +Content-Transfer-Encoding: quoted-printable +References: <3f71fdf104091317515c756512@mail.gmail.com> + <20040914184358.08e271fe@kingfisher.intern.logi-track.com> + +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/184 +X-Sequence-Number: 8312 + +Here are some results of explain analyze, I've included the LIMIT 10 +because otherwise the resultset would exhaust all available memory. + + +explain analyze select * from history where date=3D'2004-09-07' and +stock=3D'ORCL' LIMIT 10; + +"Limit (cost=3D0.00..17.92 rows=3D10 width=3D83) (actual +time=3D1612.000..1702.000 rows=3D10 loops=3D1)" +" -> Index Scan using island_history_date_stock_time on +island_history (cost=3D0.00..183099.72 rows=3D102166 width=3D83) (actual +time=3D1612.000..1702.000 rows=3D10 loops=3D1)" +" Index Cond: ((date =3D '2004-09-07'::date) AND ((stock)::text =3D +'ORCL'::text))" +"Total runtime: 1702.000 ms" + + +Ok, so for 100,000 rows it decides to use the index and returns very +quicktly.. now for + + explain analyze select * from history where date=3D'2004-09-07' and +stock=3D'MSFT' LIMIT 10; + +"Limit (cost=3D0.00..14.30 rows=3D10 width=3D83) (actual +time=3D346759.000..346759.000 rows=3D10 loops=3D1)" +" -> Seq Scan on island_history (cost=3D0.00..417867.13 rows=3D292274 +width=3D83) (actual time=3D346759.000..346759.000 rows=3D10 loops=3D1)" +" Filter: ((date =3D '2004-09-07'::date) AND ((stock)::text =3D +'MSFT'::text))" +"Total runtime: 346759.000 ms" + +Nearly 8 minutes.. Why would it take this long? Is there anything else +I can do to debug this? + +When I set enable_seqscan to OFF and force everything to use the index +every stock I query returns within 100ms, but turn seqscan back ON and +its back up to taking several minutes for non-index using plans. + +Any ideas? +--Stephen + + +On Tue, 14 Sep 2004 21:27:55 +0200, Pierre-Fr=E9d=E9ric Caillaud + wrote: +>=20 +> >> I have a table with ~8 million rows and I am executing a query which +> >> should return about ~800,000 rows. The problem is that as soon as I +> >> execute the query it absolutely kills my machine and begins swapping +> >> for 5 or 6 minutes before it begins returning results. Is postgres +> >> trying to load the whole query into memory before returning anything? +> >> Also, why would it choose not to use the index? It is properly +> >> estimating the # of rows returned. If I set enable_seqscan to off it +> >> is just as slow. +>=20 +> 1; EXPLAIN ANALYZE. +>=20 +> Note the time it takes. It should not swap, just read data from t= +he disk +> (and not kill the machine). + +From pgsql-performance-owner@postgresql.org Fri Sep 17 04:14:46 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 86B18329D87 + for ; + Fri, 17 Sep 2004 04:14:27 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 80763-10 + for ; + Fri, 17 Sep 2004 03:14:26 +0000 (GMT) +Received: from hosting.commandprompt.com (128.commandprompt.com + [207.173.200.128]) + by svr1.postgresql.org (Postfix) with ESMTP id B1D7C329D15 + for ; + Fri, 17 Sep 2004 04:14:25 +0100 (BST) +Received: from [192.168.1.51] (dsl093-038-087.pdx1.dsl.speakeasy.net + [66.93.38.87]) (authenticated) + by hosting.commandprompt.com (8.11.6/8.11.6) with ESMTP id i8H3EE701490; + Thu, 16 Sep 2004 20:14:15 -0700 +Message-ID: <414A5688.1030701@commandprompt.com> +Date: Thu, 16 Sep 2004 20:14:16 -0700 +From: "Joshua D. Drake" +Organization: Command Prompt, Inc. +User-Agent: Mozilla Thunderbird 0.8 (X11/20040913) +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: Stephen Crowley +Cc: pgsql-performance@postgresql.org, + =?ISO-8859-1?Q?Pierre-Fr=E9d=E9ric?= =?ISO-8859-1?Q?_Caillaud?= + +Subject: Re: Large # of rows in query extremely slow, not using +References: <3f71fdf104091317515c756512@mail.gmail.com> + <20040914184358.08e271fe@kingfisher.intern.logi-track.com> + + <3f71fdf1040916185113e277e6@mail.gmail.com> +In-Reply-To: <3f71fdf1040916185113e277e6@mail.gmail.com> +Content-Type: multipart/mixed; boundary="------------060808040209000905090708" +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.9 tagged_above=0.0 required=5.0 tests=RAZOR2_CHECK +X-Spam-Level: +X-Archive-Number: 200409/185 +X-Sequence-Number: 8313 + +This is a multi-part message in MIME format. +--------------060808040209000905090708 +Content-Type: text/plain; charset=ISO-8859-1; format=flowed +Content-Transfer-Encoding: quoted-printable + +> When I set enable_seqscan to OFF and force everything to use the index +> every stock I query returns within 100ms, but turn seqscan back ON and +> its back up to taking several minutes for non-index using plans. +>=20 +> Any ideas? +> --Stephen + +Try increasing your statistics target and re-running analyze. Try say 100? + +Sincerely, + +Joshua D. Drake + + + + +>=20 +>=20 +> On Tue, 14 Sep 2004 21:27:55 +0200, Pierre-Fr=E9d=E9ric Caillaud +> wrote: +>=20 +>>>>I have a table with ~8 million rows and I am executing a query which +>>>>should return about ~800,000 rows. The problem is that as soon as I +>>>>execute the query it absolutely kills my machine and begins swapping +>>>>for 5 or 6 minutes before it begins returning results. Is postgres +>>>>trying to load the whole query into memory before returning anything? +>>>>Also, why would it choose not to use the index? It is properly +>>>>estimating the # of rows returned. If I set enable_seqscan to off it +>>>>is just as slow. +>> +>> 1; EXPLAIN ANALYZE. +>> +>> Note the time it takes. It should not swap, just read data from t= +he disk +>>(and not kill the machine). +>=20 +>=20 +> ---------------------------(end of broadcast)--------------------------- +> TIP 9: the planner will ignore your desire to choose an index scan if your +> joining column's datatypes do not match + + +--=20 +Command Prompt, Inc., home of Mammoth PostgreSQL - S/ODBC and S/JDBC +Postgresql support, programming shared hosting and dedicated hosting. ++1-503-667-4564 - jd@commandprompt.com - http://www.commandprompt.com +Mammoth PostgreSQL Replicator. Integrated Replication for PostgreSQL + +--------------060808040209000905090708 +Content-Type: text/x-vcard; charset=utf-8; + name="jd.vcf" +Content-Transfer-Encoding: 7bit +Content-Disposition: attachment; + filename="jd.vcf" + +begin:vcard +fn:Joshua D. Drake +n:Drake;Joshua D. +org:Command Prompt, Inc. +adr:;;PO Box 215;Cascade Locks;Oregon;97014;USA +email;internet:jd@commandprompt.com +title:Consultant +tel;work:503-667-4564 +tel;fax:503-210-0334 +note:Command Prompt, Inc. is the largest and oldest US based commercial PostgreSQL support provider. We provide the only commercially viable integrated PostgreSQL replication solution, but also custom programming, and support. We authored the book Practical PostgreSQL, the procedural language plPHP, and adding trigger capability to plPerl. +x-mozilla-html:FALSE +url:http://www.commandprompt.com/ +version:2.1 +end:vcard + + +--------------060808040209000905090708-- + +From pgsql-performance-owner@postgresql.org Fri Sep 17 08:24:02 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id E9AD1329D3B + for ; + Fri, 17 Sep 2004 08:24:00 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 47323-02 + for ; + Fri, 17 Sep 2004 07:23:50 +0000 (GMT) +Received: from cmailg2.svr.pol.co.uk (cmailg2.svr.pol.co.uk [195.92.195.172]) + by svr1.postgresql.org (Postfix) with ESMTP id B1BBE329D15 + for ; + Fri, 17 Sep 2004 08:23:50 +0100 (BST) +Received: from modem-573.lion.dialup.pol.co.uk ([217.135.162.61] + helo=happyplace) by cmailg2.svr.pol.co.uk with smtp (Exim 4.14) + id 1C8D5s-0004SK-2P; Fri, 17 Sep 2004 08:23:44 +0100 +From: "Simon Riggs" +To: "Iain" , "Joe Conway" , + "Christopher Browne" +Cc: +Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres -- +Date: Fri, 17 Sep 2004 08:39:10 +0100 +Message-ID: +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +X-Priority: 3 (Normal) +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) +In-Reply-To: <00fb01c49bcc$c08dd210$7201a8c0@mst1x5r347kymb> +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 +Importance: Normal +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/186 +X-Sequence-Number: 8314 + +> Iain +> Joe's example wasn't excluding partions, as he didn't use a +> predicated UNION +> ALL view to select from. His queries use an indexed column that allow the +> various partitions to be probed at low cost, and he was satisfied +> wth that. + +Agreed - very very interesting design though. + +> My point in my previous post was that you could still do all that that if +> you wanted to, by building the predicated view with UNION ALL of +> each of the +> child tables. +> + +AFAICS of all the designs proposed there is still only one design *using +current PostgreSQL* that allows partitions to be excluded from queries as a +way of speeding up queries against very large tables: UNION ALL with +appended constants. + +Best Regards, Simon Riggs + + +From pgsql-performance-owner@postgresql.org Sun Sep 19 19:57:44 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 221D2329E76 + for ; + Sun, 19 Sep 2004 19:57:38 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 81191-04 + for ; + Sun, 19 Sep 2004 18:57:32 +0000 (GMT) +Received: from davinci.ethosmedia.com (server226.ethosmedia.com + [209.128.84.226]) + by svr1.postgresql.org (Postfix) with ESMTP id 96F73329E73 + for ; + Sun, 19 Sep 2004 19:57:33 +0100 (BST) +Received: from [63.195.55.98] (account josh@agliodbs.com HELO spooky) + by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.1.8) + with ESMTP id 6377718; Sun, 19 Sep 2004 11:58:49 -0700 +From: Josh Berkus +Organization: Aglio Database Solutions +To: Stephen Crowley , + pgsql-performance@postgresql.org +Subject: Re: Large # of rows in query extremely slow, not using +Date: Fri, 17 Sep 2004 10:40:18 -0700 +User-Agent: KMail/1.6.2 +References: <3f71fdf104091317515c756512@mail.gmail.com> + + <3f71fdf1040916185113e277e6@mail.gmail.com> +In-Reply-To: <3f71fdf1040916185113e277e6@mail.gmail.com> +MIME-Version: 1.0 +Content-Disposition: inline +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +Message-Id: <200409171040.18830.josh@agliodbs.com> +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/201 +X-Sequence-Number: 8329 + +Stephen, + +> " -> Seq Scan on island_history (cost=0.00..417867.13 rows=292274 +> width=83) (actual time=346759.000..346759.000 rows=10 loops=1)" + +Take a look at your row comparisons. When was the last time you ran ANALYZE? + +-- +Josh Berkus +Aglio Database Solutions +San Francisco + +From pgsql-performance-owner@postgresql.org Sat Sep 18 15:11:53 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 3D061329D69 + for ; + Fri, 17 Sep 2004 20:37:43 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 89244-07 + for ; + Fri, 17 Sep 2004 19:37:33 +0000 (GMT) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by svr1.postgresql.org (Postfix) with ESMTP id 081E7329CE3 + for ; + Fri, 17 Sep 2004 20:37:34 +0100 (BST) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by news.hub.org (8.12.9/8.12.9) with ESMTP id i8HJbWCn090306 + for ; Fri, 17 Sep 2004 19:37:32 GMT + (envelope-from news@news.hub.org) +Received: (from news@localhost) + by news.hub.org (8.12.9/8.12.9/Submit) id i8HJN7vO085814 + for pgsql-performance@postgresql.org; Fri, 17 Sep 2004 19:23:07 GMT +From: Mischa Sandberg +Reply-To: ischamay.andbergsay@activestateway.com +User-Agent: Mozilla Thunderbird 0.7.3 (X11/20040803) +X-Accept-Language: en-us, en +MIME-Version: 1.0 +X-Newsgroups: comp.databases.postgresql.performance +Subject: Tryint to match Solaris-Oracle performance with directio? +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit +Lines: 31 +Message-ID: +Date: Fri, 17 Sep 2004 19:23:08 GMT +To: pgsql-performance@postgresql.org +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, + hits=1.1 tagged_above=0.0 required=5.0 tests=NO_DNS_FOR_FROM +X-Spam-Level: * +X-Archive-Number: 200409/192 +X-Sequence-Number: 8320 + +Our product (Sophos PureMessage) runs on a Postgres database. + +Some of our Solaris customers have Oracle licenses, and they've +commented on the performance difference between Oracle and Postgresql +on such boxes. In-house, we've noticed the 2:1 (sometimes 5:1) +performance difference in inserting rows (mostly 2-4K), between +Postgresql on Solaris 8 and on Linux, for machines with comparable +CPU's and RAM. + +These (big) customers are starting to ask, why don't we just port our +dataserver to Oracle for them? I'd like to avoid that, if possible :-) + +What we can test on, in-house are leetle Sun workstations, while some of +our customers have BIG Sun iron --- so I have no means to-date to +reproduce what their bottleneck is :-( Yes, it has been recommended that +we talk to Sun about their iForce test lab ... that's in the pipe. + +In the meantime, what I gather from browsing mail archives is that +postgresql on Solaris seems to get hung up on IO rather than CPU. +Furthermore, I notice that Oracle and now MySQL use directio to bypass +the system cache, when doing heavy writes to the disk; and Postgresql +does not. + +Not wishing to alter backend/store/file for this test, I figured I could +get a customer to mount the UFS volume for pg_xlog with the option +"forcedirectio". + +Any comment on this? No consideration of what the wal_sync_method is at +this point. Presumably it's defaulting to fdatasync on Solaris. + +BTW this is Postgres 7.4.1, and our customers are Solaris 8 and 9. + +From pgsql-performance-owner@postgresql.org Fri Sep 17 21:44:58 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 781AB329C63 + for ; + Fri, 17 Sep 2004 21:44:53 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 08720-05 + for ; + Fri, 17 Sep 2004 20:44:48 +0000 (GMT) +Received: from email11.aon.at (warsl404pip7.highway.telekom.at [195.3.96.91]) + by svr1.postgresql.org (Postfix) with SMTP id A9A69329CBC + for ; + Fri, 17 Sep 2004 21:44:48 +0100 (BST) +Received: (qmail 757778 invoked from network); 17 Sep 2004 20:44:47 -0000 +Received: from m161p031.dipool.highway.telekom.at (HELO PASCAL) + ([62.46.10.31]) (envelope-sender ) + by email11.aon.at (qmail-ldap-1.03) with SMTP + for ; 17 Sep 2004 20:44:47 -0000 +From: Manfred Koizar +To: Stephen Crowley +Cc: pgsql-performance@postgresql.org, + =?ISO-8859-1?Q?Pierre=2DFr=E9d=E9ric_Cai?= =?ISO-8859-1?Q?llaud?= + +Subject: Re: Large # of rows in query extremely slow, not using +Date: Fri, 17 Sep 2004 22:44:05 +0200 +Message-ID: +References: <3f71fdf104091317515c756512@mail.gmail.com> + <20040914184358.08e271fe@kingfisher.intern.logi-track.com> + + <3f71fdf1040916185113e277e6@mail.gmail.com> +In-Reply-To: <3f71fdf1040916185113e277e6@mail.gmail.com> +X-Mailer: Forte Agent 2.0/32.652 +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/187 +X-Sequence-Number: 8315 + +On Thu, 16 Sep 2004 20:51:11 -0500, Stephen Crowley + wrote: +>explain analyze select * from history where date='2004-09-07' and +>stock='ORCL' LIMIT 10; + +>" -> Index Scan using island_history_date_stock_time on +>island_history (cost=0.00..183099.72 rows=102166 width=83) (actual +>time=1612.000..1702.000 rows=10 loops=1)" + ^^ +LIMIT 10 hides what would be the most interesting info here. I don't +believe that + EXPLAIN ANALYSE SELECT * FROM history WHERE ... +consumes lots of memory. Please try it. + +And when you post the results please include your Postgres version, some +info about hardware and OS, and your non-default settings, especially +random_page_cost and effective_cache_size. + +May I guess that the correlation of the physical order of tuples in your +table to the contents of the date column is pretty good (examine +correlation in pg_stats) and that island_history_date_stock_time is a +3-column index? + +It is well known that the optimizer overestimates the cost of index +scans in those situations. This can be compensated to a certain degree +by increasing effective_cache_size and/or decreasing random_page_cost +(which might harm other planner decisions). + +You could also try + CREATE INDEX history_date_stock ON history("date", stock); + +This will slow down INSERTs and UPDATEs, though. + +Servus + Manfred + +From pgsql-performance-owner@postgresql.org Sat Sep 18 01:08:25 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 67588329CBC + for ; + Sat, 18 Sep 2004 01:07:44 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 59838-03 + for ; + Sat, 18 Sep 2004 00:07:37 +0000 (GMT) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by svr1.postgresql.org (Postfix) with ESMTP id 17911329C67 + for ; + Sat, 18 Sep 2004 01:07:36 +0100 (BST) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by news.hub.org (8.12.9/8.12.9) with ESMTP id i8I07WCn061859 + for ; Sat, 18 Sep 2004 00:07:32 GMT + (envelope-from news@news.hub.org) +Received: (from news@localhost) + by news.hub.org (8.12.9/8.12.9/Submit) id i8HNgX1i056228 + for pgsql-performance@postgresql.org; Fri, 17 Sep 2004 23:42:33 GMT +From: Gaetano Mendola +X-Newsgroups: comp.databases.postgresql.performance +Subject: Re: Tryint to match Solaris-Oracle performance with directio? +Date: Sat, 18 Sep 2004 01:42:25 +0200 +Organization: PYRENET Midi-pyrenees Provider +Lines: 28 +Message-ID: <414B7661.7000108@bigfoot.com> +References: +Mime-Version: 1.0 +Content-Type: text/plain; charset=ISO-8859-1; format=flowed +Content-Transfer-Encoding: 7bit +X-Complaints-To: abuse@pyrenet.fr +To: ischamay.andbergsay@activestateway.com +User-Agent: Mozilla Thunderbird 0.8 (Windows/20040913) +X-Accept-Language: en-us, en +In-Reply-To: +X-Enigmail-Version: 0.86.1.0 +X-Enigmail-Supports: pgp-inline, pgp-mime +To: pgsql-performance@postgresql.org +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/188 +X-Sequence-Number: 8316 + +Mischa Sandberg wrote: +> In the meantime, what I gather from browsing mail archives is that +> postgresql on Solaris seems to get hung up on IO rather than CPU. +> Furthermore, I notice that Oracle and now MySQL use directio to bypass +> the system cache, when doing heavy writes to the disk; and Postgresql +> does not. +> +> Not wishing to alter backend/store/file for this test, I figured I could +> get a customer to mount the UFS volume for pg_xlog with the option +> "forcedirectio". +> +> Any comment on this? No consideration of what the wal_sync_method is at +> this point. Presumably it's defaulting to fdatasync on Solaris. +> +> BTW this is Postgres 7.4.1, and our customers are Solaris 8 and 9. + +If you care your data upgrade to more recent 7.4.5 + +Test your better sync method using /src/tools/fsync however do some +experiment changing the sync method, you can also avoid to update the +acces time for the inodes mounting the partition with noatime option +( this however have more impact on performance for read activities ) + + +Regards +Gaetano Mendola + + + +From pgsql-performance-owner@postgresql.org Sat Sep 18 01:24:26 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id BA651329CDB + for ; + Sat, 18 Sep 2004 01:23:56 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 63299-03 + for ; + Sat, 18 Sep 2004 00:23:50 +0000 (GMT) +Received: from mproxy.gmail.com (rproxy.gmail.com [64.233.170.206]) + by svr1.postgresql.org (Postfix) with ESMTP id F345E329CBC + for ; + Sat, 18 Sep 2004 01:23:52 +0100 (BST) +Received: by mproxy.gmail.com with SMTP id v18so528095rnb + for ; + Fri, 17 Sep 2004 17:23:52 -0700 (PDT) +Received: by 10.38.8.29 with SMTP id 29mr262418rnh; + Fri, 17 Sep 2004 17:23:44 -0700 (PDT) +Received: by 10.38.8.79 with HTTP; Fri, 17 Sep 2004 17:23:44 -0700 (PDT) +Message-ID: <3f71fdf1040917172395a3be5@mail.gmail.com> +Date: Fri, 17 Sep 2004 19:23:44 -0500 +From: Stephen Crowley +Reply-To: Stephen Crowley +To: pgsql-performance@postgresql.org +Subject: Re: Large # of rows in query extremely slow, not using +Cc: Manfred Koizar , + =?ISO-8859-1?Q?Pierre-Fr=E9d=E9ric_Cai_llaud?= + +In-Reply-To: +Mime-Version: 1.0 +Content-Type: text/plain; charset=US-ASCII +Content-Transfer-Encoding: 7bit +References: <3f71fdf104091317515c756512@mail.gmail.com> + <20040914184358.08e271fe@kingfisher.intern.logi-track.com> + + <3f71fdf1040916185113e277e6@mail.gmail.com> + +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/189 +X-Sequence-Number: 8317 + +Ok.. now I ran "VACUUM FULL' and things seem to be working as they should.. + +explain analyze select * from history where date='2004-09-07' and stock='MSFT'; + +Seq Scan on island_history (cost=0.00..275359.13 rows=292274 +width=83) (actual time=50.000..411683.000 rows=265632 loops=1) + Filter: ((date = '2004-09-07'::date) AND ((stock)::text = 'MSFT'::text)) +Total runtime: 412703.000 ms + +random_page_cost and effective_cache_size are both default, 8 and 1000 + +explain analyze select * from history where date='2004-09-07' and stock='ORCL'; + +"Index Scan using island_history_date_stock_time on island_history +(cost=0.00..181540.07 rows=102166 width=83) (actual +time=551.000..200268.000 rows=159618 loops=1)" +" Index Cond: ((date = '2004-09-07'::date) AND ((stock)::text = 'ORCL'::text))" +"Total runtime: 201009.000 ms" + +So now this in all in proportion and works as expected.. the question +is, why would the fact that it needs to be vaccumed cause such a huge +hit in performance? When i vacuumed it did free up nearly 25% of the +space. + +--Stephen + +On Fri, 17 Sep 2004 22:44:05 +0200, Manfred Koizar wrote: +> On Thu, 16 Sep 2004 20:51:11 -0500, Stephen Crowley +> wrote: +> >explain analyze select * from history where date='2004-09-07' and +> >stock='ORCL' LIMIT 10; +> +> >" -> Index Scan using island_history_date_stock_time on +> >island_history (cost=0.00..183099.72 rows=102166 width=83) (actual +> >time=1612.000..1702.000 rows=10 loops=1)" +> ^^ +> LIMIT 10 hides what would be the most interesting info here. I don't +> believe that +> EXPLAIN ANALYSE SELECT * FROM history WHERE ... +> consumes lots of memory. Please try it. +> +> And when you post the results please include your Postgres version, some +> info about hardware and OS, and your non-default settings, especially +> random_page_cost and effective_cache_size. +> +> May I guess that the correlation of the physical order of tuples in your +> table to the contents of the date column is pretty good (examine +> correlation in pg_stats) and that island_history_date_stock_time is a +> 3-column index? +> +> It is well known that the optimizer overestimates the cost of index +> scans in those situations. This can be compensated to a certain degree +> by increasing effective_cache_size and/or decreasing random_page_cost +> (which might harm other planner decisions). +> +> You could also try +> CREATE INDEX history_date_stock ON history("date", stock); +> +> This will slow down INSERTs and UPDATEs, though. +> +> Servus +> Manfred +> + +From pgsql-performance-owner@postgresql.org Sat Sep 18 02:22:52 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 83A04329CB7 + for ; + Sat, 18 Sep 2004 02:22:49 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 74506-06 + for ; + Sat, 18 Sep 2004 01:22:42 +0000 (GMT) +Received: from mail0.rawbw.com (mail0.rawbw.com [198.144.192.41]) + by svr1.postgresql.org (Postfix) with ESMTP id 9CA85329C63 + for ; + Sat, 18 Sep 2004 02:22:44 +0100 (BST) +Received: (from www@localhost) + by mail0.rawbw.com (8.11.6p2/8.11.6) id i8I1Mht01537 + for pgsql-performance@postgresql.org; + Fri, 17 Sep 2004 18:22:43 -0700 (PDT) +Received: from cybs-gw.ic3.com (cybs-gw.ic3.com [66.185.177.10]) + by webmail.rawbw.com (IMP) with HTTP + for ; Fri, 17 Sep 2004 18:22:43 -0700 +Message-ID: <1095470563.414b8de381c99@webmail.rawbw.com> +Date: Fri, 17 Sep 2004 18:22:43 -0700 +From: mudfoot@rawbw.com +To: pgsql-performance@postgresql.org +Subject: Re: Tryint to match Solaris-Oracle performance with directio? +References: <414B7661.7000108@bigfoot.com> +In-Reply-To: <414B7661.7000108@bigfoot.com> +MIME-Version: 1.0 +Content-Type: text/plain; charset=ISO-8859-1 +Content-Transfer-Encoding: 8bit +User-Agent: Internet Messaging Program (IMP) 3.2.1 +X-Originating-IP: 66.185.177.10 +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.3 tagged_above=0.0 required=5.0 tests=NO_REAL_NAME +X-Spam-Level: +X-Archive-Number: 200409/190 +X-Sequence-Number: 8318 + +I fully agree with Gaetano about testing sync methods. From testing I've done +on two different Solaris 8 boxes, the O_DSYNC option on Solaris 8 beats fsync +and fdatasync easily. Test it yourself though. There's probably some +opportuntiy there for better performance for you. + +> > BTW this is Postgres 7.4.1, and our customers are Solaris 8 and 9. +> +> If you care your data upgrade to more recent 7.4.5 +> +> Test your better sync method using /src/tools/fsync however do some +> experiment changing the sync method, you can also avoid to update the +> acces time for the inodes mounting the partition with noatime option +> ( this however have more impact on performance for read activities ) +> +> +> Regards +> Gaetano Mendola +> +> +> +> ---------------------------(end of broadcast)--------------------------- +> TIP 2: you can get off all lists at once with the unregister command +> (send "unregister YourEmailAddressHere" to majordomo@postgresql.org) +> + + + +From pgsql-performance-owner@postgresql.org Sat Sep 18 17:36:04 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id BA03B329E23 + for ; + Sat, 18 Sep 2004 17:35:56 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 60686-10 + for ; + Sat, 18 Sep 2004 16:35:51 +0000 (GMT) +Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) + by svr1.postgresql.org (Postfix) with ESMTP id 289CC329CDB + for ; + Sat, 18 Sep 2004 17:35:51 +0100 (BST) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i8IGZplF004927; + Sat, 18 Sep 2004 12:35:51 -0400 (EDT) +To: ischamay.andbergsay@activestateway.com +Cc: pgsql-performance@postgresql.org +Subject: Re: Tryint to match Solaris-Oracle performance with directio? +In-reply-to: +References: +Comments: In-reply-to Mischa Sandberg + message dated "Fri, 17 Sep 2004 19:23:08 +0000" +Date: Sat, 18 Sep 2004 12:35:50 -0400 +Message-ID: <4926.1095525350@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/193 +X-Sequence-Number: 8321 + +Mischa Sandberg writes: +> Our product (Sophos PureMessage) runs on a Postgres database. +> Some of our Solaris customers have Oracle licenses, and they've +> commented on the performance difference between Oracle and Postgresql +> on such boxes. In-house, we've noticed the 2:1 (sometimes 5:1) +> performance difference in inserting rows (mostly 2-4K), between +> Postgresql on Solaris 8 and on Linux, for machines with comparable +> CPU's and RAM. + +You haven't given any evidence at all to say that I/O is where the +problem is. I think it would be good first to work through the +conventional issues such as configuration parameters, foreign key +problems, etc. Give us some more detail about the slow INSERT +queries ... + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Sat Sep 18 18:01:30 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id DBBE2329E4D + for ; + Sat, 18 Sep 2004 18:01:27 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 67766-04 + for ; + Sat, 18 Sep 2004 17:01:22 +0000 (GMT) +Received: from trofast.sesse.net (trofast.sesse.net [129.241.93.32]) + by svr1.postgresql.org (Postfix) with ESMTP id C8C5B329E79 + for ; + Sat, 18 Sep 2004 18:01:19 +0100 (BST) +Received: from sesse by trofast.sesse.net with local (Exim 3.36 #1 (Debian)) + id 1C8iaL-0000sN-00 + for ; Sat, 18 Sep 2004 19:01:17 +0200 +Date: Sat, 18 Sep 2004 19:01:17 +0200 +From: "Steinar H. Gunderson" +To: pgsql-performance@postgresql.org +Subject: Planner having way wrong estimate for group aggregate +Message-ID: <20040918170117.GA3354@uio.no> +Mail-Followup-To: pgsql-performance@postgresql.org +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +User-Agent: Mutt/1.5.6+20040818i +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/194 +X-Sequence-Number: 8322 + +Hi, + +I'm using PostgreSQL 7.4 on a table with ~700.000 rows looking like this: + + Table "public.enkeltsalg" + Column | Type | Modifiers +------------+--------------------------+------------------------------------------------------- + id | integer | not null default nextval('"enkeltsalg_id_seq"'::text) + kommentar | text | not null default ''::text + antall | numeric(14,4) | not null + belop | numeric(10,0) | not null + type | character(1) | not null + tid | timestamp with time zone | default now() + eksternid | integer | + kasseid | integer | + baraapning | integer | + salgspris | integer | + firma | integer | + bongid | integer | +Indexes: + "enkeltsalg_pkey" primary key, btree (id) + "enkeltsalg_aapn" btree (baraapning) + "enkeltsalg_aapn_pris" btree (baraapning, salgspris) + "enkeltsalg_aapn_type" btree (baraapning, "type") + "enkeltsalg_pris" btree (salgspris) +Check constraints: + "enkeltsalg_type_valid" CHECK ("type" = 'K'::bpchar OR "type" = 'B'::bpchar OR "type" = 'M'::bpchar OR "type" = 'T'::bpchar) + +And I'm doing the query (after VACUUM ANALYZE) + +smt=# explain analyze select sum(belop) as omsetning,date_trunc('day',tid) as dato from enkeltsalg group by date_trunc('day',tid); + QUERY PLAN +---------------------------------------------------------------------------------------------------------------------------------- + GroupAggregate (cost=108062.34..114477.98 rows=172735 width=17) (actual time=20977.544..23890.020 rows=361 loops=1) + -> Sort (cost=108062.34..109912.99 rows=740263 width=17) (actual time=20947.372..21627.107 rows=710720 loops=1) + Sort Key: date_trunc('day'::text, tid) + -> Seq Scan on enkeltsalg (cost=0.00..18010.29 rows=740263 width=17) (actual time=0.091..7180.528 rows=710720 loops=1) + Total runtime: 23908.538 ms +(5 rows) + +Now, as you can see, the GroupAggregate here is _way_ off, so the planner +makes the wrong choice (it should do a hash aggregate). If I set sort_mem to +131072 instead of 16384, it does a hash aggregate (which is 10 seconds +instead of 24), but I can't have sort_mem that high generally. + +Now, my first notion was creating a functional index to help the planner: + +smt=# create index enkeltsalg_dag on enkeltsalg ( date_trunc('day',tid) ); +CREATE INDEX +smt=# vacuum analyze; +VACUUM + +However, this obviously didn't help the planner (this came as a surprise to +me, but probably won't come as a surprise to the more seasoned users here :-) +): + +smt=# explain analyze select sum(belop) as omsetning,date_trunc('day',tid) as dato from enkeltsalg group by date_trunc('day',tid); + QUERY PLAN +---------------------------------------------------------------------------------------------------------------------------------- + GroupAggregate (cost=103809.15..110017.11 rows=175512 width=17) (actual time=21061.357..23917.370 rows=361 loops=1) + -> Sort (cost=103809.15..105585.95 rows=710720 width=17) (actual time=21032.239..21695.674 rows=710720 loops=1) + Sort Key: date_trunc('day'::text, tid) + -> Seq Scan on enkeltsalg (cost=0.00..17641.00 rows=710720 width=17) (actual time=0.091..7231.387 rows=710720 loops=1) + Total runtime: 23937.791 ms +(5 rows) + +I also tried to increase the statistics on the "tid" column: + +smt=# alter table enkeltsalg alter column tid set statistics 500; +ALTER TABLE +smt=# analyze enkeltsalg; +ANALYZE + +However, this made the planner only do a _worse_ estimate: + +smt=# explain analyze select sum(belop) as omsetning,date_trunc('day',tid) as dato from enkeltsalg group by date_trunc('day',tid); + QUERY PLAN +---------------------------------------------------------------------------------------------------------------------------------- + GroupAggregate (cost=107906.59..114449.09 rows=199715 width=17) (actual time=20947.197..23794.389 rows=361 loops=1) + -> Sort (cost=107906.59..109754.56 rows=739190 width=17) (actual time=20918.001..21588.735 rows=710720 loops=1) + Sort Key: date_trunc('day'::text, tid) + -> Seq Scan on enkeltsalg (cost=0.00..17996.88 rows=739190 width=17) (actual time=0.092..7166.488 rows=710720 loops=1) + Total runtime: 23814.624 ms +(5 rows) + +Actually, it seems that the higher I set statistics on "tid", the worse the +estimate becomes. + +Also, I was told (on #postgresql :-) ) to include the following information: + +smt=# select n_distinct from pg_stats where attname='tid'; + n_distinct + ------------ + -0.270181 +(1 row) + +Any ideas for speeding this up? + +/* Steinar */ +-- +Homepage: http://www.sesse.net/ + +From pgsql-performance-owner@postgresql.org Sat Sep 18 18:03:08 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id AA993329E94 + for ; + Sat, 18 Sep 2004 18:03:06 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 67766-07 + for ; + Sat, 18 Sep 2004 17:03:01 +0000 (GMT) +Received: from latenight.fiasco.org.il (latenight.fiasco.org.il + [192.117.122.39]) + by svr1.postgresql.org (Postfix) with SMTP id A066F329E8C + for ; + Sat, 18 Sep 2004 18:02:56 +0100 (BST) +Received: (qmail 15132 invoked from network); 18 Sep 2004 17:02:53 -0000 +Received: from unknown (HELO ?172.16.19.91?) (192.117.102.130) + by latenight.fiasco.org.il with SMTP; 18 Sep 2004 17:02:49 -0000 +Message-ID: <414C6A38.1060800@shemesh.biz> +Date: Sat, 18 Sep 2004 20:02:48 +0300 +From: Shachar Shemesh +Organization: Lingnu Open Source Consulting ltd. +User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; + rv:1.7.2) Gecko/20040820 Debian/1.7.2-4 +X-Accept-Language: en +MIME-Version: 1.0 +To: ischamay.andbergsay@activestateway.com +Cc: pgsql-performance@postgresql.org +Subject: Re: Tryint to match Solaris-Oracle performance with directio? +References: +In-Reply-To: +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/195 +X-Sequence-Number: 8323 + +Mischa Sandberg wrote: + +> In the meantime, what I gather from browsing mail archives is that +> postgresql on Solaris seems to get hung up on IO rather than CPU. + +Well, people more knowledgeable in the secrets of postgres seem +confident that this is not your problem. Fortunetly, however, there is a +simple way to find out. + +Just download the utinyint var type from pgfoundry +(http://pgfoundry.org/projects/sql2pg/). There are some stuff there you +will need to compile yourself from CVS. I'm sorry, but I haven't done a +proper release just yet. In any case, the utinyint type should provide +you with the data type you seek, and thus allow you to find out whether +this is, indeed, the problem. + +-- +Shachar Shemesh +Lingnu Open Source Consulting ltd. +http://www.lingnu.com/ + + +From pgsql-performance-owner@postgresql.org Sat Sep 18 20:48:31 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id A8265329D04 + for ; + Sat, 18 Sep 2004 20:48:24 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 18197-08 + for ; + Sat, 18 Sep 2004 19:48:19 +0000 (GMT) +Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) + by svr1.postgresql.org (Postfix) with ESMTP id 72061329CFD + for ; + Sat, 18 Sep 2004 20:48:20 +0100 (BST) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i8IJmEWO007262; + Sat, 18 Sep 2004 15:48:14 -0400 (EDT) +To: "Steinar H. Gunderson" +Cc: pgsql-performance@postgresql.org +Subject: Re: Planner having way wrong estimate for group aggregate +In-reply-to: <20040918170117.GA3354@uio.no> +References: <20040918170117.GA3354@uio.no> +Comments: In-reply-to "Steinar H. Gunderson" + message dated "Sat, 18 Sep 2004 19:01:17 +0200" +Date: Sat, 18 Sep 2004 15:48:13 -0400 +Message-ID: <7261.1095536893@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/196 +X-Sequence-Number: 8324 + +"Steinar H. Gunderson" writes: +> Now, my first notion was creating a functional index to help the planner: +> ... +> However, this obviously didn't help the planner (this came as a surprise to +> me, but probably won't come as a surprise to the more seasoned users here :-) + +7.4 doesn't have any statistics on expression indexes. 8.0 will do what +you want though. (I just fixed an oversight that prevented it from +doing so...) + +> Actually, it seems that the higher I set statistics on "tid", the worse the +> estimate becomes. + +I believe that the estimate of number of groups will be exactly the same +as the estimate of the number of values of tid --- there's no knowledge +that date_trunc() might reduce the number of distinct values. + +> Any ideas for speeding this up? + +In 7.4, the only way I can see to force this to use a hash aggregate is +to temporarily set enable_sort false or raise sort_mem. + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Sat Sep 18 21:03:45 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 06DEF329D04 + for ; + Sat, 18 Sep 2004 21:03:44 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 21822-08 + for ; + Sat, 18 Sep 2004 20:03:38 +0000 (GMT) +Received: from trofast.sesse.net (trofast.sesse.net [129.241.93.32]) + by svr1.postgresql.org (Postfix) with ESMTP id 6BE76329CFD + for ; + Sat, 18 Sep 2004 21:03:38 +0100 (BST) +Received: from sesse by trofast.sesse.net with local (Exim 3.36 #1 (Debian)) + id 1C8lQm-0001Cg-00 + for ; Sat, 18 Sep 2004 22:03:36 +0200 +Date: Sat, 18 Sep 2004 22:03:36 +0200 +From: "Steinar H. Gunderson" +To: pgsql-performance@postgresql.org +Subject: Re: Planner having way wrong estimate for group aggregate +Message-ID: <20040918200336.GA4598@uio.no> +Mail-Followup-To: pgsql-performance@postgresql.org +References: <20040918170117.GA3354@uio.no> <7261.1095536893@sss.pgh.pa.us> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <7261.1095536893@sss.pgh.pa.us> +X-Operating-System: Linux 2.6.6 on a i686 +User-Agent: Mutt/1.5.6+20040818i +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/197 +X-Sequence-Number: 8325 + +On Sat, Sep 18, 2004 at 03:48:13PM -0400, Tom Lane wrote: +> 7.4 doesn't have any statistics on expression indexes. 8.0 will do what +> you want though. (I just fixed an oversight that prevented it from +> doing so...) + +OK, so I'll have to wait for 8.0.0beta3 or 8.0.0 (I tried 8.0.0beta2, it gave +me zero difference) -- fortunately, I can probably wait at the rate +everything else is progressing here. :-) + +/* Steinar */ +-- +Homepage: http://www.sesse.net/ + +From pgsql-performance-owner@postgresql.org Sun Sep 19 04:26:40 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id A9425329C63 + for ; + Sun, 19 Sep 2004 04:26:29 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 23991-08 + for ; + Sun, 19 Sep 2004 03:26:27 +0000 (GMT) +Received: from pd2mo2so.prod.shaw.ca (shawidc-mo1.cg.shawcable.net + [24.71.223.10]) + by svr1.postgresql.org (Postfix) with ESMTP id 27B24329C67 + for ; + Sun, 19 Sep 2004 04:26:23 +0100 (BST) +Received: from pd5mr8so.prod.shaw.ca + (pd5mr8so-qfe3.prod.shaw.ca [10.0.141.184]) by l-daemon + (Sun ONE Messaging Server 6.0 HotFix 1.01 (built Mar 15 2004)) + with ESMTP id <0I49000KEQVP4D60@l-daemon> for + pgsql-performance@postgresql.org; Sat, 18 Sep 2004 21:26:13 -0600 (MDT) +Received: from pn2ml10so.prod.shaw.ca ([10.0.121.80]) + by pd5mr8so.prod.shaw.ca (Sun ONE Messaging Server 6.0 HotFix 1.01 + (built Mar + 15 2004)) with ESMTP id <0I4900BE2QVPRY60@pd5mr8so.prod.shaw.ca> for + pgsql-performance@postgresql.org; Sat, 18 Sep 2004 21:26:13 -0600 (MDT) +Received: from [192.168.1.10] + (S01060050bac04c93.ed.shawcable.net [68.148.193.184]) + by l-daemon (iPlanet Messaging Server 5.2 HotFix 1.18 (built Jul 28 + 2003)) with ESMTP id <0I490050QQVOV5@l-daemon> for + pgsql-performance@postgresql.org; + Sat, 18 Sep 2004 21:26:13 -0600 (MDT) +Date: Sat, 18 Sep 2004 21:26:13 -0600 +From: Patrick Clery +Subject: Re: Comparing user attributes with bitwise operators +In-reply-to: <87llfappqq.fsf@stark.xeocode.com> +To: Greg Stark +Cc: pgsql-performance@postgresql.org +Message-id: <200409182126.13686.patrick@phpforhire.com> +MIME-version: 1.0 +Content-type: text/plain; charset=iso-8859-1 +Content-transfer-encoding: 7bit +Content-disposition: inline +References: <200409160141.37604.patrick@phpforhire.com> + <87llfappqq.fsf@stark.xeocode.com> +User-Agent: KMail/1.6.2 +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.9 tagged_above=0.0 required=5.0 + tests=FAKE_HELO_SHAW_CA +X-Spam-Level: +X-Archive-Number: 200409/198 +X-Sequence-Number: 8326 + +I have currently implemented a schema for my "Dating Site" that is storing +user search preferences and user attributes in an int[] array using the +contrib/intarray package (suggested by Greg Stark). But there are a few +problems. + a) query_int can't be cast to int4. + b) query_int can't be indexed. + +datingsite=> alter table people_attributes add column bla query_int; +ALTER TABLE +datingsite=> create index idx_query_int on people_attributes (bla); +ERROR: data type query_int has no default operator class for access method +"btree" +HINT: You must specify an operator class for the index or define a default +operator class for the data type. +datingsite=> create index idx_query_int on people_attributes (bla +gist__int_ops); +ERROR: operator class "gist__int_ops" does not exist for access method +"btree" +datingsite=> alter table people_attributes drop column bla; +ALTER TABLE + + c) query_int can only be used in one operation against int[]: + + README.intarray: + int[] @@ query_int - returns TRUE if array satisfies query (like '1&(2|3)') + + It is not possible to use >=, <=, =, etc. Also, this operator does not work +like example says: + +datingsite=> select '{2,3}'::int[] @@ '1'::query_int; + ?column? +---------- + f +(1 row) + + d) I can't find a way to simply check if an integer is an array without +declaring it as an array; Therefore, I need to use an int[] type for a column +that will only be storing one int4 if I want to compare it to an int[] array: + + README.intarray: + int[] && int[] - overlap - returns TRUE if arrays has at least one common +elements. + + e) int[] and query_int are somewhat ugly to deal with since query_int needs +to be quoted as a string, and int[] is returned as '{1,2,3}'. Or maybe I'm +just being anal :) + + +Because of these limitations, I've chosen to declare the attribute columns as +int[] arrays (even though they will only contain one value) so that I can use +'{1,2,3}'::int[] && column_name: + + README.intarray: + int[] && int[] - overlap - returns TRUE if arrays has at least one common +elements. + +Here is the schema: + +create table people ( + person_id serial, + datecreated timestamp with time zone default now (), + signup_ip cidr not null, + username character varying(30) not null, + password character varying(28) not null, + email character varying(65) not null, + dob date not null, + primary key (person_id) +); + +create table people_attributes ( + person_id int references people (person_id) on delete cascade initially +deferred, + askmecount int not null default 0, + age int[] not null default '{1}'::int[], + gender int[] not null default '{1}'::int[], + orientation int[] not null default '{1}'::int[], + bodytype int[] not null default '{1}'::int[], + children int[] not null default '{1}'::int[], + drinking int[] not null default '{1}'::int[], + education int[] not null default '{1}'::int[], + ethnicity int[] not null default '{1}'::int[], + eyecolor int[] not null default '{1}'::int[], + haircolor int[] not null default '{1}'::int[], + hairstyle int[] not null default '{1}'::int[], + height int[] not null default '{1}'::int[], + income int[] not null default '{1}'::int[], + occupation int[] not null default '{1}'::int[], + relation int[] not null default '{1}'::int[], /* multiple answer */ + religion int[] not null default '{1}'::int[], + seeking int[] not null default '{1}'::int[], /* multiple answer */ + smoking int[] not null default '{1}'::int[], + want_children int[] not null default '{1}'::int[], + weight int[] not null default '{1}'::int[], + + primary key (person_id) +) +without oids; + +create index people_attributes_search on people_attributes using gist ( + age gist__int_ops, + gender gist__int_ops, + orientation gist__int_ops, + bodytype gist__int_ops, + children gist__int_ops, + drinking gist__int_ops, + education gist__int_ops, + ethnicity gist__int_ops, + eyecolor gist__int_ops, + haircolor gist__int_ops, + hairstyle gist__int_ops, + height gist__int_ops, + income gist__int_ops, + occupation gist__int_ops, + relation gist__int_ops, + religion gist__int_ops, + seeking gist__int_ops, + smoking gist__int_ops, + want_children gist__int_ops, + weight gist__int_ops + ); + +/* These will be compared against the people_attributes table */ +create table people_searchprefs ( + person_id int references people (person_id) on delete cascade initially +deferred, + age int[] not null default +'{18,19,20,21,22,23,24,25,26,27,28,29,30}'::int[], + gender int[] not null default '{1,2,4}'::int[], + orientation int[] not null default '{1,2,8}'::int[], + bodytype int[] not null default '{1,2,3,4,5,6}'::int[], + children int[] not null default '{0}'::int[], + drinking int[] not null default '{0}'::int[], + education int[] not null default '{0}'::int[], + ethnicity int[] not null default '{0}'::int[], + eyecolor int[] not null default '{0}'::int[], + haircolor int[] not null default '{0}'::int[], + hairstyle int[] not null default '{0}'::int[], + height int[] not null default '{0}'::int[], + income int[] not null default '{0}'::int[], + occupation int[] not null default '{0}'::int[], + relation int[] not null default '{0}'::int[], + religion int[] not null default '{0}'::int[], + seeking int[] not null default '{0}'::int[], + smoking int[] not null default '{0}'::int[], + want_children int[] not null default '{0}'::int[], + weight int[] not null default '{0}'::int[], + + primary key (person_id) +) +without oids; + + +And now, the moment you've all been waiting for: performance! + + +(Number of profiles) + +datingsite=> select count(*) from people_attributes ; + count +------- + 96146 +(1 row) + +(age, gender and sexual orientation will always be a part of the query, and +are necessary to be invoke the index. The query is to show females, age 30-40 +of any orientation. But first, without the index) + +explain analyze +select person_id, gender +from people_attributes +where '{30,31,32,33,34,35,36,37,38,39,40}'::int[] && age +and '{2}'::int[] && gender +and '{1,2,4}'::int[] && orientation; + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------------------------------- + Seq Scan on people_attributes (cost=0.00..9078.56 rows=1 width=36) (actual +time=0.044..299.537 rows=937 loops=1) + Filter: (('{30,31,32,33,34,35,36,37,38,39,40}'::integer[] && age) AND +('{2}'::integer[] && gender) AND ('{1,2,4}'::integer[] && orientation)) + Total runtime: 304.707 ms +(3 rows) + + +( with the index ) + +explain analyze +select person_id, gender +from people_attributes +where '{30,31,32,33,34,35,36,37,38,39,40}'::int[] && age +and '{2}'::int[] && gender +and '{1,2,4}'::int[] && orientation; + QUERY +PLAN +----------------------------------------------------------------------------------------------------------------------------------------------------- + Index Scan using people_attributes_search on people_attributes +(cost=0.00..6.02 rows=1 width=36) (actual time=0.064..52.383 rows=937 +loops=1) + Index Cond: (('{30,31,32,33,34,35,36,37,38,39,40}'::integer[] && age) AND +('{2}'::integer[] && gender) AND ('{1,2,4}'::integer[] && orientation)) + Total runtime: 57.032 ms +(3 rows) + +(more realistically, it will have a limit of 10) + +explain analyze +select person_id, gender +from people_attributes +where '{30,31,32,33,34,35,36,37,38,39,40}'::int[] && age +and '{2}'::int[] && gender +and '{1,2,4}'::int[] && orientation limit 10; + + QUERY +PLAN +----------------------------------------------------------------------------------------------------------------------------------------------------------- + Limit (cost=0.00..6.02 rows=1 width=36) (actual time=0.235..0.651 rows=10 +loops=1) + -> Index Scan using people_attributes_search on people_attributes +(cost=0.00..6.02 rows=1 width=36) (actual time=0.224..0.550 rows=10 loops=1) + Index Cond: (('{30,31,32,33,34,35,36,37,38,39,40}'::integer[] && age) +AND ('{2}'::integer[] && gender) AND ('{1,2,4}'::integer[] && orientation)) + Total runtime: 0.817 ms +(4 rows) + +(slower with an sort key) + +explain analyze +select person_id, gender +from people_attributes +where '{30,31,32,33,34,35,36,37,38,39,40}'::int[] && age +and '{2}'::int[] && gender +and '{1,2,4}'::int[] && orientation order by age; + QUERY +PLAN +----------------------------------------------------------------------------------------------------------------------------------------------------------- + Sort (cost=6.03..6.03 rows=1 width=68) (actual time=62.572..66.338 rows=937 +loops=1) + Sort Key: age + -> Index Scan using people_attributes_search on people_attributes +(cost=0.00..6.02 rows=1 width=68) (actual time=0.223..55.999 rows=937 +loops=1) + Index Cond: (('{30,31,32,33,34,35,36,37,38,39,40}'::integer[] && age) +AND ('{2}'::integer[] && gender) AND ('{1,2,4}'::integer[] && orientation)) + Total runtime: 71.206 ms +(5 rows) + +(no better with a limit) + +explain analyze +select person_id, gender +from people_attributes +where '{30,31,32,33,34,35,36,37,38,39,40}'::int[] && age +and '{2}'::int[] && gender +and '{1,2,4}'::int[] && orientation order by age limit 10; + QUERY +PLAN +----------------------------------------------------------------------------------------------------------------------------------------------------------------- + Limit (cost=6.03..6.03 rows=1 width=68) (actual time=69.391..69.504 rows=10 +loops=1) + -> Sort (cost=6.03..6.03 rows=1 width=68) (actual time=69.381..69.418 +rows=10 loops=1) + Sort Key: age + -> Index Scan using people_attributes_search on people_attributes +(cost=0.00..6.02 rows=1 width=68) (actual time=0.068..61.648 rows=937 +loops=1) + Index Cond: (('{30,31,32,33,34,35,36,37,38,39,40}'::integer[] +&& age) AND ('{2}'::integer[] && gender) AND ('{1,2,4}'::integer[] && +orientation)) + Total runtime: 69.899 ms +(6 rows) + +The last query is the most likely since I will need to be sorting by some key. +If I wasn't sorting it looks like it wouldn't be too bad, but sorting is +inevitable I think. I've only imported 96,146 of the 150,000 profiles. This +seems a bit slow now, and it doesn't look like it will scale. + +My questions are: + +- Is there a way of speeding up the sort? +- Will using queries like " WHERE orientation IN (1,2,4) " be any +better/worse? +- The queries with the GiST index are faster, but is it of any benefit when +the int[] arrays all contain a single value? +- Is there any hope for this structure? + +Thanks for the suggestion Greg, and thanks to those who responded to this +thread. + + + +On Thursday 16 September 2004 02:44, Greg Stark wrote: +> The only kind of index that is capable of indexing this type of data +> structure for arbitrary searches would be a GiST index. I'm not aware of +> any implementation for bitfields, though it would be an appropriate use. +> +> What there is now is the contrib/intarray package. You would have to store +> more than just the bitfields, you would have to store an array of integer +> flags. That might be denser actually if you end up with many flags few of +> which are set. +> +> GiST indexes allow you to search arbitrary combinations of set and unset +> flags. using the "@@" operator +> +> int[] @@ query_int - returns TRUE if array satisfies query (like +> '1&(2|3)') +> +> You might be able to look at the code there and adapt it to apply to bit +> fields. If so I think it would be a useful tool. But GiST indexing is +> pretty esoteric stuff. + + + + primary key (person_id) +) +without oids; + + +From pgsql-performance-owner@postgresql.org Sun Sep 19 06:08:06 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 444A0329C6B + for ; + Sun, 19 Sep 2004 06:08:05 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 23490-09 + for ; + Sun, 19 Sep 2004 05:08:00 +0000 (GMT) +Received: from stark.xeocode.com (gsstark.mtl.istop.com [66.11.160.162]) + by svr1.postgresql.org (Postfix) with ESMTP id 3B5DB329C89 + for ; + Sun, 19 Sep 2004 06:07:59 +0100 (BST) +Received: from localhost ([127.0.0.1] helo=stark.xeocode.com) + by stark.xeocode.com with smtp (Exim 3.36 #1 (Debian)) + id 1C8tvY-0005l4-00; Sun, 19 Sep 2004 01:07:56 -0400 +To: Patrick Clery +Cc: Greg Stark , pgsql-performance@postgresql.org +Subject: Re: Comparing user attributes with bitwise operators +References: <200409160141.37604.patrick@phpforhire.com> + <87llfappqq.fsf@stark.xeocode.com> + <200409182126.13686.patrick@phpforhire.com> +In-Reply-To: <200409182126.13686.patrick@phpforhire.com> +From: Greg Stark +Organization: The Emacs Conspiracy; member since 1992 +Date: 19 Sep 2004 01:07:56 -0400 +Message-ID: <87sm9eluc3.fsf@stark.xeocode.com> +Lines: 110 +User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/199 +X-Sequence-Number: 8327 + + +Patrick Clery writes: + +> PLAN +> ----------------------------------------------------------------------------------------------------------------------------------------------------------------- +> Limit (cost=6.03..6.03 rows=1 width=68) (actual time=69.391..69.504 rows=10 loops=1) +> -> Sort (cost=6.03..6.03 rows=1 width=68) (actual time=69.381..69.418 rows=10 loops=1) +> Sort Key: age +> -> Index Scan using people_attributes_search on people_attributes (cost=0.00..6.02 rows=1 width=68) (actual time=0.068..61.648 rows=937 loops=1) +> Index Cond: (('{30,31,32,33,34,35,36,37,38,39,40}'::integer[] && age) AND ('{2}'::integer[] && gender) AND ('{1,2,4}'::integer[] && orientation)) +> Total runtime: 69.899 ms +> (6 rows) +... +> - Is there a way of speeding up the sort? + +The sort seems to have only taken 8ms out of 69ms or just over 10%. As long as +the index scan doesn't match too many records the sort should never be any +slower so it shouldn't be the performance bottleneck. You might consider +putting a subquery inside the order by with a limit to ensure that the sort +never gets more than some safe maximum. Something like: + +select * from (select * from people_attributes where ... limit 1000) order by age limit 10 + +This means if the query matches more than 1000 it won't be sorted properly by +age; you'll get the top 10 out of some random subset. But you're protected +against ever having to sort more than 1000 records. + +> - Will using queries like " WHERE orientation IN (1,2,4) " be any better/worse? + +Well they won't use the GiST index, so no. If there was a single column with a +btree index then this would be the cleanest way to go. + +> - The queries with the GiST index are faster, but is it of any benefit when +> the int[] arrays all contain a single value? + +Well you've gone from 5 minutes to 60ms. You'll have to do more than one test +to be sure but it sure seems like it's of some benefit. + +If they're always a single value you could make it an expression index instead +and not have to change your data model. + +Just have the fields be integers individually and make an index as: + +create index idx on people_attributes using gist ( + (array[age]) gist__int_ops, + (array[gender]) gist__int_ops, +... +) + + +However I would go one step further. I would make the index simply: + +create index idx on people_attributes using gist ( + (array[age,gender,orientation,...]) gist__int_ops +) + +And ensure that all of these attributes have distinct domains. Ie, that they +don't share any values. There are 4 billion integer values available so that +shouldn't be an issue. + +Then you could use query_int to compare them the way you want. You +misunderstood how query_int is supposed to work. You index an array column and +then you can check it against a query_int just as you're currently checking +for overlap. Think of @@ as a more powerful version of the overlap operator +that can do complex logical expressions. + +The equivalent of + + where '{30,31,32,33,34,35,36,37,38,39,40}'::int[] && age + and '{2}'::int[] && gender + and '{1,2,4}'::int[] && orientation + +would then become: + + WHERE array[age,gender,orientation] @@ '(30|31|32|33|34|35|36|37|38|39|40)&(2)&(1|2|4)' + +except you would have to change orientation and gender to not both have a +value of 2. + +You might consider doing the expression index a bit of overkill actually. You +might consider just storing a column "attributes" with an integer array +directly in the table. + +You would also want a table that lists the valid attributes to be sure not to +have any overlaps: + +1 age 1 +2 age 2 +... +101 gender male +102 gender female +103 orientation straight +104 orientation gay +105 orientation bi +106 bodytype scrawny +... + + +> - Is there any hope for this structure? + +You'll have to test this carefully. I tried using GiST indexes for my project +and found that I couldn't load the data and build the GiST indexes fast +enough. You have to test the costs of building and maintaining this index, +especially since it has so many columns in it. + +But it looks like your queries are in trouble without it so hopefully it'll be +ok on the insert/update side for you. + +-- +greg + + +From pgsql-performance-owner@postgresql.org Sun Sep 19 11:04:54 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 8B369329D9F + for ; + Sun, 19 Sep 2004 11:04:50 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 76496-02 + for ; + Sun, 19 Sep 2004 10:04:45 +0000 (GMT) +Received: from mail.coretech.co.nz (coretech.co.nz [202.36.204.41]) + by svr1.postgresql.org (Postfix) with ESMTP id EF153329D83 + for ; + Sun, 19 Sep 2004 11:04:45 +0100 (BST) +Received: (qmail 14187 invoked from network); 19 Sep 2004 10:04:42 -0000 +Received: from localhost (127.0.0.1) by 0 with SMTP; + 19 Sep 2004 10:04:42 -0000 +Received: from 82.133.100.70 ([82.133.100.70]) by mail.coretech.co.nz + (Horde) with HTTP for ; Sun, 19 Sep 2004 22:04:41 + +1200 +Message-ID: <1095588281.29ef3c9d222ad@mail.coretech.co.nz> +Date: Sun, 19 Sep 2004 22:04:41 +1200 +From: markir@coretech.co.nz +To: ischamay.andbergsay@activestateway.com +Cc: pgsql-performance@postgresql.org +Subject: Re: Tryint to match Solaris-Oracle performance with +References: +In-Reply-To: +MIME-Version: 1.0 +Content-Type: text/plain; charset="ISO-8859-1" +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +User-Agent: Internet Messaging Program (IMP) 4.0-cvs +X-Originating-IP: Withheld +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.3 tagged_above=0.0 required=5.0 tests=NO_REAL_NAME +X-Spam-Level: +X-Archive-Number: 200409/200 +X-Sequence-Number: 8328 + +Hi Mischa, + +You probably need to determine whether the bottleneck is cpu or disk (should be +easy enough!) + +Having said that, assuming your application is insert/update intensive I would +recommend: + +- mount the ufs filesystems Pg uses *without* logging +- use postgresql.conf setting fsync_method=fdatasync + +These changes made my Pgbench results improve by a factor or 4 (enough to catch +the big O maybe...) + +Then you will need to have a look at your other postgresql.conf parameters! +(posting this file to the list might be a plan) + +Cheers + +Mark + + + +Quoting Mischa Sandberg : + +> Our product (Sophos PureMessage) runs on a Postgres database. +> +> Some of our Solaris customers have Oracle licenses, and they've +> commented on the performance difference between Oracle and Postgresql +> on such boxes. In-house, we've noticed the 2:1 (sometimes 5:1) +> performance difference in inserting rows (mostly 2-4K), between +> Postgresql on Solaris 8 and on Linux, for machines with comparable +> CPU's and RAM. +> +> + + +From pgsql-performance-owner@postgresql.org Mon Sep 20 08:32:00 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 636C5329CB0 + for ; + Mon, 20 Sep 2004 08:31:59 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 27419-03 + for ; + Mon, 20 Sep 2004 07:31:53 +0000 (GMT) +Received: from email07.aon.at (warsl404pip8.highway.telekom.at [195.3.96.102]) + by svr1.postgresql.org (Postfix) with SMTP id 8EC58329C6B + for ; + Mon, 20 Sep 2004 08:31:53 +0100 (BST) +Received: (qmail 47124 invoked from network); 20 Sep 2004 07:31:51 -0000 +Received: from m170p012.dipool.highway.telekom.at (HELO PASCAL) + ([62.46.11.44]) (envelope-sender ) + by email07.aon.at (qmail-ldap-1.03) with SMTP + for ; 20 Sep 2004 07:31:51 -0000 +From: Manfred Koizar +To: Stephen Crowley +Cc: pgsql-performance@postgresql.org, + =?ISO-8859-1?Q?Pierre=2DFr=E9d=E9ric_Cai?= =?ISO-8859-1?Q?_llaud?= + +Subject: Re: Large # of rows in query extremely slow, not using +Date: Mon, 20 Sep 2004 09:31:11 +0200 +Message-ID: +References: <3f71fdf104091317515c756512@mail.gmail.com> + <20040914184358.08e271fe@kingfisher.intern.logi-track.com> + + <3f71fdf1040916185113e277e6@mail.gmail.com> + + <3f71fdf1040917172395a3be5@mail.gmail.com> +In-Reply-To: <3f71fdf1040917172395a3be5@mail.gmail.com> +X-Mailer: Forte Agent 2.0/32.652 +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=2.8 tagged_above=0.0 required=5.0 tests=RCVD_IN_DSBL, + RCVD_IN_SORBS_MISC, RCVD_IN_SORBS_SMTP +X-Spam-Level: ** +X-Archive-Number: 200409/202 +X-Sequence-Number: 8330 + +On Fri, 17 Sep 2004 19:23:44 -0500, Stephen Crowley + wrote: +>Seq Scan [...] rows=265632 +> Filter: ((date = '2004-09-07'::date) AND ((stock)::text = 'MSFT'::text)) +>Total runtime: 412703.000 ms +> +>random_page_cost and effective_cache_size are both default, 8 and 1000 + +Usually random_page_cost is 4.0 by default. And your +effective_cache_size setting is far too low for a modern machine. + +>"Index Scan [...] rows=159618 +>" Index Cond: ((date = '2004-09-07'::date) AND ((stock)::text = 'ORCL'::text))" +>"Total runtime: 201009.000 ms" + +Extrapolating this to 265000 rows you should be able to get the MSFT +result in ca. 330 seconds, if you can persuade the planner to choose an +index scan. Fiddling with random_page_cost and effective_cache_size +might do the trick. + +>So now this in all in proportion and works as expected.. the question +>is, why would the fact that it needs to be vaccumed cause such a huge +>hit in performance? When i vacuumed it did free up nearly 25% of the +>space. + +So before the VACCUM a seq scan would have taken ca. 550 seconds. Your +MSFT query with LIMIT 10 took ca. 350 seconds. It's not implausible to +assume that more than half of the table had to be scanned to find the +first ten rows matching the filter condition. + +Servus + Manfred + +From pgsql-performance-owner@postgresql.org Mon Sep 20 08:57:45 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 71EBE329D30 + for ; + Mon, 20 Sep 2004 08:57:43 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 36399-03 + for ; + Mon, 20 Sep 2004 07:57:37 +0000 (GMT) +Received: from mail.esphion.com (mail.esphion.com [202.6.75.178]) + by svr1.postgresql.org (Postfix) with ESMTP id 41D54329E85 + for ; + Mon, 20 Sep 2004 08:57:37 +0100 (BST) +Received: (qmail 16741 invoked from network); 20 Sep 2004 07:57:02 -0000 +Received: from unknown (HELO conker.?none?) (10.0.1.137) + by mail.esphion.com with SMTP; 20 Sep 2004 07:57:02 -0000 +Received: (nullmailer pid 15617 invoked by uid 10001); + Mon, 20 Sep 2004 07:57:34 -0000 +Date: Mon, 20 Sep 2004 19:57:34 +1200 +From: Guy Thornley +To: pgsql-performance@postgresql.org +Subject: O_DIRECT setting +Message-ID: <20040920075734.GK21733@conker.esphion.com> +Reply-To: Guy Thornley +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +User-Agent: Mutt/1.5.5.1+cvs20040105i +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/203 +X-Sequence-Number: 8331 + +A recent comment on this (or perhaps another?) mailing list about Sun boxen +and the directio mount option has prompted me to read about O_DIRECT on the +open() manpage. + +Has anybody tried this option? Ever taken any performance measurements? +I assume the way postgres manages its buffer memory (dealing with 8kB pages) +would be compatible with the restrictions: + + Under Linux 2.4 transfer sizes, and the alignment of user buffer + and file offset must all be multiples of the logical block size of + the file system. + +According to the manpage, O_DIRECT implies O_SYNC: + + File I/O is done directly to/from user space buffers. The I/O is + synchronous, i.e., at the completion of the read(2) or write(2) + system call, data is guaranteed to have been transferred. + +At the moment I am fairly interested in trying this, and I would spend some +time with it, but I have my hands full with other projects. I'd imagine this +is more use with the revamped buffer manager in PG8.0 than the 7.x line, but +we are not using PG8.0 here yet. + +Would people be interested in a performance benchmark? I need some benchmark +tips :) + +Incidentally, postgres heap files suffer really, really bad fragmentation, +which affects sequential scan operations (VACUUM, ANALYZE, REINDEX ...) +quite drastically. We have in-house patches that somewhat alleiviate this, +but they are not release quality. Has anybody else suffered this? + +Guy Thornley + + +From pgsql-performance-owner@postgresql.org Tue Sep 21 04:59:20 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 9F7FA329E17 + for ; + Tue, 21 Sep 2004 04:59:08 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 27453-08 + for ; + Tue, 21 Sep 2004 03:59:01 +0000 (GMT) +Received: from sccrmhc11.comcast.net (sccrmhc11.comcast.net [204.127.202.55]) + by svr1.postgresql.org (Postfix) with ESMTP id C027B329DB7 + for ; + Tue, 21 Sep 2004 04:59:00 +0100 (BST) +Received: from D7MKWD21 (c-67-160-247-54.client.comcast.net[67.160.247.54]) + by comcast.net (sccrmhc11) with SMTP + id <2004092103585801100it6hoe>; Tue, 21 Sep 2004 03:58:59 +0000 +Message-ID: <002001c49f8f$ab663b40$02120a0a@D7MKWD21> +From: "Patrick Hatcher" +To: +Subject: vacuum full & max_fsm_pages question +Date: Mon, 20 Sep 2004 21:01:26 -0700 +MIME-Version: 1.0 +Content-Type: multipart/alternative; + boundary="----=_NextPart_000_001D_01C49F54.FE56FF00" +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 6.00.2800.1437 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.8 tagged_above=0.0 required=5.0 tests=HTML_30_40, + HTML_MESSAGE +X-Spam-Level: +X-Archive-Number: 200409/204 +X-Sequence-Number: 8332 + +This is a multi-part message in MIME format. + +------=_NextPart_000_001D_01C49F54.FE56FF00 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: quoted-printable + + +Hello. +Couple of questions: + + +- Q1: Today I decided to do a vacuum full verbose analyze on a large table = +that has been giving me slow performance. And then I did it again. I noti= +ced that after each run the values in my indexes and estimate row version c= +hanged. What really got me wondering is the fact my indexes report more ro= +ws than are in the table and then the estimated rows is less than the actua= +l amount. + +The table is a read-only table that is updated 1/wk. After updating it is = +vacuumed full. I've also tried reindexing but the numbers still change. +Is this normal? Below is a partial output for 4 consecutive vacuum full an= +alyzes. No data was added nor was there anyone in the table. + +- Q2: I have about a dozen 5M plus row tables. I currently have my max_fsm= +_pages set to 300,000. As you can see in vacuum full output I supplied, on= +e table is already over this amount. Is there a limit on the size of max_f= +sm_pages? + + +CONF settings: +# - Memory - + +shared_buffers =3D 2000 # min 16, at least max_connections*2, 8KB= + each +sort_mem =3D 12288 # min 64, size in KB +#vacuum_mem =3D 8192 # min 1024, size in KB + +# - Free Space Map - + +max_fsm_pages =3D 300000 # min max_fsm_relations*16, 6 bytes each +max_fsm_relations =3D 500 # min 100, ~50 bytes each + + +Vacuum full information +#after second vacuum full +INFO: index "emaildat_fkey" now contains 8053743 row versions in 25764 pag= +es +DETAIL: 1895 index row versions were removed. +0 index pages have been deleted, 0 are currently reusable. +CPU 2.38s/0.42u sec elapsed 11.11 sec. +INFO: analyzing "cdm.cdm_email_data" +INFO: "cdm_email_data": 65882 pages, 3000 rows sampled, 392410 estimated t= +otal rows + + +#after third vacuum full +INFO: index "emaildat_fkey" now contains 8052738 row versions in 25769 pag= +es +DETAIL: 890 index row versions were removed. +0 index pages have been deleted, 0 are currently reusable. +CPU 2.08s/0.32u sec elapsed 4.36 sec. +INFO: analyzing "cdm.cdm_email_data" +INFO: "cdm_email_data": 65874 pages, 3000 rows sampled, 392363 estimated t= +otal rows + + +#after REINDEX and vacuum full +INFO: index "emaildat_fkey" now contains 8052369 row versions in 25771 pag= +es +DETAIL: 521 index row versions were removed. +0 index pages have been deleted, 0 are currently reusable. +CPU 1.37s/0.35u sec elapsed 4.79 sec. +INFO: analyzing "cdm.cdm_email_data" +INFO: "cdm_email_data": 65869 pages, 3000 rows sampled, 392333 estimated t= +otal rows + +#After vacuum full(s) +mdc_oz=3D# select count(*) from cdm.cdm_email_data; + count +--------- + 5433358 +(1 row) + + +TIA +Patrick= + +------=_NextPart_000_001D_01C49F54.FE56FF00 +Content-Type: text/html; + charset="iso-8859-1" +Content-Transfer-Encoding: quoted-printable + + + + + + + + +
 
+
Hello.
+
Couple of questions:
+
 
+
 
+
+
- Q1: Today I decided to do a vacuum full = +verbose=20 +analyze on a large table that has been giving me slow performance.  An= +d=20 +then I did it again.  I noticed that after each run the values in= + my=20 +indexes and estimate row version changed.  What really got me=20 +wondering is the fact my indexes report more rows than are in the table and= + then=20 +the estimated rows is less than the actual amount.
+
 
+
The table is a read-only table that is upd= +ated=20 +1/wk.  After updating it is vacuumed full.  I've also tried reind= +exing=20 +but the numbers still change.
+
Is this normal?  Below is a partial o= +utput for=20 +4 consecutive vacuum full analyzes.  No data was added nor was there a= +nyone=20 +in the table.
+
 
+
- Q2: I have about a dozen 5M plus row=20 +tables.  I currently have my max_fsm_pages set to 300,000.  As yo= +u can=20 +see in vacuum full output I supplied, one table is already over this=20 +amount.  Is there a limit on the size of max_fsm_pages?
+
 
+
 
+
CONF settings:
+
# - Memory -
+
 
+
shared_buffers =3D=20 +2000           # min 16, = +at=20 +least max_connections*2, 8KB each
sort_mem =3D=20 +12288           &nbs= +p;   =20 +# min 64, size in KB
#vacuum_mem =3D=20 +8192            = +; =20 +# min 1024, size in KB
+
 
+
# - Free Space Map -
+
 
+
max_fsm_pages =3D=20 +300000          # min=20 +max_fsm_relations*16, 6 bytes each
max_fsm_relations =3D=20 +500         # min 100, ~50 bytes=20 +each
+
 
+
Vacuum full information
+
#after second vacuum full
+
INFO:  index "emaildat_fkey" now cont= +ains=20 +8053743 row versions in 25764 pages
DETAIL:  1895 index row version= +s=20 +were removed.
0 index pages have been deleted, 0 are currently=20 +reusable.
CPU 2.38s/0.42u sec elapsed 11.11 sec.
INFO:  analyzin= +g=20 +"cdm.cdm_email_data"
INFO:  "cdm_email_data": 65882 pages, 3000 row= +s=20 +sampled, 392410 estimated total rows
+
 
+
 
+
#after third vacuum full
+
INFO:  index "emaildat_fkey" now cont= +ains=20 +8052738 row versions in 25769 pages
DETAIL:  890 index row versions= + were=20 +removed.
0 index pages have been deleted, 0 are currently reusable.
C= +PU=20 +2.08s/0.32u sec elapsed 4.36 sec.
INFO:  analyzing=20 +"cdm.cdm_email_data"
INFO:  "cdm_email_data": 65874 pages, 3000 row= +s=20 +sampled, 392363 estimated total rows
+
 
+
 
+
#after REINDEX and  vacuum full
+
INFO:  index "emaildat_fkey" now cont= +ains=20 +8052369 row versions in 25771 pages
DETAIL:  521 index row versions= + were=20 +removed.
0 index pages have been deleted, 0 are currently reusable.
C= +PU=20 +1.37s/0.35u sec elapsed 4.79 sec.
INFO:  analyzing=20 +"cdm.cdm_email_data"
INFO:  "cdm_email_data": 65869 pages, 3000 row= +s=20 +sampled, 392333 estimated total rows
+
 
+
#After vacuum full(s)
+
mdc_oz=3D# select count(*) from=20 +cdm.cdm_email_data;
  count
---------
 5433358
(1=20 +row)
+
 
+
TIA
+
Patrick
+ +------=_NextPart_000_001D_01C49F54.FE56FF00-- + + +From pgsql-performance-owner@postgresql.org Tue Sep 21 07:15:34 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id EFA8B329EAF + for ; + Tue, 21 Sep 2004 07:15:24 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 64505-07 + for ; + Tue, 21 Sep 2004 06:15:14 +0000 (GMT) +Received: from lakermmtao06.cox.net (lakermmtao06.cox.net [68.230.240.33]) + by svr1.postgresql.org (Postfix) with ESMTP id 90D3F329EAB + for ; + Tue, 21 Sep 2004 07:15:14 +0100 (BST) +Received: from [192.168.0.8] (really [68.105.165.3]) by lakermmtao06.cox.net + (InterMail vM.6.01.03.04 201-2131-111-106-20040729) with ESMTP + id <20040921061513.ODBF7555.lakermmtao06.cox.net@[192.168.0.8]>; + Tue, 21 Sep 2004 02:15:13 -0400 +From: Robert Treat +To: "Patrick Hatcher" +Subject: Re: vacuum full & max_fsm_pages question +Date: Tue, 21 Sep 2004 02:12:33 -0400 +User-Agent: KMail/1.6.2 +Cc: +References: <002001c49f8f$ab663b40$02120a0a@D7MKWD21> +In-Reply-To: <002001c49f8f$ab663b40$02120a0a@D7MKWD21> +MIME-Version: 1.0 +Content-Disposition: inline +Content-Type: text/plain; + charset="utf-8" +Content-Transfer-Encoding: 7bit +Message-Id: <200409210212.33497.xzilla@users.sourceforge.net> +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/205 +X-Sequence-Number: 8333 + +On Tuesday 21 September 2004 00:01, Patrick Hatcher wrote: +> Hello. +> Couple of questions:> +> - Q1: Today I decided to do a vacuum full verbose analyze on a large table +> that has been giving me slow performance. And then I did it again. I +> noticed that after each run the values in my indexes and estimate row +> version changed. What really got me wondering is the fact my indexes +> report more rows than are in the table and then the estimated rows is less +> than the actual amount. +> +> The table is a read-only table that is updated 1/wk. After updating it is +> vacuumed full. I've also tried reindexing but the numbers still change. Is +> this normal? Below is a partial output for 4 consecutive vacuum full +> analyzes. No data was added nor was there anyone in the table. +> + +This looks normal to me for a pre 7.4 database, if I am right your running on +7.2? Basically your indexes are overgrown, so each time you run vacuum you +are shrinking the number of pages involved, which will change the row counts, +and correspondingly change the count on the table as the sampled pages +change. + + +> - Q2: I have about a dozen 5M plus row tables. I currently have my +> max_fsm_pages set to 300,000. As you can see in vacuum full output I +> supplied, one table is already over this amount. Is there a limit on the +> size of max_fsm_pages? +> + +The limit is based on your memory... each page = 6 bytes. But according to +the output below you are not over 300000 pages yet on that table (though you +might be on some other tables.) + +> +> CONF settings: +> # - Memory - +> +> shared_buffers = 2000 # min 16, at least max_connections*2, 8KB +> each sort_mem = 12288 # min 64, size in KB +> #vacuum_mem = 8192 # min 1024, size in KB +> +> # - Free Space Map - +> +> max_fsm_pages = 300000 # min max_fsm_relations*16, 6 bytes each +> max_fsm_relations = 500 # min 100, ~50 bytes each +> +> +> Vacuum full information +> #after second vacuum full +> INFO: index "emaildat_fkey" now contains 8053743 row versions in 25764 +> pages DETAIL: 1895 index row versions were removed. +> 0 index pages have been deleted, 0 are currently reusable. +> CPU 2.38s/0.42u sec elapsed 11.11 sec. +> INFO: analyzing "cdm.cdm_email_data" +> INFO: "cdm_email_data": 65882 pages, 3000 rows sampled, 392410 estimated +> total rows +> +> +> #after third vacuum full +> INFO: index "emaildat_fkey" now contains 8052738 row versions in 25769 +> pages DETAIL: 890 index row versions were removed. +> 0 index pages have been deleted, 0 are currently reusable. +> CPU 2.08s/0.32u sec elapsed 4.36 sec. +> INFO: analyzing "cdm.cdm_email_data" +> INFO: "cdm_email_data": 65874 pages, 3000 rows sampled, 392363 estimated +> total rows +> +> +> #after REINDEX and vacuum full +> INFO: index "emaildat_fkey" now contains 8052369 row versions in 25771 +> pages DETAIL: 521 index row versions were removed. +> 0 index pages have been deleted, 0 are currently reusable. +> CPU 1.37s/0.35u sec elapsed 4.79 sec. +> INFO: analyzing "cdm.cdm_email_data" +> INFO: "cdm_email_data": 65869 pages, 3000 rows sampled, 392333 estimated +> total rows +> +> #After vacuum full(s) +> mdc_oz=# select count(*) from cdm.cdm_email_data; +> count +> --------- +> 5433358 +> (1 row) +> + +I do think the count(*) seems a bit off based on the vacuum output above. I'm +guessing you either have blocking transactions in the way or your not giving +us a complete copy/paste of the session involved. + +-- +Robert Treat +Build A Brighter Lamp :: Linux Apache {middleware} PostgreSQL + +From pgsql-performance-owner@postgresql.org Tue Sep 21 09:54:57 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id DD204329DB7 + for ; + Tue, 21 Sep 2004 09:54:55 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 16878-08 + for ; + Tue, 21 Sep 2004 08:54:50 +0000 (GMT) +Received: from mail.idea.net.pl (smtp-in.centertel.pl [194.9.223.7]) + by svr1.postgresql.org (Postfix) with ESMTP id 61FFA329D95 + for ; + Tue, 21 Sep 2004 09:54:51 +0100 (BST) +Received: from skorupa ([193.110.123.54]) by mta2.centertel.pl (mailserver) + with ESMTPA id <0I4D00KR7VFD4G@mta2.centertel.pl> for + pgsql-performance@postgresql.org; Tue, 21 Sep 2004 10:54:49 +0200 (CEST) +Date: Tue, 21 Sep 2004 10:54:48 +0200 +From: Mariusz =?iso-8859-2?q?Czu=B3ada?= +Subject: Hyper threading? +To: pgsql-performance@postgresql.org +Message-id: <200409211054.48574.manieq@idea.net.pl> +MIME-version: 1.0 +Content-type: text/plain; charset=iso-8859-2 +Content-transfer-encoding: 7BIT +Content-disposition: inline +User-Agent: KMail/1.6.1 +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/206 +X-Sequence-Number: 8334 + +Hi all, + +I searched list archives, but did not found anything about HT of Pentium +4/Xeon processors. I wonder if hyperthreading can boost or decrease +performance. AFAIK for other commercial servers (msssql, oracle) official +documents state something like "faster, but not always, so probably slower, +unless faster". User opinions are generaly more clear: better swhitch off HT. + +Do you have any experiance or test results regarding hyperthreading? Or what +additional conditions can make HT useful or pointless? + +TIA, + +Mariusz + + +From pgsql-performance-owner@postgresql.org Tue Sep 21 14:22:06 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 4E6E1329D9F + for ; + Tue, 21 Sep 2004 14:22:04 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 10991-08 + for ; + Tue, 21 Sep 2004 13:21:51 +0000 (GMT) +Received: from sccrmhc12.comcast.net (sccrmhc12.comcast.net [204.127.202.56]) + by svr1.postgresql.org (Postfix) with ESMTP id E26BA329D7F + for ; + Tue, 21 Sep 2004 14:21:54 +0100 (BST) +Received: from D7MKWD21 (c-67-160-247-54.client.comcast.net[67.160.247.54]) + by comcast.net (sccrmhc12) with SMTP + id <2004092113215001200ctnn2e>; Tue, 21 Sep 2004 13:21:51 +0000 +Message-ID: <000e01c49fde$4d122f50$02120a0a@D7MKWD21> +From: "Patrick Hatcher" +To: "Robert Treat" +Cc: +References: <002001c49f8f$ab663b40$02120a0a@D7MKWD21> + <200409210212.33497.xzilla@users.sourceforge.net> +Subject: Re: vacuum full & max_fsm_pages question +Date: Tue, 21 Sep 2004 06:24:18 -0700 +MIME-Version: 1.0 +Content-Type: text/plain; + charset="utf-8" +Content-Transfer-Encoding: 7bit +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 6.00.2800.1437 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/207 +X-Sequence-Number: 8335 + +Sorry. I wrote PG 7.4.2 and then I erased it to write something else and +then forgot to add it back. + +And thanks for the Page info. I was getting frustrated and looked in the +wrong place. + +So it's probably best to drop and readd the indexes then? + + +----- Original Message ----- +From: "Robert Treat" +To: "Patrick Hatcher" +Cc: +Sent: Monday, September 20, 2004 11:12 PM +Subject: Re: [PERFORM] vacuum full & max_fsm_pages question + + +> On Tuesday 21 September 2004 00:01, Patrick Hatcher wrote: +> > Hello. +> > Couple of questions:> +> > - Q1: Today I decided to do a vacuum full verbose analyze on a large +table +> > that has been giving me slow performance. And then I did it again. I +> > noticed that after each run the values in my indexes and estimate row +> > version changed. What really got me wondering is the fact my indexes +> > report more rows than are in the table and then the estimated rows is +less +> > than the actual amount. +> > +> > The table is a read-only table that is updated 1/wk. After updating it +is +> > vacuumed full. I've also tried reindexing but the numbers still change. +Is +> > this normal? Below is a partial output for 4 consecutive vacuum full +> > analyzes. No data was added nor was there anyone in the table. +> > +> +> This looks normal to me for a pre 7.4 database, if I am right your running +on +> 7.2? Basically your indexes are overgrown, so each time you run vacuum you +> are shrinking the number of pages involved, which will change the row +counts, +> and correspondingly change the count on the table as the sampled pages +> change. +> +> +> > - Q2: I have about a dozen 5M plus row tables. I currently have my +> > max_fsm_pages set to 300,000. As you can see in vacuum full output I +> > supplied, one table is already over this amount. Is there a limit on +the +> > size of max_fsm_pages? +> > +> +> The limit is based on your memory... each page = 6 bytes. But according +to +> the output below you are not over 300000 pages yet on that table (though +you +> might be on some other tables.) +> +> > +> > CONF settings: +> > # - Memory - +> > +> > shared_buffers = 2000 # min 16, at least max_connections*2, +8KB +> > each sort_mem = 12288 # min 64, size in KB +> > #vacuum_mem = 8192 # min 1024, size in KB +> > +> > # - Free Space Map - +> > +> > max_fsm_pages = 300000 # min max_fsm_relations*16, 6 bytes each +> > max_fsm_relations = 500 # min 100, ~50 bytes each +> > +> > +> > Vacuum full information +> > #after second vacuum full +> > INFO: index "emaildat_fkey" now contains 8053743 row versions in 25764 +> > pages DETAIL: 1895 index row versions were removed. +> > 0 index pages have been deleted, 0 are currently reusable. +> > CPU 2.38s/0.42u sec elapsed 11.11 sec. +> > INFO: analyzing "cdm.cdm_email_data" +> > INFO: "cdm_email_data": 65882 pages, 3000 rows sampled, 392410 +estimated +> > total rows +> > +> > +> > #after third vacuum full +> > INFO: index "emaildat_fkey" now contains 8052738 row versions in 25769 +> > pages DETAIL: 890 index row versions were removed. +> > 0 index pages have been deleted, 0 are currently reusable. +> > CPU 2.08s/0.32u sec elapsed 4.36 sec. +> > INFO: analyzing "cdm.cdm_email_data" +> > INFO: "cdm_email_data": 65874 pages, 3000 rows sampled, 392363 +estimated +> > total rows +> > +> > +> > #after REINDEX and vacuum full +> > INFO: index "emaildat_fkey" now contains 8052369 row versions in 25771 +> > pages DETAIL: 521 index row versions were removed. +> > 0 index pages have been deleted, 0 are currently reusable. +> > CPU 1.37s/0.35u sec elapsed 4.79 sec. +> > INFO: analyzing "cdm.cdm_email_data" +> > INFO: "cdm_email_data": 65869 pages, 3000 rows sampled, 392333 +estimated +> > total rows +> > +> > #After vacuum full(s) +> > mdc_oz=# select count(*) from cdm.cdm_email_data; +> > count +> > --------- +> > 5433358 +> > (1 row) +> > +> +> I do think the count(*) seems a bit off based on the vacuum output above. +I'm +> guessing you either have blocking transactions in the way or your not +giving +> us a complete copy/paste of the session involved. +> +> -- +> Robert Treat +> Build A Brighter Lamp :: Linux Apache {middleware} PostgreSQL + + +From pgsql-performance-owner@postgresql.org Tue Sep 21 18:58:21 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id BD501329CDB; + Tue, 21 Sep 2004 18:58:15 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 22684-05; Tue, 21 Sep 2004 17:58:05 +0000 (GMT) +Received: from fdd00lnhub.fds.com (external.fds.com [208.15.90.2]) + by svr1.postgresql.org (Postfix) with ESMTP id 5F611329C83; + Tue, 21 Sep 2004 18:58:04 +0100 (BST) +In-Reply-To: <200409211049.02018.josh@agliodbs.com> +Subject: Re: vacuum full & max_fsm_pages question +To: "Josh Berkus +Cc: "Patrick Hatcher" , pgsql-performance@postgresql.org, + pgsql-performance-owner@postgresql.org, + "Robert Treat" +X-Mailer: Lotus Notes Release 6.0 September 26, 2002 +Message-ID: + +From: Patrick Hatcher +Date: Tue, 21 Sep 2004 10:45:37 -0700 +X-MIMETrack: Serialize by Router on FDD00LNHUB/FSG/SVR/FDD(Release 6.5.2|June + 01, 2004) at 09/21/2004 01:57:38 PM +MIME-Version: 1.0 +Content-type: text/plain; charset=US-ASCII +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=2.4 tagged_above=0.0 required=5.0 tests=TO_HAS_SPACES +X-Spam-Level: ** +X-Archive-Number: 200409/209 +X-Sequence-Number: 8337 + + + + + +Nope. It's been running like a champ for while now. + +Patrick Hatcher +Macys.Com +Legacy Integration Developer +415-422-1610 office +HatcherPT - AIM + + + + Josh Berkus + To + Sent by: "Patrick Hatcher" + pgsql-performance + -owner@postgresql cc + .org "Robert Treat" + , + + 09/21/2004 10:49 Subject + AM Re: [PERFORM] vacuum full & + max_fsm_pages question + + + + + + + + + + +Patrick, + +> Sorry. I wrote PG 7.4.2 and then I erased it to write something else and +> then forgot to add it back. + +Odd. You shouldn't be having to re-vacuum on 7.4. + +> And thanks for the Page info. I was getting frustrated and looked in the +> wrong place. +> +> So it's probably best to drop and readd the indexes then? + +Well, I have to wonder if you've not run afoul of the known 7.4.2 bug +regarding indexes. This system hasn't had an improper database shutdown +or +power-out in the last few weeks, has it? + +-- +Josh Berkus +Aglio Database Solutions +San Francisco + +---------------------------(end of broadcast)--------------------------- +TIP 9: the planner will ignore your desire to choose an index scan if your + joining column's datatypes do not match + + + +From pgsql-performance-owner@postgresql.org Tue Sep 21 18:49:58 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 34650329CAE + for ; + Tue, 21 Sep 2004 18:49:46 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 18442-07 + for ; + Tue, 21 Sep 2004 17:49:35 +0000 (GMT) +Received: from davinci.ethosmedia.com (server226.ethosmedia.com + [209.128.84.226]) + by svr1.postgresql.org (Postfix) with ESMTP id CB842329C83 + for ; + Tue, 21 Sep 2004 18:49:34 +0100 (BST) +Received: from [63.195.55.98] (account josh@agliodbs.com HELO spooky) + by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.1.8) + with ESMTP id 6387929; Tue, 21 Sep 2004 10:50:54 -0700 +From: Josh Berkus +Organization: Aglio Database Solutions +To: "Patrick Hatcher" +Subject: Re: vacuum full & max_fsm_pages question +Date: Tue, 21 Sep 2004 10:49:02 -0700 +User-Agent: KMail/1.6.2 +Cc: "Robert Treat" , + +References: <002001c49f8f$ab663b40$02120a0a@D7MKWD21> + <200409210212.33497.xzilla@users.sourceforge.net> + <000e01c49fde$4d122f50$02120a0a@D7MKWD21> +In-Reply-To: <000e01c49fde$4d122f50$02120a0a@D7MKWD21> +MIME-Version: 1.0 +Content-Disposition: inline +Content-Type: text/plain; + charset="utf-8" +Content-Transfer-Encoding: 7bit +Message-Id: <200409211049.02018.josh@agliodbs.com> +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/208 +X-Sequence-Number: 8336 + +Patrick, + +> Sorry. I wrote PG 7.4.2 and then I erased it to write something else and +> then forgot to add it back. + +Odd. You shouldn't be having to re-vacuum on 7.4. + +> And thanks for the Page info. I was getting frustrated and looked in the +> wrong place. +> +> So it's probably best to drop and readd the indexes then? + +Well, I have to wonder if you've not run afoul of the known 7.4.2 bug +regarding indexes. This system hasn't had an improper database shutdown or +power-out in the last few weeks, has it? + +-- +Josh Berkus +Aglio Database Solutions +San Francisco + +From pgsql-performance-owner@postgresql.org Tue Sep 21 23:52:27 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 555CF329E85 + for ; + Tue, 21 Sep 2004 23:52:20 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 18641-07 + for ; + Tue, 21 Sep 2004 22:52:16 +0000 (GMT) +Received: from pns.mm.eutelsat.org (pns.mm.eutelsat.org [194.214.173.227]) + by svr1.postgresql.org (Postfix) with ESMTP id 5ADC9329E5F + for ; + Tue, 21 Sep 2004 23:52:16 +0100 (BST) +Received: from nts-03.mm.eutelsat.org (localhost [127.0.0.1]) + by pns.mm.eutelsat.org (8.11.6/linuxconf) with ESMTP id i8LMonm27127 + for ; Wed, 22 Sep 2004 00:50:50 +0200 +Received: from [127.0.0.1] (accesspoint.mm.eutelsat.org [194.214.173.4]) + by nts-03.mm.eutelsat.org (8.11.6/linuxconf) with ESMTP id i8LMqDV06872 + for ; Wed, 22 Sep 2004 00:52:13 +0200 +Message-ID: <4150B096.1050904@bigfoot.com> +Date: Wed, 22 Sep 2004 00:52:06 +0200 +From: Gaetano Mendola +User-Agent: Mozilla Thunderbird 0.8 (Windows/20040913) +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: "pgsql-performance@postgresql.org" +Subject: 7.4 vs 7.3 ( hash join issue ) +X-Enigmail-Version: 0.86.1.0 +X-Enigmail-Supports: pgp-inline, pgp-mime +Content-Type: text/plain; charset=ISO-8859-1; format=flowed +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 + tests=TO_ADDRESS_EQ_REAL +X-Spam-Level: +X-Archive-Number: 200409/210 +X-Sequence-Number: 8338 + +-----BEGIN PGP SIGNED MESSAGE----- +Hash: SHA1 + +Hi all, +I'm having performance degradation with a view upgrading from +7.3 to 7.4, the view is a not so complex, one of his field +is the result from a function. +If I remove the function ( or I use a void function ) the 7.4 +out perform the 7.3: + +On 7.4 I get: + +xxxxx=# explain analyze select * from v_ivan_2; +~ QUERY PLAN +- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ +~ Hash Left Join (cost=7028.36..16780.89 rows=65613 width=288) (actual time=2059.923..9340.043 rows=79815 loops=1) +~ Hash Cond: ("outer".id_baa_loc = "inner".id_baa_loc) +~ -> Hash Left Join (cost=6350.62..15134.25 rows=65613 width=258) (actual time=1816.013..7245.085 rows=65609 loops=1) +~ Hash Cond: ("outer".id_localita = "inner".id_localita) +~ -> Hash Left Join (cost=6252.93..14786.74 rows=65613 width=247) (actual time=1777.072..6533.316 rows=65609 loops=1) +~ Hash Cond: ("outer".id_frazione = "inner".id_frazione) +~ -> Hash Left Join (cost=6226.61..14362.74 rows=65613 width=235) (actual time=1768.273..5837.104 rows=65609 loops=1) +~ Hash Cond: ("outer".id_baa = "inner".id_baa) +~ -> Hash Left Join (cost=5092.24..12342.65 rows=65594 width=197) (actual time=1354.059..4562.398 rows=65592 loops=1) +~ Hash Cond: ("outer".id_pratica = "inner".id_pratica) +~ -> Hash Left Join (cost=3597.52..10010.84 rows=65594 width=173) (actual time=785.775..3278.372 rows=65592 loops=1) +~ Hash Cond: ("outer".id_pratica = "inner".id_pratica) +~ -> Hash Join (cost=1044.77..6605.97 rows=65594 width=149) (actual time=274.316..2070.788 rows=65592 loops=1) +~ Hash Cond: ("outer".id_stato_pratica = "inner".id_stato_pratica) +~ -> Hash Join (cost=1043.72..5850.59 rows=65593 width=141) (actual time=273.478..1421.274 rows=65592 loops=1) +~ Hash Cond: ("outer".id_pratica = "inner".id_pratica) +~ -> Seq Scan on t_pratica p (cost=0.00..3854.27 rows=65927 width=137) (actual time=7.275..533.281 rows=65927 loops=1) +~ -> Hash (cost=1010.92..1010.92 rows=65592 width=8) (actual time=265.615..265.615 rows=0 loops=1) +~ -> Seq Scan on t_baa_pratica bp (cost=0.00..1010.92 rows=65592 width=8) (actual time=0.209..164.761 rows=65592 loops=1) +~ -> Hash (cost=1.05..1.05 rows=5 width=22) (actual time=0.254..0.254 rows=0 loops=1) +~ -> Seq Scan on lookup_stato_pratica s (cost=0.00..1.05 rows=5 width=22) (actual time=0.190..0.210 rows=5 loops=1) +~ -> Hash (cost=2519.82..2519.82 rows=65865 width=28) (actual time=511.104..511.104 rows=0 loops=1) +~ -> Seq Scan on t_persona (cost=0.00..2519.82 rows=65865 width=28) (actual time=0.068..381.586 rows=65864 loops=1) +~ Filter: (is_rich = true) +~ -> Hash (cost=1462.53..1462.53 rows=64356 width=28) (actual time=567.919..567.919 rows=0 loops=1) +~ -> Index Scan using idx_t_persona_is_inte on t_persona (cost=0.00..1462.53 rows=64356 width=28) (actual time=12.953..432.697 rows=64356 loops=1) +~ Index Cond: (is_inte = true) +~ -> Hash (cost=1113.65..1113.65 rows=41444 width=46) (actual time=413.782..413.782 rows=0 loops=1) +~ -> Hash Join (cost=4.33..1113.65 rows=41444 width=46) (actual time=2.687..333.746 rows=41444 loops=1) +~ Hash Cond: ("outer".id_comune = "inner".id_comune) +~ -> Seq Scan on t_baa_loc bl (cost=0.00..653.44 rows=41444 width=20) (actual time=0.422..94.803 rows=41444 loops=1) +~ -> Hash (cost=4.22..4.22 rows=222 width=34) (actual time=1.735..1.735 rows=0 loops=1) +~ -> Seq Scan on t_comune co (cost=0.00..4.22 rows=222 width=34) (actual time=0.521..1.277 rows=222 loops=1) +~ -> Hash (cost=25.59..25.59 rows=1459 width=20) (actual time=8.343..8.343 rows=0 loops=1) +~ -> Seq Scan on t_frazione f (cost=0.00..25.59 rows=1459 width=20) (actual time=0.554..5.603 rows=1459 loops=1) +~ -> Hash (cost=94.94..94.94 rows=5494 width=19) (actual time=38.504..38.504 rows=0 loops=1) +~ -> Seq Scan on t_localita l (cost=0.00..94.94 rows=5494 width=19) (actual time=8.499..28.216 rows=5494 loops=1) +~ -> Hash (cost=660.61..660.61 rows=34261 width=38) (actual time=198.663..198.663 rows=0 loops=1) +~ -> Seq Scan on t_affaccio af (cost=0.00..660.61 rows=34261 width=38) (actual time=5.875..133.336 rows=34261 loops=1) +~ Total runtime: 9445.263 ms +(40 rows) + + +On 7.3 I get: + + +xxxxx=# explain analyze select * from v_ivan_2; +~ QUERY PLAN +- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +~ Hash Join (cost=5597.02..15593.91 rows=65610 width=354) (actual time=2169.37..13102.64 rows=79815 loops=1) +~ Hash Cond: ("outer".id_baa_loc = "inner".id_baa_loc) +~ -> Hash Join (cost=4919.28..13953.00 rows=65610 width=316) (actual time=1966.38..10568.69 rows=65609 loops=1) +~ Hash Cond: ("outer".id_localita = "inner".id_localita) +~ -> Hash Join (cost=4821.59..13596.30 rows=65610 width=297) (actual time=1934.29..9151.45 rows=65609 loops=1) +~ Hash Cond: ("outer".id_frazione = "inner".id_frazione) +~ -> Hash Join (cost=4795.27..13157.36 rows=65610 width=277) (actual time=1925.29..7795.71 rows=65609 loops=1) +~ Hash Cond: ("outer".id_baa = "inner".id_baa) +~ -> Hash Join (cost=3640.17..11149.38 rows=65592 width=223) (actual time=1375.66..5870.74 rows=65592 loops=1) +~ Hash Cond: ("outer".id_pratica = "inner".id_pratica) +~ -> Hash Join (cost=3597.53..10237.66 rows=65592 width=195) (actual time=835.95..4332.46 rows=65592 loops=1) +~ Hash Cond: ("outer".id_pratica = "inner".id_pratica) +~ -> Hash Join (cost=1044.78..6800.07 rows=65592 width=167) (actual time=307.55..2903.04 rows=65592 loops=1) +~ Hash Cond: ("outer".id_pratica = "inner".id_pratica) +~ -> Merge Join (cost=1.06..4770.96 rows=65927 width=159) (actual time=1.41..1898.12 rows=65927 loops=1) +~ Merge Cond: ("outer".id_stato_pratica = "inner".id_stato_pratica) +~ -> Index Scan using idx_t_pratica on t_pratica p (cost=0.00..4044.70 rows=65927 width=137) (actual time=0.58..894.95 rows=65927 loops=1) +~ -> Sort (cost=1.06..1.06 rows=5 width=22) (actual time=0.78..58.49 rows=63528 loops=1) +~ Sort Key: s.id_stato_pratica +~ -> Seq Scan on lookup_stato_pratica s (cost=0.00..1.05 rows=5 width=22) (actual time=0.11..0.13 rows=5 loops=1) +~ -> Hash (cost=1010.92..1010.92 rows=65592 width=8) (actual time=305.40..305.40 rows=0 loops=1) +~ -> Seq Scan on t_baa_pratica bp (cost=0.00..1010.92 rows=65592 width=8) (actual time=0.23..192.88 rows=65592 loops=1) +~ -> Hash (cost=2519.82..2519.82 rows=65864 width=28) (actual time=527.88..527.88 rows=0 loops=1) +~ -> Seq Scan on t_persona (cost=0.00..2519.82 rows=65864 width=28) (actual time=0.07..394.51 rows=65864 loops=1) +~ Filter: (is_rich = true) +~ -> Hash (cost=10.46..10.46 rows=64356 width=28) (actual time=539.27..539.27 rows=0 loops=1) +~ -> Index Scan using idx_t_persona_is_inte on t_persona (cost=0.00..10.46 rows=64356 width=28) (actual time=0.61..403.48 rows=64356 loops=1) +~ Index Cond: (is_inte = true) +~ -> Hash (cost=1134.38..1134.38 rows=41444 width=54) (actual time=549.25..549.25 rows=0 loops=1) +~ -> Hash Join (cost=4.33..1134.38 rows=41444 width=54) (actual time=2.19..470.20 rows=41444 loops=1) +~ Hash Cond: ("outer".id_comune = "inner".id_comune) +~ -> Seq Scan on t_baa_loc bl (cost=0.00..653.44 rows=41444 width=20) (actual time=0.15..179.24 rows=41444 loops=1) +~ -> Hash (cost=4.22..4.22 rows=222 width=34) (actual time=1.55..1.55 rows=0 loops=1) +~ -> Seq Scan on t_comune co (cost=0.00..4.22 rows=222 width=34) (actual time=0.22..1.08 rows=222 loops=1) +~ -> Hash (cost=25.59..25.59 rows=1459 width=20) (actual time=8.37..8.37 rows=0 loops=1) +~ -> Seq Scan on t_frazione f (cost=0.00..25.59 rows=1459 width=20) (actual time=0.22..5.46 rows=1459 loops=1) +~ -> Hash (cost=94.94..94.94 rows=5494 width=19) (actual time=31.46..31.46 rows=0 loops=1) +~ -> Seq Scan on t_localita l (cost=0.00..94.94 rows=5494 width=19) (actual time=0.22..20.41 rows=5494 loops=1) +~ -> Hash (cost=660.61..660.61 rows=34261 width=38) (actual time=199.96..199.96 rows=0 loops=1) +~ -> Seq Scan on t_affaccio af (cost=0.00..660.61 rows=34261 width=38) (actual time=0.21..130.67 rows=34261 loops=1) +~ Total runtime: 13190.70 msec +(41 rows) + + + +As you can see the 7.3 do a index scan on the table t_pratica and the 7.4 perform a sequential scan, +the plans however are very close to each other. + +So I identify the performance issue on the function call, indeed: + + +7.4: + +xxxxx=# explain analyze select sp_foo(id_pratica) from t_pratica; +~ QUERY PLAN +- ------------------------------------------------------------------------------------------------------------------ +~ Seq Scan on t_pratica (cost=0.00..3887.23 rows=65927 width=4) (actual time=4.013..45240.015 rows=65927 loops=1) +~ Total runtime: 45499.123 ms +(2 rows) + + +7.3: + +xxxxx=# explain analyze select sp_foo(id_pratica) from t_pratica; +~ QUERY PLAN +- ---------------------------------------------------------------------------------------------------------------- +~ Seq Scan on t_pratica (cost=0.00..3854.27 rows=65927 width=4) (actual time=0.58..18446.99 rows=65927 loops=1) +~ Total runtime: 18534.41 msec +(2 rows) + + + +This is the sp_foo: + +CREATE FUNCTION sp_foo (integer) RETURNS text +~ AS ' +DECLARE +~ a_id_pratica ALIAS FOR $1; + +~ my_parere TEXT; +BEGIN +~ a_id_pratica := $1; + +~ SELECT INTO my_parere le.nome +~ FROM t_evento e, +~ lookup_tipo_evento le +~ WHERE e.id_tipo_evento = le.id_tipo_evento AND +~ e.id_pratica = a_id_pratica AND +~ e.id_tipo_evento in (5,6,7,8 ) +~ ORDER by e.id_evento desc +~ LIMIT 1; + +~ RETURN my_parere; +END; +' LANGUAGE plpgsql; + + +Preparing a statement this is the plan used by 7.4: + +xxxxx=# explain analyze execute foo_body( 5 ); +~ QUERY PLAN +- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +~ Limit (cost=10.30..10.30 rows=1 width=24) (actual time=0.538..0.538 rows=0 loops=1) +~ -> Sort (cost=10.30..10.30 rows=1 width=24) (actual time=0.534..0.534 rows=0 loops=1) +~ Sort Key: e.id_evento +~ -> Hash Join (cost=9.11..10.30 rows=1 width=24) (actual time=0.512..0.512 rows=0 loops=1) +~ Hash Cond: ("outer".id_tipo_evento = "inner".id_tipo_evento) +~ -> Seq Scan on lookup_tipo_evento le (cost=0.00..1.16 rows=16 width=32) (actual time=0.010..0.041 rows=16 loops=1) +~ -> Hash (cost=9.11..9.11 rows=1 width=16) (actual time=0.144..0.144 rows=0 loops=1) +~ -> Index Scan using t_evento_id_pratica_key on t_evento e (cost=0.00..9.11 rows=1 width=16) (actual time=0.140..0.140 rows=0 loops=1) +~ Index Cond: (id_pratica = $1) +~ Filter: (((id_tipo_evento)::text = '5'::text) OR ((id_tipo_evento)::text = '6'::text) OR ((id_tipo_evento)::text = '7'::text) OR ((id_tipo_evento)::text = '8'::text)) +~ Total runtime: 0.824 ms +(11 rows) + + + +The table t_pratica have 65927 rows so 0.824 ms * 65927 is almost the total time execution for +each t_pratica row ~ 45000 ms + + +Unfortunately I can not see the plan used by the 7.3 engine due the lack of explain execute, +however I did an explain analyze on the select: + +xxxxx=# explain analyze SELECT le.nome +xxxxx-# FROM t_evento e,lookup_tipo_evento le +xxxxx-# WHERE e.id_tipo_evento = le.id_tipo_evento +xxxxx-# AND e.id_pratica = 5 +xxxxx-# AND e.id_tipo_evento in (5,6,7,8 ) +xxxxx-# ORDER by e.id_evento desc +xxxxx-# LIMIT 1; +~ QUERY PLAN +- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +~ Limit (cost=10.27..10.27 rows=1 width=48) (actual time=0.19..0.19 rows=0 loops=1) +~ -> Sort (cost=10.27..10.27 rows=1 width=48) (actual time=0.18..0.18 rows=0 loops=1) +~ Sort Key: e.id_evento +~ -> Merge Join (cost=10.24..10.27 rows=1 width=48) (actual time=0.09..0.09 rows=0 loops=1) +~ Merge Cond: ("outer".id_tipo_evento = "inner".id_tipo_evento) +~ -> Sort (cost=9.02..9.02 rows=1 width=16) (actual time=0.09..0.09 rows=0 loops=1) +~ Sort Key: e.id_tipo_evento +~ -> Index Scan using t_evento_id_pratica_key on t_evento e (cost=0.00..9.02 rows=1 width=16) (actual time=0.06..0.06 rows=0 loops=1) +~ Index Cond: (id_pratica = 5) +~ Filter: (((id_tipo_evento)::text = '5'::text) OR ((id_tipo_evento)::text = '6'::text) OR ((id_tipo_evento)::text = '7'::text) OR ((id_tipo_evento)::text = '8'::text)) +~ -> Sort (cost=1.22..1.23 rows=16 width=32) (never executed) +~ Sort Key: le.id_tipo_evento +~ -> Seq Scan on lookup_tipo_evento le (cost=0.00..1.16 rows=16 width=32) (never executed) +~ Total runtime: 0.31 msec +(14 rows) + + +Disabling the hashjoin on the 7.4 I got best performance that 7.3: + +xxxxx=# set enable_hashjoin = off; +SET +xxxxx=# explain analyze select sp_get_ultimo_parere(id_pratica) from t_pratica; +~ QUERY PLAN +- ------------------------------------------------------------------------------------------------------------------- +~ Seq Scan on t_pratica (cost=0.00..3887.23 rows=65927 width=4) (actual time=12.384..12396.136 rows=65927 loops=1) +~ Total runtime: 12485.548 ms +(2 rows) + + +Now my question is why the 7.4 choose the hash join ? :-( +I can provide further details if you ask + +BTW with the hash_join = off the 7.4 choose the same 7.3 plan for this function body. + +Of course both engines are running on the same machine with the same settings. + + +Regards +Gaetano Mendola + + + + + + + + + + + + + + + + + + + + + + + + +-----BEGIN PGP SIGNATURE----- +Version: GnuPG v1.2.4 (MingW32) +Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org + +iD8DBQFBULCU7UpzwH2SGd4RAt2ZAKC9FjAKiljRqgaZSZa+p/7N65Cl7ACePWBV +TaR2VH1kDSBS7b+kNK4deFo= +=X+th +-----END PGP SIGNATURE----- + + +From pgsql-performance-owner@postgresql.org Wed Sep 22 07:48:16 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 3E046329D9F + for ; + Wed, 22 Sep 2004 07:48:15 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 36147-01 + for ; + Wed, 22 Sep 2004 06:48:11 +0000 (GMT) +Received: from zigo.dhs.org (as2-4-3.an.g.bonet.se [194.236.34.191]) + by svr1.postgresql.org (Postfix) with ESMTP id 0B793329D3B + for ; + Wed, 22 Sep 2004 07:48:11 +0100 (BST) +Received: from zigo.zigo.dhs.org (zigo.zigo.dhs.org [192.168.0.1]) + by zigo.dhs.org (Postfix) with ESMTP + id D3CAD8467; Wed, 22 Sep 2004 08:48:09 +0200 (CEST) +Date: Wed, 22 Sep 2004 08:48:09 +0200 (CEST) +From: Dennis Bjorklund +To: Gaetano Mendola +Cc: "pgsql-performance@postgresql.org" +Subject: Re: 7.4 vs 7.3 ( hash join issue ) +In-Reply-To: <4150B096.1050904@bigfoot.com> +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=ISO-8859-1 +Content-Transfer-Encoding: 8BIT +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/211 +X-Sequence-Number: 8339 + +On Wed, 22 Sep 2004, Gaetano Mendola wrote: + +> Now my question is why the 7.4 choose the hash join ? :-( + +It looks to me that the marge join is faster because there wasn't really +anything to merge, it resulted in 0 rows. Maybe the hash join that is +choosen in 7.4 would have been faster had there been a couple of result +rows (just a guess). + +It would be interesting to compare the plans in 7.4 with and without +hash_join active and see what costs it estimates for a merge join compared +to a hash join. + +-- +/Dennis Bj�rklund + + +From pgsql-performance-owner@postgresql.org Wed Sep 22 09:44:39 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 04393329D95 + for ; + Wed, 22 Sep 2004 09:44:33 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 71194-03 + for ; + Wed, 22 Sep 2004 08:44:29 +0000 (GMT) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by svr1.postgresql.org (Postfix) with ESMTP id 065E1329CDB + for ; + Wed, 22 Sep 2004 09:44:30 +0100 (BST) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by news.hub.org (8.12.9/8.12.9) with ESMTP id i8M8iQfi072946 + for ; Wed, 22 Sep 2004 08:44:28 GMT + (envelope-from news@news.hub.org) +Received: (from news@localhost) + by news.hub.org (8.12.9/8.12.9/Submit) id i8M8M8gQ065875 + for pgsql-performance@postgresql.org; Wed, 22 Sep 2004 08:22:08 GMT +From: Gaetano Mendola +X-Newsgroups: comp.databases.postgresql.performance +Subject: Re: 7.4 vs 7.3 ( hash join issue ) +Date: Wed, 22 Sep 2004 10:22:05 +0200 +Organization: PYRENET Midi-pyrenees Provider +Lines: 68 +Message-ID: <4151362C.6070106@bigfoot.com> +References: <4150B096.1050904@bigfoot.com> + +Mime-Version: 1.0 +Content-Type: text/plain; charset=ISO-8859-1; format=flowed +Content-Transfer-Encoding: 7bit +X-Complaints-To: abuse@pyrenet.fr +To: Dennis Bjorklund +User-Agent: Mozilla Thunderbird 0.8 (Windows/20040913) +X-Accept-Language: en-us, en +In-Reply-To: +X-Enigmail-Version: 0.86.1.0 +X-Enigmail-Supports: pgp-inline, pgp-mime +To: pgsql-performance@postgresql.org +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/212 +X-Sequence-Number: 8340 + +Dennis Bjorklund wrote: +> On Wed, 22 Sep 2004, Gaetano Mendola wrote: +> +> +>>Now my question is why the 7.4 choose the hash join ? :-( +> +> +> It looks to me that the marge join is faster because there wasn't really +> anything to merge, it resulted in 0 rows. Maybe the hash join that is +> choosen in 7.4 would have been faster had there been a couple of result +> rows (just a guess). +> +> It would be interesting to compare the plans in 7.4 with and without +> hash_join active and see what costs it estimates for a merge join compared +> to a hash join. + +Here they are: + +hash_join = on + + QUERY PLAN +-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Limit (cost=10.21..10.21 rows=1 width=24) (actual time=0.885..0.885 rows=0 loops=1) + -> Sort (cost=10.21..10.21 rows=1 width=24) (actual time=0.880..0.880 rows=0 loops=1) + Sort Key: e.id_evento + -> Hash Join (cost=9.02..10.21 rows=1 width=24) (actual time=0.687..0.687 rows=0 loops=1) + Hash Cond: ("outer".id_tipo_evento = "inner".id_tipo_evento) + -> Seq Scan on lookup_tipo_evento le (cost=0.00..1.16 rows=16 width=32) (actual time=0.017..0.038 rows=16 loops=1) + -> Hash (cost=9.02..9.02 rows=1 width=16) (actual time=0.212..0.212 rows=0 loops=1) + -> Index Scan using t_evento_id_pratica_key on t_evento e (cost=0.00..9.02 rows=1 width=16) (actual time=0.208..0.208 rows=0 loops=1) + Index Cond: (id_pratica = 5) + Filter: (((id_tipo_evento)::text = '5'::text) OR ((id_tipo_evento)::text = '6'::text) OR ((id_tipo_evento)::text = '7'::text) OR ((id_tipo_evento)::text = '8'::text)) + Total runtime: 1.244 ms +(11 rows) + +hash_join = off + QUERY PLAN +-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Limit (cost=10.28..10.28 rows=1 width=24) (actual time=0.429..0.429 rows=0 loops=1) + -> Sort (cost=10.28..10.28 rows=1 width=24) (actual time=0.425..0.425 rows=0 loops=1) + Sort Key: e.id_evento + -> Merge Join (cost=10.25..10.27 rows=1 width=24) (actual time=0.218..0.218 rows=0 loops=1) + Merge Cond: ("outer".id_tipo_evento = "inner".id_tipo_evento) + -> Sort (cost=9.02..9.02 rows=1 width=16) (actual time=0.214..0.214 rows=0 loops=1) + Sort Key: e.id_tipo_evento + -> Index Scan using t_evento_id_pratica_key on t_evento e (cost=0.00..9.02 rows=1 width=16) (actual time=0.110..0.110 rows=0 loops=1) + Index Cond: (id_pratica = 5) + Filter: (((id_tipo_evento)::text = '5'::text) OR ((id_tipo_evento)::text = '6'::text) OR ((id_tipo_evento)::text = '7'::text) OR ((id_tipo_evento)::text = '8'::text)) + -> Sort (cost=1.22..1.23 rows=16 width=32) (never executed) + Sort Key: le.id_tipo_evento + -> Seq Scan on lookup_tipo_evento le (cost=0.00..1.16 rows=16 width=32) (never executed) + Total runtime: 0.721 ms +(14 rows) + + + + + +Regards +Gaetano Mendola + + + + + + + + + +From pgsql-performance-owner@postgresql.org Wed Sep 22 10:32:28 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 23A35329E80 + for ; + Wed, 22 Sep 2004 10:32:27 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 88332-01 + for ; + Wed, 22 Sep 2004 09:32:22 +0000 (GMT) +Received: from zigo.dhs.org (as2-4-3.an.g.bonet.se [194.236.34.191]) + by svr1.postgresql.org (Postfix) with ESMTP id E62EC329E7E + for ; + Wed, 22 Sep 2004 10:32:20 +0100 (BST) +Received: from zigo.zigo.dhs.org (zigo.zigo.dhs.org [192.168.0.1]) + by zigo.dhs.org (Postfix) with ESMTP + id A67AE8467; Wed, 22 Sep 2004 11:32:19 +0200 (CEST) +Date: Wed, 22 Sep 2004 11:32:19 +0200 (CEST) +From: Dennis Bjorklund +To: Gaetano Mendola +Cc: pgsql-performance@postgresql.org +Subject: Re: 7.4 vs 7.3 ( hash join issue ) +In-Reply-To: <4151362C.6070106@bigfoot.com> +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=ISO-8859-1 +Content-Transfer-Encoding: 8BIT +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/213 +X-Sequence-Number: 8341 + +On Wed, 22 Sep 2004, Gaetano Mendola wrote: + +> Limit (cost=10.21..10.21 rows=1 width=24) (actual time=0.885..0.885 rows=0 loops=1) +> Limit (cost=10.28..10.28 rows=1 width=24) (actual time=0.429..0.429 rows=0 loops=1) + +These estimated costs are almost the same, but the runtime differs a bit. +This means that maybe you need to alter settings like random_page_cost, +effective_cache and maybe some others to make the cost reflect the runtime +better. + +Since the costs are so close to each other very small changes can make it +choose the other plan. It's also very hard to make an estimate that is +correct in all situations. That's why it's called an estimate after all. + +-- +/Dennis Bj�rklund + + +From pgsql-performance-owner@postgresql.org Wed Sep 22 11:44:34 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 28738329C82 + for ; + Wed, 22 Sep 2004 11:44:33 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 10604-02 + for ; + Wed, 22 Sep 2004 10:44:27 +0000 (GMT) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by svr1.postgresql.org (Postfix) with ESMTP id 9DCF5329C6B + for ; + Wed, 22 Sep 2004 11:44:28 +0100 (BST) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by news.hub.org (8.12.9/8.12.9) with ESMTP id i8MAiQfg012278 + for ; Wed, 22 Sep 2004 10:44:26 GMT + (envelope-from news@news.hub.org) +Received: (from news@localhost) + by news.hub.org (8.12.9/8.12.9/Submit) id i8MAS7Vu007190 + for pgsql-performance@postgresql.org; Wed, 22 Sep 2004 10:28:07 GMT +From: Gaetano Mendola +X-Newsgroups: comp.databases.postgresql.performance +Subject: Re: 7.4 vs 7.3 ( hash join issue ) +Date: Wed, 22 Sep 2004 12:28:04 +0200 +Organization: PYRENET Midi-pyrenees Provider +Lines: 65 +Message-ID: <415153B4.5040902@bigfoot.com> +References: <4151362C.6070106@bigfoot.com> + +Mime-Version: 1.0 +Content-Type: text/plain; charset=ISO-8859-1; format=flowed +Content-Transfer-Encoding: 7bit +X-Complaints-To: abuse@pyrenet.fr +To: Dennis Bjorklund +User-Agent: Mozilla Thunderbird 0.8 (Windows/20040913) +X-Accept-Language: en-us, en +In-Reply-To: +X-Enigmail-Version: 0.86.1.0 +X-Enigmail-Supports: pgp-inline, pgp-mime +To: pgsql-performance@postgresql.org +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/214 +X-Sequence-Number: 8342 + +Dennis Bjorklund wrote: + > On Wed, 22 Sep 2004, Gaetano Mendola wrote: + > + > + >> Limit (cost=10.21..10.21 rows=1 width=24) (actual time=0.885..0.885 rows=0 loops=1) + >> Limit (cost=10.28..10.28 rows=1 width=24) (actual time=0.429..0.429 rows=0 loops=1) + > + > + > These estimated costs are almost the same, but the runtime differs a bit. + > This means that maybe you need to alter settings like random_page_cost, + > effective_cache and maybe some others to make the cost reflect the runtime + > better. + > + > Since the costs are so close to each other very small changes can make it + > choose the other plan. It's also very hard to make an estimate that is + > correct in all situations. That's why it's called an estimate after all. + +Is not feseable. + +That values are obtained with random_page_cost = 2, effective_cache_size = 20000, +cpu_tuple_cost = 0.01 +increasing or decreasing random_page_cost this means increase or decrease both +costs: + + +random_page_cost = 1.5 + hashjoin on => 8.47 + hashjoin off => 8.53 + + +random_page_cost = 3 + hashjoin on => 13.70 + hashjoin off => 13.76 + + +so is choosen the hasjoin method in both cases. + +In the other side the effective_cache_size doesn't affect this costs. + +Decreasing the cpu_tuple_cost have the same effect + +cpu_tuple_cost = 0.005 + hashjoin on => 10.11 + hashjoin off => 10.17 + +cpu_tuple_cost = 0.001 + hashjoin on => 10.03 + hashjoin off => 10.03 + +cpu_tuple_cost = 0.0005 + hashjoin on => 10.01 + hashjoin off => 10.01 + + And when the two costs are the same the hashjoin path is choosen. + +I think cpu_tuple_cost less then 0.001 is not a good idea + +I think the only way is set the hashjoin = off. Any other suggestion ? + +Regards +Gaetano Mendola + + + + + +From pgsql-performance-owner@postgresql.org Wed Sep 22 14:43:39 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id A1D5C329D7F + for ; + Wed, 22 Sep 2004 14:43:37 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 71491-03 + for ; + Wed, 22 Sep 2004 13:43:30 +0000 (GMT) +Received: from stark.xeocode.com (gsstark.mtl.istop.com [66.11.160.162]) + by svr1.postgresql.org (Postfix) with ESMTP id C18AF329D18 + for ; + Wed, 22 Sep 2004 14:43:32 +0100 (BST) +Received: from localhost ([127.0.0.1] helo=stark.xeocode.com) + by stark.xeocode.com with smtp (Exim 3.36 #1 (Debian)) + id 1CA7P3-0002Ie-00; Wed, 22 Sep 2004 09:43:25 -0400 +To: Gaetano Mendola +Cc: Dennis Bjorklund , + pgsql-performance@postgresql.org +Subject: Re: 7.4 vs 7.3 ( hash join issue ) +References: <4150B096.1050904@bigfoot.com> + + <4151362C.6070106@bigfoot.com> +In-Reply-To: <4151362C.6070106@bigfoot.com> +From: Greg Stark +Organization: The Emacs Conspiracy; member since 1992 +Date: 22 Sep 2004 09:43:24 -0400 +Message-ID: <87y8j2ctc3.fsf@stark.xeocode.com> +Lines: 18 +User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/215 +X-Sequence-Number: 8343 + + +Gaetano Mendola writes: + +> hash_join = on +> -> Seq Scan on lookup_tipo_evento le (cost=0.00..1.16 rows=16 width=32) (actual time=0.017..0.038 rows=16 loops=1) +> +> hash_join = off +> -> Seq Scan on lookup_tipo_evento le (cost=0.00..1.16 rows=16 width=32) (never executed) + + +Actually this looks like it's arguably a bug to me. Why does the hash join +execute the sequential scan at all? Shouldn't it also like the merge join +recognize that the other hashed relation is empty and skip the sequential scan +entirely? + + +-- +greg + + +From pgsql-performance-owner@postgresql.org Wed Sep 22 16:22:51 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 723E6329CB0 + for ; + Wed, 22 Sep 2004 16:22:50 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 12961-07 + for ; + Wed, 22 Sep 2004 15:22:45 +0000 (GMT) +Received: from zigo.dhs.org (as2-4-3.an.g.bonet.se [194.236.34.191]) + by svr1.postgresql.org (Postfix) with ESMTP id 1268B329C82 + for ; + Wed, 22 Sep 2004 16:22:44 +0100 (BST) +Received: from zigo.zigo.dhs.org (zigo.zigo.dhs.org [192.168.0.1]) + by zigo.dhs.org (Postfix) with ESMTP + id D0F698467; Wed, 22 Sep 2004 17:22:42 +0200 (CEST) +Date: Wed, 22 Sep 2004 17:22:42 +0200 (CEST) +From: Dennis Bjorklund +To: Greg Stark +Cc: Gaetano Mendola , +Subject: Re: 7.4 vs 7.3 ( hash join issue ) +In-Reply-To: <87y8j2ctc3.fsf@stark.xeocode.com> +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=ISO-8859-1 +Content-Transfer-Encoding: 8BIT +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/216 +X-Sequence-Number: 8344 + +On 22 Sep 2004, Greg Stark wrote: + +> Actually this looks like it's arguably a bug to me. Why does the hash +> join execute the sequential scan at all? Shouldn't it also like the +> merge join recognize that the other hashed relation is empty and skip +> the sequential scan entirely? + +I'm not sure you can classify that as a bug. It's just that he in one of +the plans started with the empty scan and bacause of that didn't need +the other, but with the hash join it started with the table that had 16 +rows and then got to the empty one. + +While I havn't checked, I assume that if it had started with the empty +table there then it would have skipped the other. + +I don't know what criteria is used to select which part to start with when +doing a hash join. Looks like it started with the one that had the highest +estimate of rows here, doing it the other way around might be a good idea +because you in some cases are lucky to find an empty scans and can omit +the other. + +The above are just observations of the behaviour, I've not seen the source +at all. + +-- +/Dennis Bj�rklund + + +From pgsql-performance-owner@postgresql.org Wed Sep 22 18:38:20 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 58B98329DD1 + for ; + Wed, 22 Sep 2004 18:38:18 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 64801-05 + for ; + Wed, 22 Sep 2004 17:38:12 +0000 (GMT) +Received: from stark.xeocode.com (gsstark.mtl.istop.com [66.11.160.162]) + by svr1.postgresql.org (Postfix) with ESMTP id CED87329D14 + for ; + Wed, 22 Sep 2004 18:38:11 +0100 (BST) +Received: from localhost ([127.0.0.1] helo=stark.xeocode.com) + by stark.xeocode.com with smtp (Exim 3.36 #1 (Debian)) + id 1CAB45-00035h-00; Wed, 22 Sep 2004 13:38:01 -0400 +To: Dennis Bjorklund +Cc: Greg Stark , Gaetano Mendola , + +Subject: Re: 7.4 vs 7.3 ( hash join issue ) +References: +In-Reply-To: +From: Greg Stark +Organization: The Emacs Conspiracy; member since 1992 +Date: 22 Sep 2004 13:38:00 -0400 +Message-ID: <87sm9acih3.fsf@stark.xeocode.com> +Lines: 28 +User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/217 +X-Sequence-Number: 8345 + + +Dennis Bjorklund writes: + +> On 22 Sep 2004, Greg Stark wrote: +> +> > Actually this looks like it's arguably a bug to me. Why does the hash +> > join execute the sequential scan at all? Shouldn't it also like the +> > merge join recognize that the other hashed relation is empty and skip +> > the sequential scan entirely? +> +> I'm not sure you can classify that as a bug. It's just that he in one of +> the plans started with the empty scan and bacause of that didn't need +> the other, but with the hash join it started with the table that had 16 +> rows and then got to the empty one. + +No, postgres didn't do things in reverse order. It hashed the empty table and +then went ahead and checked every record of the non-empty table against the +empty hash table. + +Reading the code there's no check for this, and it seems like it would be a +useful low-cost little optimization. + +I think postgres normally hashes the table it thinks is smaller, so you do +join against an empty relation it should end up on the hash side of the hash +join and allow postgres to avoid the scan of the outer table. + +-- +greg + + +From pgsql-patches-owner@postgresql.org Wed Sep 22 18:56:26 2004 +X-Original-To: pgsql-patches-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id F022A329C67 + for ; + Wed, 22 Sep 2004 18:56:23 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 70901-02 + for ; + Wed, 22 Sep 2004 17:56:17 +0000 (GMT) +Received: from stark.xeocode.com (gsstark.mtl.istop.com [66.11.160.162]) + by svr1.postgresql.org (Postfix) with ESMTP id 702D3329C63 + for ; + Wed, 22 Sep 2004 18:56:16 +0100 (BST) +Received: from localhost ([127.0.0.1] helo=stark.xeocode.com) + by stark.xeocode.com with smtp (Exim 3.36 #1 (Debian)) + id 1CABLh-0003wo-00; Wed, 22 Sep 2004 13:56:13 -0400 +To: Greg Stark +Cc: Dennis Bjorklund , Greg Stark , + Gaetano Mendola , +Subject: Re: [PERFORM] 7.4 vs 7.3 ( hash join issue ) +References: + <87sm9acih3.fsf@stark.xeocode.com> +In-Reply-To: <87sm9acih3.fsf@stark.xeocode.com> +From: Greg Stark +Organization: The Emacs Conspiracy; member since 1992 +Date: 22 Sep 2004 13:56:13 -0400 +Message-ID: <87mzzichmq.fsf@stark.xeocode.com> +Lines: 63 +User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 +MIME-Version: 1.0 +Content-Type: multipart/mixed; + boundary="=NATO-ANZUS-ANDVT-argus-Peking-passwd-undercover-Aladdin-lock-picking" +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/250 +X-Sequence-Number: 13112 + +--=NATO-ANZUS-ANDVT-argus-Peking-passwd-undercover-Aladdin-lock-picking + + +Greg Stark writes: + +> Dennis Bjorklund writes: +> +> > On 22 Sep 2004, Greg Stark wrote: +> > +> > > Actually this looks like it's arguably a bug to me. Why does the hash +> > > join execute the sequential scan at all? Shouldn't it also like the +> > > merge join recognize that the other hashed relation is empty and skip +> > > the sequential scan entirely? +> > +> > I'm not sure you can classify that as a bug. It's just that he in one of +> > the plans started with the empty scan and bacause of that didn't need +> > the other, but with the hash join it started with the table that had 16 +> > rows and then got to the empty one. +> +> No, postgres didn't do things in reverse order. It hashed the empty table and +> then went ahead and checked every record of the non-empty table against the +> empty hash table. + +Alright, attached is a simple patch that changes this. I don't really know +enough of the overall code to be sure this is safe. But from what I see of the +hash join code it never returns any rows unless there's a match except for +outer joins. So I think it should be safe. + +test=# create table a (a integer); +CREATE TABLE +test=# create table b (a integer); +CREATE TABLE +test=# set enable_mergejoin = off; +SET +test=# explain analyze select * from a natural join b; + QUERY PLAN +----------------------------------------------------------------------------------------------------------- + Hash Join (cost=22.50..345.00 rows=5000 width=4) (actual time=0.022..0.022 rows=0 loops=1) + Hash Cond: ("outer".a = "inner".a) + -> Seq Scan on a (cost=0.00..20.00 rows=1000 width=4) (never executed) + -> Hash (cost=20.00..20.00 rows=1000 width=4) (actual time=0.005..0.005 rows=0 loops=1) + -> Seq Scan on b (cost=0.00..20.00 rows=1000 width=4) (actual time=0.002..0.002 rows=0 loops=1) + Total runtime: 0.089 ms +(6 rows) + +By comparison, note the sequential scan doesn't show "never executed" on 7.4.3 +(sorry, I didn't think to run the query against 8.0 before I compiled the +patched version): + + QUERY PLAN +----------------------------------------------------------------------------------------------------------- + Hash Join (cost=22.50..345.00 rows=5000 width=4) (actual time=0.881..0.881 rows=0 loops=1) + Hash Cond: ("outer".a = "inner".a) + -> Seq Scan on a (cost=0.00..20.00 rows=1000 width=4) (actual time=0.001..0.001 rows=0 loops=1) + -> Hash (cost=20.00..20.00 rows=1000 width=4) (actual time=0.008..0.008 rows=0 loops=1) + -> Seq Scan on b (cost=0.00..20.00 rows=1000 width=4) (actual time=0.004..0.004 rows=0 loops=1) + Total runtime: 1.105 ms +(6 rows) + + +--=NATO-ANZUS-ANDVT-argus-Peking-passwd-undercover-Aladdin-lock-picking +Content-Disposition: attachment; filename=hashjoinpatch + +Index: backend/executor/nodeHash.c +=================================================================== +RCS file: /projects/cvsroot/pgsql-server/src/backend/executor/nodeHash.c,v +retrieving revision 1.86 +diff -c -r1.86 nodeHash.c +*** backend/executor/nodeHash.c 29 Aug 2004 04:12:31 -0000 1.86 +--- backend/executor/nodeHash.c 22 Sep 2004 17:51:53 -0000 +*************** +*** 232,237 **** +--- 232,238 ---- + hashtable->buckets = NULL; + hashtable->nbatch = nbatch; + hashtable->curbatch = 0; ++ hashtable->ntup = 0; + hashtable->innerBatchFile = NULL; + hashtable->outerBatchFile = NULL; + hashtable->innerBatchSize = NULL; +*************** +*** 493,498 **** +--- 494,501 ---- + heapTuple->t_len); + hashTuple->next = hashtable->buckets[bucketno]; + hashtable->buckets[bucketno] = hashTuple; ++ ++ hashtable->ntup ++; + } + else + { +Index: backend/executor/nodeHashjoin.c +=================================================================== +RCS file: /projects/cvsroot/pgsql-server/src/backend/executor/nodeHashjoin.c,v +retrieving revision 1.64 +diff -c -r1.64 nodeHashjoin.c +*** backend/executor/nodeHashjoin.c 29 Aug 2004 05:06:42 -0000 1.64 +--- backend/executor/nodeHashjoin.c 22 Sep 2004 17:51:54 -0000 +*************** +*** 127,132 **** +--- 127,140 ---- + hashNode->hashtable = hashtable; + (void) ExecProcNode((PlanState *) hashNode); + ++ /* An empty hash table can't return any matches */ ++ if (hashtable->nbatch == 0 && ++ hashtable->ntup == 0 && ++ node->js.jointype != JOIN_LEFT) ++ { ++ return NULL; ++ } ++ + /* + * Open temp files for outer batches, if needed. Note that file + * buffers are palloc'd in regular executor context. +Index: include/executor/hashjoin.h +=================================================================== +RCS file: /projects/cvsroot/pgsql-server/src/include/executor/hashjoin.h,v +retrieving revision 1.32 +diff -c -r1.32 hashjoin.h +*** include/executor/hashjoin.h 29 Aug 2004 04:13:06 -0000 1.32 +--- include/executor/hashjoin.h 22 Sep 2004 17:52:04 -0000 +*************** +*** 57,62 **** +--- 57,64 ---- + int nbatch; /* number of batches; 0 means 1-pass join */ + int curbatch; /* current batch #, or 0 during 1st pass */ + ++ int ntup; /* Total number of tuples hashed in this batch */ ++ + /* + * all these arrays are allocated for the life of the hash join, but + * only if nbatch > 0: + +--=NATO-ANZUS-ANDVT-argus-Peking-passwd-undercover-Aladdin-lock-picking + + + +-- +greg + +--=NATO-ANZUS-ANDVT-argus-Peking-passwd-undercover-Aladdin-lock-picking-- + + +From pgsql-performance-owner@postgresql.org Wed Sep 22 18:56:52 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 44406329E77 + for ; + Wed, 22 Sep 2004 18:56:45 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 71500-04 + for ; + Wed, 22 Sep 2004 17:56:39 +0000 (GMT) +Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) + by svr1.postgresql.org (Postfix) with ESMTP id 4387B329E63 + for ; + Wed, 22 Sep 2004 18:56:40 +0100 (BST) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id i8MHuY1p014107; + Wed, 22 Sep 2004 13:56:34 -0400 (EDT) +To: Greg Stark +Cc: Dennis Bjorklund , Gaetano Mendola , + pgsql-performance@postgresql.org +Subject: Re: 7.4 vs 7.3 ( hash join issue ) +In-reply-to: <87sm9acih3.fsf@stark.xeocode.com> +References: + <87sm9acih3.fsf@stark.xeocode.com> +Comments: In-reply-to Greg Stark + message dated "22 Sep 2004 13:38:00 -0400" +Date: Wed, 22 Sep 2004 13:56:34 -0400 +Message-ID: <14106.1095875794@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/218 +X-Sequence-Number: 8346 + +Greg Stark writes: +> No, postgres didn't do things in reverse order. It hashed the empty table and +> then went ahead and checked every record of the non-empty table against the +> empty hash table. + +> Reading the code there's no check for this, and it seems like it would be a +> useful low-cost little optimization. + +Yeah, I was just looking at doing that. + +It would also be interesting to prefetch one row from the outer table and fall +out immediately (without building the hash table) if the outer table is +empty. This seems to require some contortion of the code though :-( + +> I think postgres normally hashes the table it thinks is smaller, + +Right, it will prefer to put the physically smaller table (estimated +width*rows) on the inside. + + regards, tom lane + +From pgsql-patches-owner@postgresql.org Wed Sep 22 19:46:37 2004 +X-Original-To: pgsql-patches-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 1F8CD329E73; + Wed, 22 Sep 2004 19:46:33 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 87514-06; Wed, 22 Sep 2004 18:46:26 +0000 (GMT) +Received: from stark.xeocode.com (gsstark.mtl.istop.com [66.11.160.162]) + by svr1.postgresql.org (Postfix) with ESMTP id 17A36329E6B; + Wed, 22 Sep 2004 19:46:26 +0100 (BST) +Received: from localhost ([127.0.0.1] helo=stark.xeocode.com) + by stark.xeocode.com with smtp (Exim 3.36 #1 (Debian)) + id 1CAC84-0004sZ-00; Wed, 22 Sep 2004 14:46:13 -0400 +To: Tom Lane +Cc: Greg Stark , Dennis Bjorklund , + Gaetano Mendola , + pgsql-performance@postgresql.org, pgsql-patches@postgresql.org +Subject: Re: [PERFORM] 7.4 vs 7.3 ( hash join issue ) +References: + <87sm9acih3.fsf@stark.xeocode.com> <14106.1095875794@sss.pgh.pa.us> +In-Reply-To: <14106.1095875794@sss.pgh.pa.us> +From: Greg Stark +Organization: The Emacs Conspiracy; member since 1992 +Date: 22 Sep 2004 14:46:12 -0400 +Message-ID: <87brfycfbf.fsf@stark.xeocode.com> +Lines: 36 +User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 +MIME-Version: 1.0 +Content-Type: multipart/mixed; + boundary="=IRA-Mafia-Dateline-morse-chameleon-man-Panama-investigation-AUTODIN-" +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/251 +X-Sequence-Number: 13113 + +--=IRA-Mafia-Dateline-morse-chameleon-man-Panama-investigation-AUTODIN- + + +Tom Lane writes: + +> Yeah, I was just looking at doing that. + +Well I imagine it takes you as long to read my patch as it would for you to +write it. But anyways it's still useful to me as exercises. + +> It would also be interesting to prefetch one row from the outer table and fall +> out immediately (without building the hash table) if the outer table is +> empty. This seems to require some contortion of the code though :-( + +Why is it any more complicated than just moving the hash build down lower? +There's one small special case needed in ExecHashJoinOuterGetTuple but it's +pretty non-intrusive. + +It seems to work for me but I can't test multiple batches easily. I think I've +convinced myself that they would work fine but... + +test=# explain analyze select * from a natural join b; + QUERY PLAN +----------------------------------------------------------------------------------------------------- + Hash Join (cost=22.50..345.00 rows=5000 width=4) (actual time=0.005..0.005 rows=0 loops=1) + Hash Cond: ("outer".a = "inner".a) + -> Seq Scan on a (cost=0.00..20.00 rows=1000 width=4) (actual time=0.002..0.002 rows=0 loops=1) + -> Hash (cost=20.00..20.00 rows=1000 width=4) (never executed) + -> Seq Scan on b (cost=0.00..20.00 rows=1000 width=4) (never executed) + Total runtime: 0.070 ms +(6 rows) + + + +--=IRA-Mafia-Dateline-morse-chameleon-man-Panama-investigation-AUTODIN- +Content-Disposition: attachment; filename=hashjoinpatch2 + +Index: backend/executor/nodeHash.c +=================================================================== +RCS file: /projects/cvsroot/pgsql-server/src/backend/executor/nodeHash.c,v +retrieving revision 1.86 +diff -c -r1.86 nodeHash.c +*** backend/executor/nodeHash.c 29 Aug 2004 04:12:31 -0000 1.86 +--- backend/executor/nodeHash.c 22 Sep 2004 18:37:40 -0000 +*************** +*** 232,237 **** +--- 232,238 ---- + hashtable->buckets = NULL; + hashtable->nbatch = nbatch; + hashtable->curbatch = 0; ++ hashtable->ntup = 0; + hashtable->innerBatchFile = NULL; + hashtable->outerBatchFile = NULL; + hashtable->innerBatchSize = NULL; +*************** +*** 493,498 **** +--- 494,501 ---- + heapTuple->t_len); + hashTuple->next = hashtable->buckets[bucketno]; + hashtable->buckets[bucketno] = hashTuple; ++ ++ hashtable->ntup ++; + } + else + { +Index: backend/executor/nodeHashjoin.c +=================================================================== +RCS file: /projects/cvsroot/pgsql-server/src/backend/executor/nodeHashjoin.c,v +retrieving revision 1.64 +diff -c -r1.64 nodeHashjoin.c +*** backend/executor/nodeHashjoin.c 29 Aug 2004 05:06:42 -0000 1.64 +--- backend/executor/nodeHashjoin.c 22 Sep 2004 18:37:41 -0000 +*************** +*** 109,143 **** + ResetExprContext(econtext); + + /* +- * if this is the first call, build the hash table for inner relation +- */ +- if (!node->hj_hashdone) +- { +- /* +- * create the hash table +- */ +- Assert(hashtable == NULL); +- hashtable = ExecHashTableCreate((Hash *) hashNode->ps.plan, +- node->hj_HashOperators); +- node->hj_HashTable = hashtable; +- +- /* +- * execute the Hash node, to build the hash table +- */ +- hashNode->hashtable = hashtable; +- (void) ExecProcNode((PlanState *) hashNode); +- +- /* +- * Open temp files for outer batches, if needed. Note that file +- * buffers are palloc'd in regular executor context. +- */ +- for (i = 0; i < hashtable->nbatch; i++) +- hashtable->outerBatchFile[i] = BufFileCreateTemp(false); +- +- node->hj_hashdone = true; +- } +- +- /* + * Now get an outer tuple and probe into the hash table for matches + */ + outerTupleSlot = node->js.ps.ps_OuterTupleSlot; +--- 109,114 ---- +*************** +*** 163,171 **** +--- 134,180 ---- + node->hj_MatchedOuter = false; + + /* ++ * if this is the first call, build the hash table for inner relation ++ */ ++ if (!node->hj_hashdone) ++ { ++ /* ++ * create the hash table ++ */ ++ Assert(hashtable == NULL); ++ hashtable = ExecHashTableCreate((Hash *) hashNode->ps.plan, ++ node->hj_HashOperators); ++ node->hj_HashTable = hashtable; ++ ++ /* ++ * execute the Hash node, to build the hash table ++ */ ++ hashNode->hashtable = hashtable; ++ (void) ExecProcNode((PlanState *) hashNode); ++ ++ /* An empty hash table can't return any matches */ ++ if (hashtable->nbatch == 0 && ++ hashtable->ntup == 0 && ++ node->js.jointype != JOIN_LEFT) ++ { ++ return NULL; ++ } ++ ++ /* ++ * Open temp files for outer batches, if needed. Note that file ++ * buffers are palloc'd in regular executor context. ++ */ ++ for (i = 0; i < hashtable->nbatch; i++) ++ hashtable->outerBatchFile[i] = BufFileCreateTemp(false); ++ ++ node->hj_hashdone = true; ++ } ++ ++ /* + * now we have an outer tuple, find the corresponding bucket + * for this tuple from the hash table + */ ++ + node->hj_CurBucketNo = ExecHashGetBucket(hashtable, econtext, + outerkeys); + node->hj_CurTuple = NULL; +*************** +*** 503,511 **** + ExecHashJoinOuterGetTuple(PlanState *node, HashJoinState *hjstate) + { + HashJoinTable hashtable = hjstate->hj_HashTable; +! int curbatch = hashtable->curbatch; + TupleTableSlot *slot; + + if (curbatch == 0) + { /* if it is the first pass */ + slot = ExecProcNode(node); +--- 512,531 ---- + ExecHashJoinOuterGetTuple(PlanState *node, HashJoinState *hjstate) + { + HashJoinTable hashtable = hjstate->hj_HashTable; +! int curbatch; + TupleTableSlot *slot; + ++ /* The very first tuple of the first batch is done before the hash table is ++ * built to avoid building an unnecessary hash table. If it's not there ++ * there is no need for subsequent batches anyways. If it is the hash table ++ * will get built and we'll handle it normally for subsequent batches. ++ */ ++ ++ if (!hjstate->hj_hashdone) { ++ return ExecProcNode(node); ++ } ++ ++ curbatch = hashtable->curbatch; + if (curbatch == 0) + { /* if it is the first pass */ + slot = ExecProcNode(node); +Index: include/executor/hashjoin.h +=================================================================== +RCS file: /projects/cvsroot/pgsql-server/src/include/executor/hashjoin.h,v +retrieving revision 1.32 +diff -c -r1.32 hashjoin.h +*** include/executor/hashjoin.h 29 Aug 2004 04:13:06 -0000 1.32 +--- include/executor/hashjoin.h 22 Sep 2004 18:37:54 -0000 +*************** +*** 57,62 **** +--- 57,64 ---- + int nbatch; /* number of batches; 0 means 1-pass join */ + int curbatch; /* current batch #, or 0 during 1st pass */ + ++ int ntup; /* Total number of tuples hashed in this batch */ ++ + /* + * all these arrays are allocated for the life of the hash join, but + * only if nbatch > 0: + +--=IRA-Mafia-Dateline-morse-chameleon-man-Panama-investigation-AUTODIN- + + +-- +greg + +--=IRA-Mafia-Dateline-morse-chameleon-man-Panama-investigation-AUTODIN--- + + +From pgsql-patches-owner@postgresql.org Wed Sep 22 20:01:00 2004 +X-Original-To: pgsql-patches-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id F3EF3329D27 + for ; + Wed, 22 Sep 2004 20:00:50 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 94406-02 + for ; + Wed, 22 Sep 2004 19:00:42 +0000 (GMT) +Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) + by svr1.postgresql.org (Postfix) with ESMTP id B9D91329E85 + for ; + Wed, 22 Sep 2004 20:00:43 +0100 (BST) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id i8MJ0Z3V017292; + Wed, 22 Sep 2004 15:00:35 -0400 (EDT) +To: Greg Stark +Cc: Dennis Bjorklund , Gaetano Mendola , + pgsql-performance@postgresql.org, pgsql-patches@postgresql.org +Subject: Re: [PERFORM] 7.4 vs 7.3 ( hash join issue ) +In-reply-to: <87brfycfbf.fsf@stark.xeocode.com> +References: + <87sm9acih3.fsf@stark.xeocode.com> <14106.1095875794@sss.pgh.pa.us> + <87brfycfbf.fsf@stark.xeocode.com> +Comments: In-reply-to Greg Stark + message dated "22 Sep 2004 14:46:12 -0400" +Date: Wed, 22 Sep 2004 15:00:35 -0400 +Message-ID: <17291.1095879635@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/252 +X-Sequence-Number: 13114 + +Greg Stark writes: +>> It would also be interesting to prefetch one row from the outer table and fall +>> out immediately (without building the hash table) if the outer table is +>> empty. This seems to require some contortion of the code though :-( + +> Why is it any more complicated than just moving the hash build down lower? + +Having to inject the consideration into ExecHashJoinOuterGetTuple seems +messy to me. + +On reflection I'm not sure it would be a win anyway, for a couple of reasons. +(1) Assuming that the planner has gotten things right and put the larger +relation on the outside, the case of an empty outer relation and a +nonempty inner one should rarely arise. +(2) Doing this would lose some of the benefit from the optimization to +detect an empty inner relation. If the outer subplan is a slow-start +one (such as another hashjoin), it would lose a lot of the benefit :-( + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Wed Sep 22 20:51:14 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 3FE38329D27 + for ; + Wed, 22 Sep 2004 20:51:06 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 11914-03 + for ; + Wed, 22 Sep 2004 19:50:59 +0000 (GMT) +Received: from mproxy.gmail.com (rproxy.gmail.com [64.233.170.197]) + by svr1.postgresql.org (Postfix) with ESMTP id 8FF9E329D18 + for ; + Wed, 22 Sep 2004 20:50:59 +0100 (BST) +Received: by mproxy.gmail.com with SMTP id 79so2078554rnk + for ; + Wed, 22 Sep 2004 12:50:45 -0700 (PDT) +Received: by 10.38.74.50 with SMTP id w50mr4242256rna; + Wed, 22 Sep 2004 12:50:26 -0700 (PDT) +Received: by 10.38.73.17 with HTTP; Wed, 22 Sep 2004 12:50:26 -0700 (PDT) +Message-ID: +Date: Wed, 22 Sep 2004 16:50:26 -0300 +From: Scott Kirkwood +Reply-To: Scott Kirkwood +To: pgsql-performance@postgresql.org +Subject: Caching of Queries +Mime-Version: 1.0 +Content-Type: text/plain; charset=US-ASCII +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/221 +X-Sequence-Number: 8349 + +I couldn't find anything in the docs or in the mailing list on this, +but it is something that Oracle appears to do as does MySQL. +The idea, I believe, is to do a quick (hash) string lookup of the +query and if it's exactly the same as another query that has been done +recently to re-use the old parse tree. +It should save the time of doing the parsing of the SQL and looking up +the object in the system tables. +It should probably go through the planner again because values passed +as parameters may have changed. Although, for extra points it could +look at the previous query plan as a hint. +On the surface it looks like an easy enhancement, but what do I know? +I suppose it would benefit mostly those programs that use a lot of +PQexecParams() with simple queries where a greater percentage of the +time is spent parsing the SQL rather than building the execute plan. +What do you think? + +From pgsql-performance-owner@postgresql.org Wed Sep 22 20:59:23 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 6CBFB329CD9 + for ; + Wed, 22 Sep 2004 20:59:21 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 11523-09 + for ; + Wed, 22 Sep 2004 19:59:13 +0000 (GMT) +Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) + by svr1.postgresql.org (Postfix) with ESMTP id 8B89A329E73 + for ; + Wed, 22 Sep 2004 20:59:14 +0100 (BST) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id i8MJx7ZD018411; + Wed, 22 Sep 2004 15:59:08 -0400 (EDT) +To: Scott Kirkwood +Cc: pgsql-performance@postgresql.org +Subject: Re: Caching of Queries +In-reply-to: +References: +Comments: In-reply-to Scott Kirkwood + message dated "Wed, 22 Sep 2004 16:50:26 -0300" +Date: Wed, 22 Sep 2004 15:59:07 -0400 +Message-ID: <18410.1095883147@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/222 +X-Sequence-Number: 8350 + +Scott Kirkwood writes: +> What do you think? + +I think this would allow the problems of cached plans to bite +applications that were previously not subject to them :-(. +An app that wants plan re-use can use PREPARE to identify the +queries that are going to be re-executed. + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Wed Sep 22 21:09:29 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 59450329D27 + for ; + Wed, 22 Sep 2004 21:09:27 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 14649-08 + for ; + Wed, 22 Sep 2004 20:09:20 +0000 (GMT) +Received: from e2.ny.us.ibm.com (e2.ny.us.ibm.com [32.97.182.102]) + by svr1.postgresql.org (Postfix) with ESMTP id 81E0B329D14 + for ; + Wed, 22 Sep 2004 21:09:19 +0100 (BST) +Received: from northrelay02.pok.ibm.com (northrelay02.pok.ibm.com + [9.56.224.150]) + by e2.ny.us.ibm.com (8.12.10/8.12.9) with ESMTP id i8MK9D7J044872 + for ; Wed, 22 Sep 2004 16:09:13 -0400 +Received: from d01ml255.pok.ibm.com (d01av04.pok.ibm.com [9.56.224.64]) + by northrelay02.pok.ibm.com (8.12.10/NCO/VER6.6) with ESMTP id + i8MKAQeb157282 + for ; Wed, 22 Sep 2004 16:10:26 -0400 +Subject: Infinite CPU loop due to field ::type casting +To: pgsql-performance@postgresql.org +X-Mailer: Lotus Notes Release 6.0.2CF1 June 9, 2003 +Message-ID: + +From: Steven Rosenstein +Date: Wed, 22 Sep 2004 16:09:10 -0400 +X-MIMETrack: Serialize by Router on D01ML255/01/M/IBM(Release 6.51HF562 | + September 17, 2004) at 09/22/2004 16:09:12 +MIME-Version: 1.0 +Content-type: text/plain; charset=US-ASCII +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/223 +X-Sequence-Number: 8351 + + + + + +Gentlefolk, + +I'm not sure if this is the proper forum for this question, and it might +have been answered in a previous thread, but I'm new to PostgreSQL and the +research I did in the archives did not turn up anything addressing this +issue. Please direct me to the proper forum is this is not the correct +venue. + +Environment: Red Hat Enterprise Linux 3 Workstation, PostgreSQL V7.3.6 +(stock with the RHEL distribution) + +The two tables I used in the example are tbl_device and tbl_sad_event: + +vsa=# \d vsa.tbl_device; + Table "vsa.tbl_device" + Column | Type | +Modifiers +----------------+--------------------------+--------------------------------------------------------- + id | integer | not null default +nextval('vsa.tbl_device_id_seq'::text) + name | character varying(100) | not null + account_id | bigint | not null + vss_site_id | bigint | not null + org_site_id | bigint | not null default 0 + device_type_id | integer | not null default 1 + os_family_id | integer | not null default 0 + status_id | integer | not null default 0 + timezone | character varying(80) | + clientkey | character varying(2048) | not null + record_created | timestamp with time zone | default now() +Indexes: pk_tbl_device primary key btree (id), + idx_d_uniq_name_site_account_key unique btree (name, vss_site_id, +account_id, clientkey), + tbl_device_clientkey_key unique btree (clientkey), + idx_d_account_id btree (account_id), + idx_d_account_site_name btree (account_id, vss_site_id, name), + idx_d_device_type_id btree (device_type_id), + idx_d_name btree (name), + idx_d_org_site_id btree (org_site_id), + idx_d_os_family_id btree (os_family_id), + idx_d_status_id btree (status_id), + idx_d_vss_site_id btree (vss_site_id) +Foreign Key constraints: fk_d_va FOREIGN KEY (account_id) REFERENCES +vsa.tbl_vsa_account(id) ON UPDATE NO ACTION ON DELETE NO ACTION, + fk_d_vs FOREIGN KEY (vss_site_id) REFERENCES +vsa.tbl_vss_site(id) ON UPDATE NO ACTION ON DELETE NO ACTION, + fk_d_dof FOREIGN KEY (os_family_id) REFERENCES +vsa.enum_device_os_family(id) ON UPDATE NO ACTION ON DELETE NO ACTION, + fk_d_dsc FOREIGN KEY (status_id) REFERENCES +vsa.enum_device_status_code(id) ON UPDATE NO ACTION ON DELETE NO ACTION, + fk_d_dt FOREIGN KEY (device_type_id) REFERENCES +vsa.enum_device_type(id) ON UPDATE NO ACTION ON DELETE NO ACTION +Triggers: trg_clean_device_name + +vsa=# \d vsa.tbl_sad_event + Table "vsa.tbl_sad_event" + Column | Type | +Modifiers +----------------+-----------------------------+------------------------------------------------------------ + id | integer | not null default +nextval('vsa.tbl_sad_event_id_seq'::text) + device_id | bigint | not null + log_type | integer | + severity | character varying(20) | + time_logged | timestamp without time zone | + user_name | character varying(50) | + remote_user | character varying(50) | + remote_host | character varying(100) | + source_tag | character varying(30) | + event_code | character varying(50) | + type | character varying(6) | + record_created | timestamp with time zone | default now() +Indexes: pk_tbl_sad_event primary key btree (id), + idx_se_dev_time_type btree (device_id, time_logged, "type"), + idx_se_device_id btree (device_id), + idx_se_time_logged btree (time_logged), + idx_se_type btree ("type"), + sjr_se_id_time_type btree (device_id, time_logged, "type") +Foreign Key constraints: fk_sade_d FOREIGN KEY (device_id) REFERENCES +vsa.tbl_device(id) ON UPDATE NO ACTION ON DELETE CASCADE + + +Here is my original query, and the query plan generated by the planner: + +vsa=# explain +SELECT dev.name, dev.vss_site_id, tbl.log_type, tbl.severity, tbl.count +FROM vsa.tbl_device AS dev +LEFT OUTER JOIN + (SELECT stbl.device_id, stbl.log_type, stbl.severity, count(*) + FROM vsa.dtbl_logged_event_20040922 AS stbl + WHERE stbl.log_type IN (2, 3, 4, 5) + GROUP BY stbl.device_id, stbl.log_type, stbl.severity) AS tbl + ON (dev.id=tbl.device_id) +ORDER BY dev.name; + QUERY PLAN + +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ + Sort (cost=40893.18..40960.93 rows=27100 width=79) + Sort Key: dev.name + -> Merge Join (cost=38417.13..38897.77 rows=27100 width=79) + Merge Cond: ("outer".id = "inner".device_id) + -> Sort (cost=869.52..872.70 rows=1275 width=26) + Sort Key: dev.id + -> Seq Scan on tbl_device dev (cost=0.00..803.75 rows=1275 width=26) + -> Sort (cost=37547.62..37615.37 rows=27100 width=26) + Sort Key: tbl.device_id + -> Subquery Scan tbl (cost=0.00..35552.21 rows=27100 width=26) + -> Aggregate (cost=0.00..35552.21 rows=27100 width=26) + -> Group (cost=0.00..34874.70 rows=271005 width=26) + -> Index Scan using idx_le_id_type_severity_evtcode_20040922 on dtbl_logged_event_20040922 stbl +(cost=0.00..32842.16 rows=271005 width=26) + Filter: ((log_type = 2) OR (log_type = 3) OR (log_type = 4) OR (log_type = 5)) +(14 rows) + +Time: 1.43 ms + + +Late in the development I realized that we had created an inconsistency in +our design by having vsa.tbl_device.id defined as "int", and +vsa.tbl_sad_event.device_id defined as "bigint". These two fields are used +in the ON clause (ON (dev.id=tbl.device_id)), and my understanding is that +they should be of the same type cast. Trying to remedy this situation, I +explicitly tried casting vsa.tbl_sad_event.device_id as "int" (::int): + +vsa=# explain +SELECT dev.name, dev.vss_site_id, tbl.log_type, tbl.severity, tbl.count +FROM vsa.tbl_device AS dev +LEFT OUTER JOIN + (SELECT stbl.device_id, stbl.log_type, stbl.severity, count(*) + FROM vsa.dtbl_logged_event_20040922 AS stbl + WHERE stbl.log_type IN (2, 3, 4, 5) GROUP BY stbl.device_id, +stbl.log_type, stbl.severity) AS tbl + ON (dev.id=tbl.device_id::int) +ORDER BY dev.name; + QUERY PLAN + +------------------------------------------------------------------------------------------------------------------------------------------------------------------ + Nested Loop (cost=0.00..45848850.65 rows=27100 width=79) + Join Filter: ("outer".id = ("inner".device_id)::integer) + -> Index Scan using idx_d_name on tbl_device dev (cost=0.00..1490.19 rows=1275 width=26) + -> Subquery Scan tbl (cost=0.00..35552.21 rows=27100 width=26) + -> Aggregate (cost=0.00..35552.21 rows=27100 width=26) + -> Group (cost=0.00..34874.70 rows=271005 width=26) + -> Index Scan using idx_le_id_type_severity_evtcode_20040922 on dtbl_logged_event_20040922 stbl (cost=0.00..32842.16 +rows=271005 width=26) + Filter: ((log_type = 2) OR (log_type = 3) OR (log_type = 4) OR (log_type = 5)) +(8 rows) + +Time: 1.62 ms + + +Notice that the query plan changes completely when I cast device_id as int. +What is worse (and why I'm writing) is that when I run the second query, it +goes into an infinite CPU loop. The original query completed in under 4 +seconds. I've left the second query running for 30 minutes or more, and +TOP show 100% CPU utilization and 0% disk I/O (0% iowait). + +We are starting to see this phenomenon in other queries which do *not* have +any explicit type casting, but in which something like +"cast(vsa.tbl_sad_event.time_logged AS date)" is used in a WHERE clause. +It's becoming a show-stopper until we understand what is happening. + +Any information or suggestions about this problem or making the query more +efficient will be greatly appreciated. + +Thanks! +--- Steve + + +From pgsql-performance-owner@postgresql.org Wed Sep 22 21:33:31 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 30FE2329E44 + for ; + Wed, 22 Sep 2004 21:33:30 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 24317-03 + for ; + Wed, 22 Sep 2004 20:33:21 +0000 (GMT) +Received: from e2.ny.us.ibm.com (e2.ny.us.ibm.com [32.97.182.102]) + by svr1.postgresql.org (Postfix) with ESMTP id A2AB7329E3C + for ; + Wed, 22 Sep 2004 21:33:21 +0100 (BST) +Received: from northrelay04.pok.ibm.com (northrelay04.pok.ibm.com + [9.56.224.206]) + by e2.ny.us.ibm.com (8.12.10/8.12.9) with ESMTP id i8MKXK7J358540 + for ; Wed, 22 Sep 2004 16:33:20 -0400 +Received: from d01ml255.pok.ibm.com (d01av04.pok.ibm.com [9.56.224.64]) + by northrelay04.pok.ibm.com (8.12.10/NCO/VER6.6) with ESMTP id + i8MKYY6D088044 + for ; Wed, 22 Sep 2004 16:34:34 -0400 +Subject: Fw: Infinite CPU loop due to field ::type casting, Take II :-) +To: pgsql-performance@postgresql.org +X-Mailer: Lotus Notes Release 6.0.2CF1 June 9, 2003 +Message-ID: + +From: Steven Rosenstein +Date: Wed, 22 Sep 2004 16:33:16 -0400 +X-MIMETrack: Serialize by Router on D01ML255/01/M/IBM(Release 6.51HF562 | + September 17, 2004) at 09/22/2004 16:33:20 +MIME-Version: 1.0 +Content-type: text/plain; charset=US-ASCII +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/225 +X-Sequence-Number: 8353 + + + + + +I just realized in my haste to send this email out I provided the wrong +table in my example. Below is the same email, but with +vsa.dtbl_logged_event_20040922 substituted for vsa.tbl_sad_event. + +Sorry for the inconvenience. + +--- Steve + + +Gentlefolk, + +I'm not sure if this is the proper forum for this question, and it might +have been answered in a previous thread, but I'm new to PostgreSQL and the +research I did in the archives did not turn up anything addressing this +issue. Please direct me to the proper forum is this is not the correct +venue. + +Environment: Red Hat Enterprise Linux 3 Workstation, PostgreSQL V7.3.6 +(stock with the RHEL distribution) + +The two tables I used in the example are tbl_device and +dtbl_logged_event_20040922: + +vsa=# \d vsa.tbl_device; + Table "vsa.tbl_device" + Column | Type | +Modifiers +----------------+--------------------------+--------------------------------------------------------- + id | integer | not null default +nextval('vsa.tbl_device_id_seq'::text) + name | character varying(100) | not null + account_id | bigint | not null + vss_site_id | bigint | not null + org_site_id | bigint | not null default 0 + device_type_id | integer | not null default 1 + os_family_id | integer | not null default 0 + status_id | integer | not null default 0 + timezone | character varying(80) | + clientkey | character varying(2048) | not null + record_created | timestamp with time zone | default now() +Indexes: pk_tbl_device primary key btree (id), + idx_d_uniq_name_site_account_key unique btree (name, vss_site_id, +account_id, clientkey), + tbl_device_clientkey_key unique btree (clientkey), + idx_d_account_id btree (account_id), + idx_d_account_site_name btree (account_id, vss_site_id, name), + idx_d_device_type_id btree (device_type_id), + idx_d_name btree (name), + idx_d_org_site_id btree (org_site_id), + idx_d_os_family_id btree (os_family_id), + idx_d_status_id btree (status_id), + idx_d_vss_site_id btree (vss_site_id) +Foreign Key constraints: fk_d_va FOREIGN KEY (account_id) REFERENCES +vsa.tbl_vsa_account(id) ON UPDATE NO ACTION ON DELETE NO ACTION, + fk_d_vs FOREIGN KEY (vss_site_id) REFERENCES +vsa.tbl_vss_site(id) ON UPDATE NO ACTION ON DELETE NO ACTION, + fk_d_dof FOREIGN KEY (os_family_id) REFERENCES +vsa.enum_device_os_family(id) ON UPDATE NO ACTION ON DELETE NO ACTION, + fk_d_dsc FOREIGN KEY (status_id) REFERENCES +vsa.enum_device_status_code(id) ON UPDATE NO ACTION ON DELETE NO ACTION, + fk_d_dt FOREIGN KEY (device_type_id) REFERENCES +vsa.enum_device_type(id) ON UPDATE NO ACTION ON DELETE NO ACTION +Triggers: trg_clean_device_name + +vsa=# \d vsa.dtbl_logged_event_20040922 + Table +"vsa.dtbl_logged_event_20040922" + Column | Type | +Modifiers +-----------------+-----------------------------+------------------------------------------------------------------------- + id | integer | not null default +nextval('vsa.dtbl_logged_event_20040922_id_seq'::text) + device_id | bigint | not null + report_datetime | timestamp without time zone | + time_logged | timestamp without time zone | + log_type | integer | not null + type | character varying(50) | + severity | character varying(30) | + source_tag | character varying(30) | + remote_host | character varying(100) | + user_name | character varying(50) | + event_code | character varying(10) | + description | text | + record_created | timestamp with time zone | default now() + event_code_new | character varying(30) | + remote_user | character varying(50) | +Indexes: pk_dtbl_logged_event_20040922 primary key btree (id), + idx_le_device_id_20040922 btree (device_id), + idx_le_id_source_event_20040922 btree (device_id, source_tag, +event_code), + idx_le_id_src_20040922 btree (device_id, source_tag), + idx_le_id_type_severity_evtcode_20040922 btree (device_id, +log_type, severity, event_code), + idx_le_log_type_20040922 btree (log_type), + idx_le_source_tag_20040922 btree (source_tag), + idx_le_time_logged_20040922 btree (time_logged), + idx_le_time_type_20040922 btree (time_logged, log_type) +Foreign Key constraints: fk_le_lelt_20040922 FOREIGN KEY (log_type) +REFERENCES vsa.enum_le_log_type(id) ON UPDATE NO ACTION ON DELETE NO +ACTION, + fk_le_d_20040922 FOREIGN KEY (device_id) +REFERENCES vsa.tbl_device(id) ON UPDATE NO ACTION ON DELETE CASCADE + + +Here is my original query, and the query plan generated by the planner: + +vsa=# explain +SELECT dev.name, dev.vss_site_id, tbl.log_type, tbl.severity, tbl.count +FROM vsa.tbl_device AS dev +LEFT OUTER JOIN + (SELECT stbl.device_id, stbl.log_type, stbl.severity, count(*) + FROM vsa.dtbl_logged_event_20040922 AS stbl + WHERE stbl.log_type IN (2, 3, 4, 5) + GROUP BY stbl.device_id, stbl.log_type, stbl.severity) AS tbl + ON (dev.id=tbl.device_id) +ORDER BY dev.name; + QUERY PLAN + +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ + Sort (cost=40893.18..40960.93 rows=27100 width=79) + Sort Key: dev.name + -> Merge Join (cost=38417.13..38897.77 rows=27100 width=79) + Merge Cond: ("outer".id = "inner".device_id) + -> Sort (cost=869.52..872.70 rows=1275 width=26) + Sort Key: dev.id + -> Seq Scan on tbl_device dev (cost=0.00..803.75 rows=1275 width=26) + -> Sort (cost=37547.62..37615.37 rows=27100 width=26) + Sort Key: tbl.device_id + -> Subquery Scan tbl (cost=0.00..35552.21 rows=27100 width=26) + -> Aggregate (cost=0.00..35552.21 rows=27100 width=26) + -> Group (cost=0.00..34874.70 rows=271005 width=26) + -> Index Scan using idx_le_id_type_severity_evtcode_20040922 on dtbl_logged_event_20040922 stbl +(cost=0.00..32842.16 rows=271005 width=26) + Filter: ((log_type = 2) OR (log_type = 3) OR (log_type = 4) OR (log_type = 5)) +(14 rows) + +Time: 1.43 ms + + +Late in the development I realized that we had created an inconsistency in +our design by having vsa.tbl_device.id defined as "int", and +vsa.dtbl_logged_event_20040922.device_id defined as "bigint". These two +fields are used in the ON clause (ON (dev.id=tbl.device_id)), and my +understanding is that they should be of the same type cast. Trying to +remedy this situation, I explicitly tried casting +vsa.dtbl_logged_event_20040922.device_id as "int" (::int): + +vsa=# explain +SELECT dev.name, dev.vss_site_id, tbl.log_type, tbl.severity, tbl.count +FROM vsa.tbl_device AS dev +LEFT OUTER JOIN + (SELECT stbl.device_id, stbl.log_type, stbl.severity, count(*) + FROM vsa.dtbl_logged_event_20040922 AS stbl + WHERE stbl.log_type IN (2, 3, 4, 5) GROUP BY stbl.device_id, +stbl.log_type, stbl.severity) AS tbl + ON (dev.id=tbl.device_id::int) +ORDER BY dev.name; + QUERY PLAN + +------------------------------------------------------------------------------------------------------------------------------------------------------------------ + Nested Loop (cost=0.00..45848850.65 rows=27100 width=79) + Join Filter: ("outer".id = ("inner".device_id)::integer) + -> Index Scan using idx_d_name on tbl_device dev (cost=0.00..1490.19 rows=1275 width=26) + -> Subquery Scan tbl (cost=0.00..35552.21 rows=27100 width=26) + -> Aggregate (cost=0.00..35552.21 rows=27100 width=26) + -> Group (cost=0.00..34874.70 rows=271005 width=26) + -> Index Scan using idx_le_id_type_severity_evtcode_20040922 on dtbl_logged_event_20040922 stbl (cost=0.00..32842.16 +rows=271005 width=26) + Filter: ((log_type = 2) OR (log_type = 3) OR (log_type = 4) OR (log_type = 5)) +(8 rows) + +Time: 1.62 ms + + +Notice that the query plan changes completely when I cast device_id as int. +What is worse (and why I'm writing) is that when I run the second query, it +goes into an infinite CPU loop. The original query completed in under 4 +seconds. I've left the second query running for 30 minutes or more, and +TOP show 100% CPU utilization and 0% disk I/O (0% iowait). + +We are starting to see this phenomenon in other queries which do *not* have +any explicit type casting, but in which something like +"cast(vsa.dtbl_logged_event_20040922.time_logged AS date)" is used in a +WHERE clause. It's becoming a show-stopper until we understand what is +happening. + +Any information or suggestions about this problem or making the query more +efficient will be greatly appreciated. + +Thanks! +--- Steve + + +From pgsql-performance-owner@postgresql.org Wed Sep 22 21:31:55 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 7E85B329E65 + for ; + Wed, 22 Sep 2004 21:31:53 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 24593-01 + for ; + Wed, 22 Sep 2004 20:31:45 +0000 (GMT) +Received: from mail.libertyrms.com (unknown [207.219.45.62]) + by svr1.postgresql.org (Postfix) with ESMTP id 3A338329E45 + for ; + Wed, 22 Sep 2004 21:31:45 +0100 (BST) +Received: from dba4.int.libertyrms.com ([10.1.3.13] ident=ahammond) + by mail.libertyrms.com with esmtp (Exim 4.22) + id 1CADmD-0002YA-Ao; Wed, 22 Sep 2004 16:31:45 -0400 +Message-ID: <4151E1E7.2000009@ca.afilias.info> +Date: Wed, 22 Sep 2004 16:34:47 -0400 +From: Andrew Hammond +Organization: Afilias Canada Corp. +User-Agent: Mozilla Thunderbird 0.7.3 (X11/20040830) +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: Postgresql Performance +Cc: Rod Taylor +Subject: Re: NAS, SAN or any alternate solution ? +References: + + <1090344321.7056.105.camel@jester> +In-Reply-To: <1090344321.7056.105.camel@jester> +X-Enigmail-Version: 0.85.0.0 +X-Enigmail-Supports: pgp-inline, pgp-mime +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit +X-SA-Exim-Mail-From: ahammond@ca.afilias.info +X-SA-Exim-Scanned: No; SAEximRunCond expanded to false +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/224 +X-Sequence-Number: 8352 + +-----BEGIN PGP SIGNED MESSAGE----- +Hash: SHA1 + +Rod Taylor wrote: +| I've used both a NetApp and Hitachi based SANs with PostgreSQL. Both +| work as well as expected, but do require some tweeking as they normally +| are not optimized for the datablock size that PostgreSQL likes to deal +| with (8k by default) -- this can make as much as a 50% difference in +| performance levels. + +I'm looking for documentation about the datablock size you mentioned above. + +My goal is to tune the disk / filesystem on our prototype system. It's +an EMC disk array, so sectors on disk are 512 bytes of usable space. +We've decided to go with RAID 10 since the goal is to maximize +performance. Currently the raid element size is set at 16 sectors which +is 8192 bytes of payload. I've got a sysadmin working on getting XFS +going with 8192 byte blocks. My next task will be to calculate the +amount of space used by XFS for headers etc. to find out how much of +those 8192 bytes can be used for the postgres payload. Then configure +postgres to use datablocks that size. So I'm looking for details on how +to manipulate the size of the datablock. + +I'm also not entirely sure how to make the datablocks line up with the +filesystem blocks. Any suggestions on this would be greatly appreciated. + +- -- +Andrew Hammond 416-673-4138 ahammond@ca.afilias.info +Database Administrator, Afilias Canada Corp. +CB83 2838 4B67 D40F D086 3568 81FC E7E5 27AF 4A9A +-----BEGIN PGP SIGNATURE----- +Version: GnuPG v1.2.5 (GNU/Linux) + +iD8DBQFBUeHmgfzn5SevSpoRAu2sAJ4nHHup5lhp4+RcgBPGoJpUFoE1SQCgyvW1 +ixyAvqb7ZkB+IIdGb36mpxI= +=uDLW +-----END PGP SIGNATURE----- + +From pgsql-performance-owner@postgresql.org Wed Sep 22 21:53:18 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id CE947329CF8 + for ; + Wed, 22 Sep 2004 21:53:11 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 29120-04 + for ; + Wed, 22 Sep 2004 20:53:04 +0000 (GMT) +Received: from tht.net (vista.tht.net [216.126.88.2]) + by svr1.postgresql.org (Postfix) with ESMTP id D3E79329C6B + for ; + Wed, 22 Sep 2004 21:53:04 +0100 (BST) +Received: from [134.22.69.205] (dyn-69-205.tor.dsl.tht.net [134.22.69.205]) + by tht.net (Postfix) with ESMTP + id 612B276A67; Wed, 22 Sep 2004 16:53:02 -0400 (EDT) +Subject: Re: NAS, SAN or any alternate solution ? +From: Rod Taylor +To: Andrew Hammond +Cc: Postgresql Performance +In-Reply-To: <4151E1E7.2000009@ca.afilias.info> +References: + + <1090344321.7056.105.camel@jester> <4151E1E7.2000009@ca.afilias.info> +Content-Type: text/plain +Message-Id: <1095886379.24440.56.camel@jester> +Mime-Version: 1.0 +X-Mailer: Ximian Evolution 1.4.6 +Date: Wed, 22 Sep 2004 16:52:59 -0400 +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/226 +X-Sequence-Number: 8354 + +> Rod Taylor wrote: +> | I've used both a NetApp and Hitachi based SANs with PostgreSQL. Both +> | work as well as expected, but do require some tweeking as they normally +> | are not optimized for the datablock size that PostgreSQL likes to deal +> | with (8k by default) -- this can make as much as a 50% difference in +> | performance levels. + +> I'm also not entirely sure how to make the datablocks line up with the +> filesystem blocks. Any suggestions on this would be greatly appreciated. + +We just played with Veritas settings while running pg_bench on a 200GB +database. I no longer have access to the NetApp, but the settings for +the Hitachi are below. + +In tunefstab we have: + +read_pref_io=8192,read_nstream=4,write_pref_io=8192,write_nstream=2 + +In fstab it's: + defaults,mincache=tmpcache,noatime + + +If you have better settings, please shoot them over so we can try them +out. Perhaps even get someone over there to write a new SAN section in +the Tuning Chapter. + + +From pgsql-performance-owner@postgresql.org Sun Sep 26 20:24:20 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 7B887329E64 + for ; + Wed, 22 Sep 2004 22:44:08 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 46404-04 + for ; + Wed, 22 Sep 2004 21:44:00 +0000 (GMT) +Received: from hotmail.com (bay9-dav21.bay9.hotmail.com [64.4.46.125]) + by svr1.postgresql.org (Postfix) with ESMTP id 91B6D329E17 + for ; + Wed, 22 Sep 2004 22:44:01 +0100 (BST) +Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; + Wed, 22 Sep 2004 14:44:00 -0700 +Received: from 67.81.98.198 by bay9-dav21.bay9.hotmail.com with DAV; + Wed, 22 Sep 2004 21:43:12 +0000 +X-Originating-IP: [67.81.98.198] +X-Originating-Email: [awerman@hotmail.com] +X-Sender: awerman@hotmail.com +From: "Aaron Werman" +To: "Scott Kirkwood" , + +References: +Subject: Re: Caching of Queries +Date: Wed, 22 Sep 2004 17:43:16 -0400 +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 6.00.2800.1437 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 +Message-ID: +X-OriginalArrivalTime: 22 Sep 2004 21:44:00.0666 (UTC) + FILETIME=[457BEFA0:01C4A0ED] +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/272 +X-Sequence-Number: 8400 + +There is a difference between MySQL and Oracle here. + +Oracle, to reduce parse/planner costs, hashes statements to see if it can +match an existing optimizer plan. This is optional and there are a few +flavors that range from a characher to characyter match through parse tree +matches through replacing of literals in the statements with parameters. +This dramatically improves performance in almost all high transaction rate +systems. + +MySQL stores a statement with its results. This is optional and when a +client allows this type of processing, the SQL is hashed and matched to the +statement - and the stored *result* is returned. The point is that a lot of +systems do lots of static queries, such as a pick list on a web page - but +if the data changes the prior result is returned. This (plus a stable jdbc +driver) was the reason MySQL did well in the eWeek database comparison. + +/Aaron + + + +----- Original Message ----- +From: "Scott Kirkwood" +To: +Sent: Wednesday, September 22, 2004 3:50 PM +Subject: [PERFORM] Caching of Queries + + +> I couldn't find anything in the docs or in the mailing list on this, +> but it is something that Oracle appears to do as does MySQL. +> The idea, I believe, is to do a quick (hash) string lookup of the +> query and if it's exactly the same as another query that has been done +> recently to re-use the old parse tree. +> It should save the time of doing the parsing of the SQL and looking up +> the object in the system tables. +> It should probably go through the planner again because values passed +> as parameters may have changed. Although, for extra points it could +> look at the previous query plan as a hint. +> On the surface it looks like an easy enhancement, but what do I know? +> I suppose it would benefit mostly those programs that use a lot of +> PQexecParams() with simple queries where a greater percentage of the +> time is spent parsing the SQL rather than building the execute plan. +> What do you think? +> +> ---------------------------(end of broadcast)--------------------------- +> TIP 7: don't forget to increase your free space map settings +> + +From pgsql-performance-owner@postgresql.org Wed Sep 22 22:49:13 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id D48C8329CF8 + for ; + Wed, 22 Sep 2004 22:49:10 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 46404-06 + for ; + Wed, 22 Sep 2004 21:49:03 +0000 (GMT) +Received: from vt-pe2550-001.VANTAGE.vantage.com (unknown [64.80.203.242]) + by svr1.postgresql.org (Postfix) with ESMTP id C8243329E64 + for ; + Wed, 22 Sep 2004 22:49:02 +0100 (BST) +X-MimeOLE: Produced By Microsoft Exchange V6.0.6249.0 +content-class: urn:content-classes:message +MIME-Version: 1.0 +Content-Type: multipart/alternative; + boundary="----_=_NextPart_001_01C4A0ED.F93C8FE4" +Subject: SAN performance +Date: Wed, 22 Sep 2004 17:49:02 -0400 +Message-ID: + <4BAFBB6B9CC46F41B2AD7D9F4BBAF785018B4049@vt-pe2550-001.vantage.vantage.com> +X-MS-Has-Attach: +X-MS-TNEF-Correlator: +Thread-Topic: SAN performance +Thread-Index: AcSg7fk6DNUKcUPbTpqwKexS5AAopA== +From: "Anjan Dave" +To: +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.1 tagged_above=0.0 required=5.0 tests=HTML_60_70, + HTML_MESSAGE +X-Spam-Level: +X-Archive-Number: 200409/227 +X-Sequence-Number: 8355 + +This is a multi-part message in MIME format. + +------_=_NextPart_001_01C4A0ED.F93C8FE4 +Content-Type: text/plain; + charset="us-ascii" +Content-Transfer-Encoding: quoted-printable + +Hello, + +=20 + +I'll be moving a DB from internal RAID-10 SCSI storage to an EMC CX300 +FC RAID-10 LUN, bound to the host. I've setup a test host machine and a +test LUN. The /var/lib/pgsql/data folder is sym-linked to a partition on +the LUN.=20 + +=20 + +Other than the shared_buffers, effective cache size, and sort memory, I +am not sure if I need to change any other parameters in the +postgresql.conf file for getting maximum performance from the EMC box. + +=20 + +Is there a general guideline for setting up postgres database and the +tunable parameters on a SAN, especially for EMC? + +=20 + +Appreciate any help, + +=20 + +Thanks, +Anjan + + +------_=_NextPart_001_01C4A0ED.F93C8FE4 +Content-Type: text/html; + charset="us-ascii" +Content-Transfer-Encoding: quoted-printable + + + + + + + + + + + + +
+ +

Hello,

+ +

 

+ +

I’ll be moving a DB from internal RAID-10 SCSI sto= +rage +to an EMC CX300 FC RAID-10 LUN, bound to the host. I’ve setup a test = +host +machine and a test LUN. The /var/lib/pgsql/data folder is sym-linked to a p= +artition +on the LUN.

+ +

 

+ +

Other than the shared_buffers, effective cache size, and +sort memory, I am not sure if I need to change any other parameters in the +postgresql.conf file for getting maximum performance from the EMC box.= +

+ +

 

+ +

Is there a general guideline for setting up postgres dat= +abase +and the tunable parameters on a SAN, especially for EMC?<= +/font>

+ +

 

+ +

Appreciate any help,

+ +

 

+ +

Thanks,
+Anjan

+ +
+ + + + + +------_=_NextPart_001_01C4A0ED.F93C8FE4-- + +From pgsql-performance-owner@postgresql.org Wed Sep 22 23:03:55 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 25972329CDB + for ; + Wed, 22 Sep 2004 23:03:53 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 52762-05 + for ; + Wed, 22 Sep 2004 22:03:44 +0000 (GMT) +Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) + by svr1.postgresql.org (Postfix) with ESMTP id B1D97329E69 + for ; + Wed, 22 Sep 2004 23:03:45 +0100 (BST) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id i8MM3j64019168; + Wed, 22 Sep 2004 18:03:45 -0400 (EDT) +To: Steven Rosenstein +Cc: pgsql-performance@postgresql.org +Subject: Re: Fw: Infinite CPU loop due to field ::type casting, Take II :-) +In-reply-to: + +References: + +Comments: In-reply-to Steven Rosenstein + message dated "Wed, 22 Sep 2004 16:33:16 -0400" +Date: Wed, 22 Sep 2004 18:03:45 -0400 +Message-ID: <19167.1095890625@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/228 +X-Sequence-Number: 8356 + +Steven Rosenstein writes: +> Environment: Red Hat Enterprise Linux 3 Workstation, PostgreSQL V7.3.6 + +> vsa=# explain +> SELECT dev.name, dev.vss_site_id, tbl.log_type, tbl.severity, tbl.count +> FROM vsa.tbl_device AS dev +> LEFT OUTER JOIN +> (SELECT stbl.device_id, stbl.log_type, stbl.severity, count(*) +> FROM vsa.dtbl_logged_event_20040922 AS stbl +> WHERE stbl.log_type IN (2, 3, 4, 5) GROUP BY stbl.device_id, +> stbl.log_type, stbl.severity) AS tbl +> ON (dev.id=tbl.device_id::int) +> ORDER BY dev.name; +> QUERY PLAN + +> ------------------------------------------------------------------------------------------------------------------------------------------------------------------ +> Nested Loop (cost=0.00..45848850.65 rows=27100 width=79) +> Join Filter: ("outer".id = ("inner".device_id)::integer) +> -> Index Scan using idx_d_name on tbl_device dev (cost=0.00..1490.19 rows=1275 width=26) +> -> Subquery Scan tbl (cost=0.00..35552.21 rows=27100 width=26) +> -> Aggregate (cost=0.00..35552.21 rows=27100 width=26) +> -> Group (cost=0.00..34874.70 rows=271005 width=26) +> -> Index Scan using idx_le_id_type_severity_evtcode_20040922 on dtbl_logged_event_20040922 stbl (cost=0.00..32842.16 +> rows=271005 width=26) +> Filter: ((log_type = 2) OR (log_type = 3) OR (log_type = 4) OR (log_type = 5)) +> (8 rows) + +> Time: 1.62 ms + + +> Notice that the query plan changes completely when I cast device_id as int. +> What is worse (and why I'm writing) is that when I run the second query, it +> goes into an infinite CPU loop. + +"Bad plan" and "infinite loop" are two very different things. + +In 7.3 you'd be better off without the cast, as you just found out. The +7.3 backend can only handle merge or hash joins that use a join clause +of the form "variable = variable" --- anything more complicated falls +back to a nested loop join. It does handle mergejoins between unlike +data types, though, so you were doing okay with the undecorated query. + +7.4 is smarter; dunno if you want to upgrade at this point. + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Thu Sep 23 03:14:53 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id B7B5B329E45 + for ; + Thu, 23 Sep 2004 03:14:50 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 11479-10 + for ; + Thu, 23 Sep 2004 02:14:39 +0000 (GMT) +Received: from sue.samurai.com (sue.samurai.com [205.207.28.74]) + by svr1.postgresql.org (Postfix) with ESMTP id 5DF6D329E43 + for ; + Thu, 23 Sep 2004 03:14:42 +0100 (BST) +Received: from localhost (localhost [127.0.0.1]) + by sue.samurai.com (Postfix) with ESMTP id 7252F3F17; + Wed, 22 Sep 2004 22:14:43 -0400 (EDT) +Received: from sue.samurai.com ([127.0.0.1]) + by localhost (sue.samurai.com [127.0.0.1]) (amavisd-new, port 10024) + with LMTP id 49757-01-9; Wed, 22 Sep 2004 22:14:42 -0400 (EDT) +Received: from localhost (unknown [61.88.101.19]) + by sue.samurai.com (Postfix) with ESMTP id 85B9B3F00; + Wed, 22 Sep 2004 22:14:40 -0400 (EDT) +Subject: Re: Caching of Queries +From: Neil Conway +To: Tom Lane +Cc: Scott Kirkwood , + pgsql-performance@postgresql.org +In-Reply-To: <18410.1095883147@sss.pgh.pa.us> +References: + <18410.1095883147@sss.pgh.pa.us> +Content-Type: text/plain +Message-Id: <1095905663.22485.294.camel@localhost.localdomain> +Mime-Version: 1.0 +X-Mailer: Ximian Evolution 1.4.6 +Date: Thu, 23 Sep 2004 12:14:24 +1000 +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at mailbox.samurai.com +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/229 +X-Sequence-Number: 8357 + +On Thu, 2004-09-23 at 05:59, Tom Lane wrote: +> I think this would allow the problems of cached plans to bite +> applications that were previously not subject to them :-(. +> An app that wants plan re-use can use PREPARE to identify the +> queries that are going to be re-executed. + +I agree; if you want to do some work in this area, making improvements +to PREPARE would IMHO be the best bet. For example, some people have +talked about having PREPARE store queries in shared memory. Another idea +would be to improve the quality of the plan we generate at PREPARE time: +for instance you could generate 'n' plans for various combinations of +input parameters, and then choose the best query plan at EXECUTE time. +It's a difficult problem to solve, however (consider multiple parameters +to PREPARE, for example). + +-Neil + + + +From pgsql-performance-owner@postgresql.org Thu Sep 23 04:42:11 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 1FD0F329E3C + for ; + Thu, 23 Sep 2004 04:41:42 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 35690-01 + for ; + Thu, 23 Sep 2004 03:41:36 +0000 (GMT) +Received: from stark.xeocode.com (gsstark.mtl.istop.com [66.11.160.162]) + by svr1.postgresql.org (Postfix) with ESMTP id 66FBF329E58 + for ; + Thu, 23 Sep 2004 04:41:34 +0100 (BST) +Received: from localhost ([127.0.0.1] helo=stark.xeocode.com) + by stark.xeocode.com with smtp (Exim 3.36 #1 (Debian)) + id 1CAKTx-0006Jn-00; Wed, 22 Sep 2004 23:41:21 -0400 +To: Andrew Hammond +Cc: Postgresql Performance , + Rod Taylor +Subject: Re: NAS, SAN or any alternate solution ? +References: + + <1090344321.7056.105.camel@jester> <4151E1E7.2000009@ca.afilias.info> +In-Reply-To: <4151E1E7.2000009@ca.afilias.info> +From: Greg Stark +Organization: The Emacs Conspiracy; member since 1992 +Date: 22 Sep 2004 23:41:21 -0400 +Message-ID: <87r7otbqji.fsf@stark.xeocode.com> +Lines: 46 +User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/230 +X-Sequence-Number: 8358 + + +Andrew Hammond writes: + +> My goal is to tune the disk / filesystem on our prototype system. It's +> an EMC disk array, so sectors on disk are 512 bytes of usable space. +> We've decided to go with RAID 10 since the goal is to maximize +> performance. Currently the raid element size is set at 16 sectors which +> is 8192 bytes of payload. + +Do people find it works well to have a stripe size that small? It seems like +it would be better to have it be at least a few filesystem/postgres blocks so +that subsequent reads stand a chance of being sequential and not causing +another spindle to have to seek. Does this depend on whether it's an DSS load +vs an OLTP load? If it's a single query at a time DSS system perhaps small +blocksizes work best to get maximum throughput? + +> I've got a sysadmin working on getting XFS going with 8192 byte blocks. + +Having your filesystem block size match postgres's block size is probably a +good idea. So 8k blocks is good. + +> My next task will be to calculate the amount of space used by XFS for +> headers etc. to find out how much of those 8192 bytes can be used for the +> postgres payload. + +No filesystem that I know of uses up space in every block. The overhead is all +stored elsewhere in blocks exclusively contain such overhead data. So just +setting postgres to 8k which the default would work well. + +> Then configure postgres to use datablocks that size. So I'm looking for +> details on how to manipulate the size of the datablock. + +Look in pg_config_manual.h in src/include. Postgres has to be recompiled to +change it and the database has to be reinitialized. But it could be set to 16k +or 32k. In which case you would probably want to adjust your filesystem to +match. But unless you do experiments you won't know if it would be of any +benefit to change. + +> I'm also not entirely sure how to make the datablocks line up with the +> filesystem blocks. Any suggestions on this would be greatly appreciated. + +They just will. The files start on a block boundary, so every 8k is a new +block. Postgres stores 8k at a time always. + +-- +greg + + +From pgsql-performance-owner@postgresql.org Thu Sep 23 04:59:01 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 58D25329E4A + for ; + Thu, 23 Sep 2004 04:58:57 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 39394-03 + for ; + Thu, 23 Sep 2004 03:58:51 +0000 (GMT) +Received: from sue.samurai.com (sue.samurai.com [205.207.28.74]) + by svr1.postgresql.org (Postfix) with ESMTP id 68830329D28 + for ; + Thu, 23 Sep 2004 04:58:51 +0100 (BST) +Received: from localhost (localhost [127.0.0.1]) + by sue.samurai.com (Postfix) with ESMTP id DD4F73F41; + Wed, 22 Sep 2004 23:58:50 -0400 (EDT) +Received: from sue.samurai.com ([127.0.0.1]) + by localhost (sue.samurai.com [127.0.0.1]) (amavisd-new, port 10024) + with LMTP id 54452-01-2; Wed, 22 Sep 2004 23:58:50 -0400 (EDT) +Received: from localhost (unknown [61.88.101.19]) + by sue.samurai.com (Postfix) with ESMTP id 3A2363F3F; + Wed, 22 Sep 2004 23:58:48 -0400 (EDT) +Subject: Re: O_DIRECT setting +From: Neil Conway +To: Guy Thornley +Cc: pgsql-performance@postgresql.org +In-Reply-To: <20040920075734.GK21733@conker.esphion.com> +References: <20040920075734.GK21733@conker.esphion.com> +Content-Type: text/plain +Message-Id: <1095911914.22485.414.camel@localhost.localdomain> +Mime-Version: 1.0 +X-Mailer: Ximian Evolution 1.4.6 +Date: Thu, 23 Sep 2004 13:58:34 +1000 +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at mailbox.samurai.com +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/231 +X-Sequence-Number: 8359 + +On Mon, 2004-09-20 at 17:57, Guy Thornley wrote: +> According to the manpage, O_DIRECT implies O_SYNC: +> +> File I/O is done directly to/from user space buffers. The I/O is +> synchronous, i.e., at the completion of the read(2) or write(2) +> system call, data is guaranteed to have been transferred. + +This seems like it would be a rather large net loss. PostgreSQL already +structures writes so that the writes we need to hit disk immediately +(WAL records) are fsync()'ed -- the kernel is given more freedom to +schedule how other writes are flushed from the cache. Also, my +recollection is that O_DIRECT also disables readahead -- if that's +correct, that's not what we want either. + +BTW, using O_DIRECT has been discussed a few times in the past. Have you +checked the list archives? (for both -performance and -hackers) + +> Would people be interested in a performance benchmark? + +Sure -- I'd definitely be curious, although as I said I'm skeptical it's +a win. + +> I need some benchmark tips :) + +Some people have noted that it can be difficult to use contrib/pgbench +to get reproducible results -- you might want to look at Jan's TPC-W +implementation or the OSDL database benchmarks: + +http://pgfoundry.org/projects/tpc-w-php/ +http://www.osdl.org/lab_activities/kernel_testing/osdl_database_test_suite/ + +> Incidentally, postgres heap files suffer really, really bad fragmentation, +> which affects sequential scan operations (VACUUM, ANALYZE, REINDEX ...) +> quite drastically. We have in-house patches that somewhat alleiviate this, +> but they are not release quality. + +Can you elaborate on these "in-house patches"? + +-Neil + + + +From pgsql-performance-owner@postgresql.org Thu Sep 23 07:35:52 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 7FE16329E42 + for ; + Thu, 23 Sep 2004 07:35:51 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 76423-07 + for ; + Thu, 23 Sep 2004 06:35:44 +0000 (GMT) +Received: from server.gpdnet.co.uk (gpdnet.plus.com [212.56.100.243]) + by svr1.postgresql.org (Postfix) with ESMTP id 69AA8329E3C + for ; + Thu, 23 Sep 2004 07:35:44 +0100 (BST) +Received: from gary (unknown [192.168.1.2]) + by server.gpdnet.co.uk (Postfix) with ESMTP id EEA9CFB88E + for ; + Thu, 23 Sep 2004 07:36:05 +0100 (BST) +From: "Gary Doades" +To: pgsql-performance@postgresql.org +Date: Thu, 23 Sep 2004 07:36:11 +0100 +MIME-Version: 1.0 +Subject: Re: Caching of Queries +Message-ID: <41527CEB.18344.26EF6F28@localhost> +In-reply-to: <18410.1095883147@sss.pgh.pa.us> +References: +X-mailer: Pegasus Mail for Windows (v4.12a) +Content-type: text/plain; charset=US-ASCII +Content-transfer-encoding: 7BIT +Content-description: Mail message body +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/232 +X-Sequence-Number: 8360 + +On 22 Sep 2004 at 15:59, Tom Lane wrote: + +> Scott Kirkwood writes: +> > What do you think? +> +> I think this would allow the problems of cached plans to bite +> applications that were previously not subject to them :-(. +> An app that wants plan re-use can use PREPARE to identify the +> queries that are going to be re-executed. +> +> regards, tom lane +> + +And then there are the people that would like to upgrade and get a +performance gain without having to change their programs. A simple +conf flag could turn query/plan caching off for all those that rely on each +statement being re-planned. + +This is where SQLServer etc. tend to get big wins. I know from direct +comparisons that SQLServer often takes quite a bit longer to parse/plan +a select statement than Postgres, but wins out overall from its +query/plan caching. + +Regards, +Gary. + + +From pgsql-performance-owner@postgresql.org Thu Sep 23 10:14:53 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 2789C329E47 + for ; + Thu, 23 Sep 2004 10:14:52 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 27521-08 + for ; + Thu, 23 Sep 2004 09:14:43 +0000 (GMT) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by svr1.postgresql.org (Postfix) with ESMTP id 86A57329E4F + for ; + Thu, 23 Sep 2004 10:14:45 +0100 (BST) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by news.hub.org (8.12.9/8.12.9) with ESMTP id i8N9Edfi032407 + for ; Thu, 23 Sep 2004 09:14:42 GMT + (envelope-from news@news.hub.org) +Received: (from news@localhost) + by news.hub.org (8.12.9/8.12.9/Submit) id i8N8qPa6024583 + for pgsql-performance@postgresql.org; Thu, 23 Sep 2004 08:52:25 GMT +From: Gaetano Mendola +X-Newsgroups: comp.databases.postgresql.performance +Subject: Re: Caching of Queries +Date: Thu, 23 Sep 2004 10:52:21 +0200 +Organization: PYRENET Midi-pyrenees Provider +Lines: 12 +Message-ID: <41528EC5.8030901@bigfoot.com> +References: + <18410.1095883147@sss.pgh.pa.us> + <1095905663.22485.294.camel@localhost.localdomain> +Mime-Version: 1.0 +Content-Type: text/plain; charset=ISO-8859-1; format=flowed +Content-Transfer-Encoding: 7bit +X-Complaints-To: abuse@pyrenet.fr +To: Neil Conway +User-Agent: Mozilla Thunderbird 0.8 (Windows/20040913) +X-Accept-Language: en-us, en +In-Reply-To: <1095905663.22485.294.camel@localhost.localdomain> +X-Enigmail-Version: 0.86.1.0 +X-Enigmail-Supports: pgp-inline, pgp-mime +To: pgsql-performance@postgresql.org +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/233 +X-Sequence-Number: 8361 + +Neil Conway wrote: +> Another idea would be to improve the quality of the plan we generate at PREPARE time: +> for instance you could generate 'n' plans for various combinations of +> input parameters, and then choose the best query plan at EXECUTE time. +> It's a difficult problem to solve, however (consider multiple parameters +> to PREPARE, for example). + +Do you mean store different plans for each different histogram segment ? + +Regards +Gaetano Mendola + + +From pgsql-performance-owner@postgresql.org Thu Sep 23 14:36:41 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 31AFD329D14 + for ; + Thu, 23 Sep 2004 14:36:39 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 17380-10 + for ; + Thu, 23 Sep 2004 13:36:28 +0000 (GMT) +Received: from candle.pha.pa.us (candle.pha.pa.us [207.106.42.251]) + by svr1.postgresql.org (Postfix) with ESMTP id E3B32329CA4 + for ; + Thu, 23 Sep 2004 14:36:30 +0100 (BST) +Received: (from pgman@localhost) + by candle.pha.pa.us (8.11.6/8.11.6) id i8NDZjR21993; + Thu, 23 Sep 2004 09:35:45 -0400 (EDT) +From: Bruce Momjian +Message-Id: <200409231335.i8NDZjR21993@candle.pha.pa.us> +Subject: Re: O_DIRECT setting +In-Reply-To: <1095911914.22485.414.camel@localhost.localdomain> +To: Neil Conway +Date: Thu, 23 Sep 2004 09:35:45 -0400 (EDT) +Cc: Guy Thornley , pgsql-performance@postgresql.org +X-Mailer: ELM [version 2.4ME+ PL108 (25)] +MIME-Version: 1.0 +Content-Transfer-Encoding: 7bit +Content-Type: text/plain; charset=US-ASCII +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/234 +X-Sequence-Number: 8362 + + +TODO has: + + * Consider use of open/fcntl(O_DIRECT) to minimize OS caching + +Should the item be removed? + +--------------------------------------------------------------------------- + +Neil Conway wrote: +> On Mon, 2004-09-20 at 17:57, Guy Thornley wrote: +> > According to the manpage, O_DIRECT implies O_SYNC: +> > +> > File I/O is done directly to/from user space buffers. The I/O is +> > synchronous, i.e., at the completion of the read(2) or write(2) +> > system call, data is guaranteed to have been transferred. +> +> This seems like it would be a rather large net loss. PostgreSQL already +> structures writes so that the writes we need to hit disk immediately +> (WAL records) are fsync()'ed -- the kernel is given more freedom to +> schedule how other writes are flushed from the cache. Also, my +> recollection is that O_DIRECT also disables readahead -- if that's +> correct, that's not what we want either. +> +> BTW, using O_DIRECT has been discussed a few times in the past. Have you +> checked the list archives? (for both -performance and -hackers) +> +> > Would people be interested in a performance benchmark? +> +> Sure -- I'd definitely be curious, although as I said I'm skeptical it's +> a win. +> +> > I need some benchmark tips :) +> +> Some people have noted that it can be difficult to use contrib/pgbench +> to get reproducible results -- you might want to look at Jan's TPC-W +> implementation or the OSDL database benchmarks: +> +> http://pgfoundry.org/projects/tpc-w-php/ +> http://www.osdl.org/lab_activities/kernel_testing/osdl_database_test_suite/ +> +> > Incidentally, postgres heap files suffer really, really bad fragmentation, +> > which affects sequential scan operations (VACUUM, ANALYZE, REINDEX ...) +> > quite drastically. We have in-house patches that somewhat alleiviate this, +> > but they are not release quality. +> +> Can you elaborate on these "in-house patches"? +> +> -Neil +> +> +> +> ---------------------------(end of broadcast)--------------------------- +> TIP 4: Don't 'kill -9' the postmaster +> + +-- + Bruce Momjian | http://candle.pha.pa.us + pgman@candle.pha.pa.us | (610) 359-1001 + + If your life is a hard drive, | 13 Roberts Road + + Christ can be your backup. | Newtown Square, Pennsylvania 19073 + +From pgsql-performance-owner@postgresql.org Thu Sep 23 15:44:57 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id AA4B2329CF7 + for ; + Thu, 23 Sep 2004 15:44:55 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 46795-02 + for ; + Thu, 23 Sep 2004 14:44:42 +0000 (GMT) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by svr1.postgresql.org (Postfix) with ESMTP id 6F799329D22 + for ; + Thu, 23 Sep 2004 15:44:45 +0100 (BST) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by news.hub.org (8.12.9/8.12.9) with ESMTP id i8NEidfi048346 + for ; Thu, 23 Sep 2004 14:44:39 GMT + (envelope-from news@news.hub.org) +Received: (from news@localhost) + by news.hub.org (8.12.9/8.12.9/Submit) id i8NE4LWC032363 + for pgsql-performance@postgresql.org; Thu, 23 Sep 2004 14:04:21 GMT +From: Gaetano Mendola +X-Newsgroups: comp.databases.postgresql.performance +Subject: Re: 7.4 vs 7.3 ( hash join issue ) +Date: Thu, 23 Sep 2004 16:04:20 +0200 +Organization: PYRENET Midi-pyrenees Provider +Lines: 35 +Message-ID: <4152D7E4.3010409@bigfoot.com> +References: + <87sm9acih3.fsf@stark.xeocode.com> <14106.1095875794@sss.pgh.pa.us> +Mime-Version: 1.0 +Content-Type: text/plain; charset=ISO-8859-1; format=flowed +Content-Transfer-Encoding: 7bit +X-Complaints-To: abuse@pyrenet.fr +To: Tom Lane +User-Agent: Mozilla Thunderbird 0.8 (Windows/20040913) +X-Accept-Language: en-us, en +In-Reply-To: <14106.1095875794@sss.pgh.pa.us> +X-Enigmail-Version: 0.86.1.0 +X-Enigmail-Supports: pgp-inline, pgp-mime +To: pgsql-performance@postgresql.org +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/236 +X-Sequence-Number: 8364 + +Tom Lane wrote: +> Greg Stark writes: +> +>>No, postgres didn't do things in reverse order. It hashed the empty table and +>>then went ahead and checked every record of the non-empty table against the +>>empty hash table. +> +> +>>Reading the code there's no check for this, and it seems like it would be a +>>useful low-cost little optimization. +> +> +> Yeah, I was just looking at doing that. +> +> It would also be interesting to prefetch one row from the outer table and fall +> out immediately (without building the hash table) if the outer table is +> empty. This seems to require some contortion of the code though :-( +> +> +>>I think postgres normally hashes the table it thinks is smaller, +> +> +> Right, it will prefer to put the physically smaller table (estimated +> width*rows) on the inside. + +Do you plan to do a patch for the 7.4, so I'll wait for a 7.4.6 ( that IIRC have already +two important patches pending ) or is 8.0 stuff ? + + + +Regards +Gaetano Mendola + + + + +From pgsql-performance-owner@postgresql.org Thu Sep 23 15:25:58 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 0BD14329CF8 + for ; + Thu, 23 Sep 2004 15:25:57 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 38553-04 + for ; + Thu, 23 Sep 2004 14:24:58 +0000 (GMT) +Received: from main.gmane.org (main.gmane.org [80.91.229.2]) + by svr1.postgresql.org (Postfix) with ESMTP id E8C5A329D28 + for ; + Thu, 23 Sep 2004 15:24:49 +0100 (BST) +Received: from list by main.gmane.org with local (Exim 3.35 #1 (Debian)) + id 1CAUWg-0008Cl-00 + for ; Thu, 23 Sep 2004 16:24:50 +0200 +Received: from srv.protecting.net ([212.126.218.242]) + by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) + id 1AlnuQ-0007hv-00 + for ; Thu, 23 Sep 2004 16:24:50 +0200 +Received: from hf0722x by srv.protecting.net with local (Gmexim 0.1 (Debian)) + id 1AlnuQ-0007hv-00 + for ; Thu, 23 Sep 2004 16:24:50 +0200 +X-Injected-Via-Gmane: http://gmane.org/ +To: pgsql-performance@postgresql.org +From: Harald Fuchs +Subject: Re: Caching of Queries +Date: 23 Sep 2004 16:24:46 +0200 +Organization: Linux Private Site +Lines: 13 +Message-ID: +References: +Reply-To: hf0722x@protecting.net +Mime-Version: 1.0 +Content-Type: text/plain; charset=US-ASCII +X-Complaints-To: usenet@sea.gmane.org +X-Gmane-NNTP-Posting-Host: srv.protecting.net +User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/235 +X-Sequence-Number: 8363 + +In article , +Scott Kirkwood writes: + +> I couldn't find anything in the docs or in the mailing list on this, +> but it is something that Oracle appears to do as does MySQL. +> The idea, I believe, is to do a quick (hash) string lookup of the +> query and if it's exactly the same as another query that has been done +> recently to re-use the old parse tree. + +That's not was MySQL is doing. MySQL caches not the query plan, but +the result set for the (hashed) query string. If the same query comes +again, it is not executed at all (unless one of the tables involved +have been changed meanwhile). + + +From pgsql-performance-owner@postgresql.org Thu Sep 23 15:57:58 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 93837329CF8 + for ; + Thu, 23 Sep 2004 15:57:55 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 52495-04 + for ; + Thu, 23 Sep 2004 14:57:42 +0000 (GMT) +Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) + by svr1.postgresql.org (Postfix) with ESMTP id AD6A5329CF7 + for ; + Thu, 23 Sep 2004 15:57:45 +0100 (BST) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id i8NEvfYo026124; + Thu, 23 Sep 2004 10:57:41 -0400 (EDT) +To: Bruce Momjian +Cc: Neil Conway , Guy Thornley , + pgsql-performance@postgresql.org +Subject: Re: O_DIRECT setting +In-reply-to: <200409231335.i8NDZjR21993@candle.pha.pa.us> +References: <200409231335.i8NDZjR21993@candle.pha.pa.us> +Comments: In-reply-to Bruce Momjian + message dated "Thu, 23 Sep 2004 09:35:45 -0400" +Date: Thu, 23 Sep 2004 10:57:41 -0400 +Message-ID: <26123.1095951461@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/237 +X-Sequence-Number: 8365 + +Bruce Momjian writes: +> TODO has: +> * Consider use of open/fcntl(O_DIRECT) to minimize OS caching +> Should the item be removed? + +I think it's fine ;-) ... it says "consider it", not "do it". The point +is that we could do with more research in this area, even if O_DIRECT +per se is not useful. Maybe you could generalize the entry to +"investigate ways of fine-tuning OS caching behavior". + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Thu Sep 23 16:29:36 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id ACEA2329D28 + for ; + Thu, 23 Sep 2004 16:29:30 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 61295-10 + for ; + Thu, 23 Sep 2004 15:29:28 +0000 (GMT) +Received: from web41114.mail.yahoo.com (web41114.mail.yahoo.com + [66.218.93.30]) + by svr1.postgresql.org (Postfix) with SMTP id EB05D329DB3 + for ; + Thu, 23 Sep 2004 16:29:26 +0100 (BST) +Message-ID: <20040923152925.18234.qmail@web41114.mail.yahoo.com> +Received: from [61.25.53.100] by web41114.mail.yahoo.com via HTTP; + Thu, 23 Sep 2004 08:29:25 PDT +Date: Thu, 23 Sep 2004 08:29:25 -0700 (PDT) +From: Mr Pink +Subject: Re: Caching of Queries +To: Scott Kirkwood , + pgsql-performance@postgresql.org +In-Reply-To: +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/238 +X-Sequence-Number: 8366 + +Not knowing anything about the internals of pg, I don't know how this relates, but in theory, +query plan caching is not just about saving time re-planning queries, it's about scalability. +Optimizing queries requires shared locks on the database metadata, which, as I understand it +causes contention and serialization, which kills scalability. + +I read this thread from last to first, and I'm not sure if I missed something, but if pg isnt +caching plans, then I would say plan caching should be a top priority for future enhancements. It +needn't be complex either: if the SQL string is the same, and none of the tables involved in the +query have changed (in structure), then re-use the cached plan. Basically, DDL and updated +statistics would have to invalidate plans for affected tables. + +Preferably, it should work equally for prepared statements and those not pre-prepared. If you're +not using prepare (and bind variables) though, your plan caching down the drain anyway... + +I don't think that re-optimizing based on values of bind variables is needed. It seems like it +could actually be counter-productive and difficult to asses it's impact. + +That's the way I see it anyway. + +:) + +--- Scott Kirkwood wrote: + +> I couldn't find anything in the docs or in the mailing list on this, +> but it is something that Oracle appears to do as does MySQL. +> The idea, I believe, is to do a quick (hash) string lookup of the +> query and if it's exactly the same as another query that has been done +> recently to re-use the old parse tree. +> It should save the time of doing the parsing of the SQL and looking up +> the object in the system tables. +> It should probably go through the planner again because values passed +> as parameters may have changed. Although, for extra points it could +> look at the previous query plan as a hint. +> On the surface it looks like an easy enhancement, but what do I know? +> I suppose it would benefit mostly those programs that use a lot of +> PQexecParams() with simple queries where a greater percentage of the +> time is spent parsing the SQL rather than building the execute plan. +> What do you think? +> +> ---------------------------(end of broadcast)--------------------------- +> TIP 7: don't forget to increase your free space map settings +> + + + + +_______________________________ +Do you Yahoo!? +Declare Yourself - Register online to vote today! +http://vote.yahoo.com + +From pgsql-performance-owner@postgresql.org Thu Sep 23 16:39:42 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 645FE329E4C + for ; + Thu, 23 Sep 2004 16:39:40 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 66043-09 + for ; + Thu, 23 Sep 2004 15:39:38 +0000 (GMT) +Received: from web41110.mail.yahoo.com (web41110.mail.yahoo.com + [66.218.93.26]) + by svr1.postgresql.org (Postfix) with SMTP id 128A8329E01 + for ; + Thu, 23 Sep 2004 16:39:36 +0100 (BST) +Message-ID: <20040923153931.34861.qmail@web41110.mail.yahoo.com> +Received: from [61.25.53.100] by web41110.mail.yahoo.com via HTTP; + Thu, 23 Sep 2004 08:39:31 PDT +Date: Thu, 23 Sep 2004 08:39:31 -0700 (PDT) +From: Mr Pink +Subject: Re: SAN performance +To: Anjan Dave , pgsql-performance@postgresql.org +In-Reply-To: + <4BAFBB6B9CC46F41B2AD7D9F4BBAF785018B4049@vt-pe2550-001.vantage.vantage.com> +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/239 +X-Sequence-Number: 8367 + +Hi, + +I expect you mean RAID 1/0 or 1+0 since the CX300 didn't support RAID 10 last time I looked. + +Whether you are using a SAN or not, you should consider putting the WAL files (pg_xlog folder) on +seperate diskes from the DB. Since the log files are mostly written to, not read from you could +just use RAID 1. + +It's a pity pg doesn't have a way to use a cluster of servers to get the most out of your +expensive SAN. + +I read a comment earlier about setting block sizes to 8k to math pg's block size. Seems to make +sense, you should check it out. + +Have fun, +Mr Pink + +--- Anjan Dave wrote: + +> Hello, +> +> +> +> I'll be moving a DB from internal RAID-10 SCSI storage to an EMC CX300 +> FC RAID-10 LUN, bound to the host. I've setup a test host machine and a +> test LUN. The /var/lib/pgsql/data folder is sym-linked to a partition on +> the LUN. +> +> +> +> Other than the shared_buffers, effective cache size, and sort memory, I +> am not sure if I need to change any other parameters in the +> postgresql.conf file for getting maximum performance from the EMC box. +> +> +> +> Is there a general guideline for setting up postgres database and the +> tunable parameters on a SAN, especially for EMC? +> +> +> +> Appreciate any help, +> +> +> +> Thanks, +> Anjan +> +> + + + + + +__________________________________ +Do you Yahoo!? +New and Improved Yahoo! Mail - 100MB free storage! +http://promotions.yahoo.com/new_mail + +From pgsql-performance-owner@postgresql.org Thu Sep 23 17:45:34 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 20826329CFD; + Thu, 23 Sep 2004 17:45:31 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 91106-09; Thu, 23 Sep 2004 16:45:23 +0000 (GMT) +Received: from fdd00lnhub.fds.com (external.fds.com [208.15.90.2]) + by svr1.postgresql.org (Postfix) with ESMTP id B9C18329CB0; + Thu, 23 Sep 2004 17:45:21 +0100 (BST) +In-Reply-To: <200409211049.02018.josh@agliodbs.com> +To: "Josh Berkus +Cc: "Patrick Hatcher" , pgsql-performance@postgresql.org, + pgsql-performance-owner@postgresql.org, + "Robert Treat" +Subject: Re: vacuum full & max_fsm_pages question +MIME-Version: 1.0 +X-Mailer: Lotus Notes Release 6.5 September 18, 2003 +Message-ID: + +From: Patrick Hatcher +Date: Thu, 23 Sep 2004 09:32:50 -0700 +X-MIMETrack: Serialize by Router on FDD00LNHUB/FSG/SVR/FDD(Release 6.5.2|June + 01, 2004) at 09/23/2004 12:44:54 PM, + Serialize complete at 09/23/2004 12:44:54 PM +Content-Type: multipart/alternative; + boundary="=_alternative 005C0EB888256F18_=" +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=2.9 tagged_above=0.0 required=5.0 tests=HTML_20_30, + HTML_MESSAGE, TO_HAS_SPACES +X-Spam-Level: ** +X-Archive-Number: 200409/240 +X-Sequence-Number: 8368 + +This is a multipart message in MIME format. +--=_alternative 005C0EB888256F18_= +Content-Type: text/plain; charset="US-ASCII" + +I upgraded to 7.4.3 this morning and did a vacuum full analyze on the +problem table and now the indexes show the correct number of records + + +Patrick Hatcher +Macys.Com + + + + +Josh Berkus +Sent by: pgsql-performance-owner@postgresql.org +09/21/04 10:49 AM + +To +"Patrick Hatcher" +cc +"Robert Treat" , + +Subject +Re: [PERFORM] vacuum full & max_fsm_pages question + + + + + + +Patrick, + +> Sorry. I wrote PG 7.4.2 and then I erased it to write something else +and +> then forgot to add it back. + +Odd. You shouldn't be having to re-vacuum on 7.4. + +> And thanks for the Page info. I was getting frustrated and looked in +the +> wrong place. +> +> So it's probably best to drop and readd the indexes then? + +Well, I have to wonder if you've not run afoul of the known 7.4.2 bug +regarding indexes. This system hasn't had an improper database shutdown +or +power-out in the last few weeks, has it? + +-- +Josh Berkus +Aglio Database Solutions +San Francisco + +---------------------------(end of broadcast)--------------------------- +TIP 9: the planner will ignore your desire to choose an index scan if your + joining column's datatypes do not match + + +--=_alternative 005C0EB888256F18_= +Content-Type: text/html; charset="US-ASCII" + + +
I upgraded to 7.4.3 this morning and +did a vacuum full analyze on the problem table and now the indexes show +the correct number of records +
+
+Patrick Hatcher
+Macys.Com
+
+
+
+
+ + +
Josh Berkus <josh@agliodbs.com> + +
Sent by: pgsql-performance-owner@postgresql.org +

09/21/04 10:49 AM +

+ + + + +
+
To
+
"Patrick Hatcher" +<pathat@comcast.net> +
+
cc
+
"Robert Treat" +<xzilla@users.sourceforge.net>, <pgsql-performance@postgresql.org> +
+
Subject
+
Re: [PERFORM] vacuum full +& max_fsm_pages question
+
+ + +
+
+
+
+
+
Patrick,
+
+> Sorry.  I wrote PG 7.4.2 and then I erased it to write something +else and
+> then forgot to add it back.
+
+Odd.  You shouldn't be having to re-vacuum on 7.4.
+
+> And thanks for the Page info.  I was getting frustrated and looked +in the
+> wrong place.
+>
+> So it's probably best to drop and readd the indexes then?
+
+Well, I have to wonder if you've not run afoul of the known 7.4.2 bug
+regarding indexes.   This system hasn't had an improper database shutdown +or
+power-out in the last few weeks, has it?
+
+--
+Josh Berkus
+Aglio Database Solutions
+San Francisco
+
+---------------------------(end of broadcast)---------------------------
+TIP 9: the planner will ignore your desire to choose an index scan if your
+      joining column's datatypes do not match
+
+
+--=_alternative 005C0EB888256F18_=-- + +From pgsql-performance-owner@postgresql.org Thu Sep 23 17:53:55 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 54AC6329E45 + for ; + Thu, 23 Sep 2004 17:53:53 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 96369-04 + for ; + Thu, 23 Sep 2004 16:53:45 +0000 (GMT) +Received: from ms-smtp-02.nyroc.rr.com (ms-smtp-02.nyroc.rr.com [24.24.2.56]) + by svr1.postgresql.org (Postfix) with ESMTP id EFE05329E62 + for ; + Thu, 23 Sep 2004 17:53:44 +0100 (BST) +Received: from vaio (roc-66-66-153-192.rochester.rr.com [66.66.153.192]) + by ms-smtp-02.nyroc.rr.com (8.12.10/8.12.10) with ESMTP id + i8NGrUaX017580; Thu, 23 Sep 2004 12:53:31 -0400 (EDT) +Message-Id: <200409231653.i8NGrUaX017580@ms-smtp-02.nyroc.rr.com> +From: "Jason Coene" +To: "'Mr Pink'" , + "'Scott Kirkwood'" +Cc: +Subject: Re: Caching of Queries +Date: Thu, 23 Sep 2004 12:53:25 -0400 +MIME-Version: 1.0 +Content-Type: text/plain; + charset="US-ASCII" +Content-Transfer-Encoding: 7bit +X-Mailer: Microsoft Office Outlook, Build 11.0.5510 +In-reply-to: <20040923152925.18234.qmail@web41114.mail.yahoo.com> +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 +Thread-Index: AcShglXErjddGsQ4QjebVPA8XO1LFQACZEUg +X-Virus-Scanned: Symantec AntiVirus Scan Engine +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/241 +X-Sequence-Number: 8369 + +I'm not an expert, but I've been hunting down a killer performance problem +for a while now. It seems this may be the cause. + +At peak load, our database slows to a trickle. The CPU and disk utilization +are normal - 20-30% used CPU and disk performance good. + +All of our "postgres" processes end up in the "semwai" state - seemingly +waiting on other queries to complete. If the system isn't taxed in CPU or +disk, I have a good feeling that this may be the cause. I didn't know that +planning queries could create such a gridlock, but based on Mr Pink's +explanation, it sounds like a very real possibility. + +We're running on SELECT's, and the number of locks on our "high traffic" +tables grows to the hundreds. If it's not the SELECT locking (and we don't +get that many INSERT/UPDATE on these tables), could the planner be doing it? + +At peak load (~ 1000 queries/sec on highest traffic table, all very +similar), the serialized queries pile up and essentially create a DoS on our +service - requiring a restart of the PG daemon. Upon stop & start, it's +back to normal. + +I've looked at PREPARE, but apparently it only lasts per-session - that's +worthless in our case (web based service, one connection per data-requiring +connection). + +Does this sound plausible? Is there an alternative way to do this that I +don't know about? Additionally, in our case, I personally don't see any +downside to caching and using the same query plan when the only thing +substituted are variables. In fact, I'd imagine it would help performance +significantly in high-volume web applications. + +Thanks, + +Jason + +> -----Original Message----- +> From: pgsql-performance-owner@postgresql.org [mailto:pgsql-performance- +> owner@postgresql.org] On Behalf Of Mr Pink +> Sent: Thursday, September 23, 2004 11:29 AM +> To: Scott Kirkwood; pgsql-performance@postgresql.org +> Subject: Re: [PERFORM] Caching of Queries +> +> Not knowing anything about the internals of pg, I don't know how this +> relates, but in theory, +> query plan caching is not just about saving time re-planning queries, it's +> about scalability. +> Optimizing queries requires shared locks on the database metadata, which, +> as I understand it +> causes contention and serialization, which kills scalability. +> +> I read this thread from last to first, and I'm not sure if I missed +> something, but if pg isnt +> caching plans, then I would say plan caching should be a top priority for +> future enhancements. It +> needn't be complex either: if the SQL string is the same, and none of the +> tables involved in the +> query have changed (in structure), then re-use the cached plan. Basically, +> DDL and updated +> statistics would have to invalidate plans for affected tables. +> +> Preferably, it should work equally for prepared statements and those not +> pre-prepared. If you're +> not using prepare (and bind variables) though, your plan caching down the +> drain anyway... +> +> I don't think that re-optimizing based on values of bind variables is +> needed. It seems like it +> could actually be counter-productive and difficult to asses it's impact. +> +> That's the way I see it anyway. +> +> :) +> + + +From pgsql-performance-owner@postgresql.org Thu Sep 23 18:06:04 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 05B88329E44 + for ; + Thu, 23 Sep 2004 18:05:57 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 99526-06 + for ; + Thu, 23 Sep 2004 17:05:39 +0000 (GMT) +Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) + by svr1.postgresql.org (Postfix) with ESMTP id B546B329CB0 + for ; + Thu, 23 Sep 2004 18:05:39 +0100 (BST) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id i8NH5W8S027438; + Thu, 23 Sep 2004 13:05:32 -0400 (EDT) +To: "Jason Coene" +Cc: "'Mr Pink'" , + "'Scott Kirkwood'" , + pgsql-performance@postgresql.org +Subject: Re: Caching of Queries +In-reply-to: <200409231653.i8NGrUaX017580@ms-smtp-02.nyroc.rr.com> +References: <200409231653.i8NGrUaX017580@ms-smtp-02.nyroc.rr.com> +Comments: In-reply-to "Jason Coene" + message dated "Thu, 23 Sep 2004 12:53:25 -0400" +Date: Thu, 23 Sep 2004 13:05:32 -0400 +Message-ID: <27437.1095959132@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/242 +X-Sequence-Number: 8370 + +"Jason Coene" writes: +> All of our "postgres" processes end up in the "semwai" state - seemingly +> waiting on other queries to complete. If the system isn't taxed in CPU or +> disk, I have a good feeling that this may be the cause. + +Whatever that is, I'll bet lunch that it's got 0 to do with caching +query plans. Can you get stack tracebacks from some of the stuck +processes? What do they show in "ps"? + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Thu Sep 23 18:15:07 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 75231329CF7 + for ; + Thu, 23 Sep 2004 18:15:05 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 04612-04 + for ; + Thu, 23 Sep 2004 17:14:46 +0000 (GMT) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by svr1.postgresql.org (Postfix) with ESMTP id 65616329CAE + for ; + Thu, 23 Sep 2004 18:14:46 +0100 (BST) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by news.hub.org (8.12.9/8.12.9) with ESMTP id i8NHEjfg006035 + for ; Thu, 23 Sep 2004 17:14:45 GMT + (envelope-from news@news.hub.org) +Received: (from news@localhost) + by news.hub.org (8.12.9/8.12.9/Submit) id i8NHCMCY005137 + for pgsql-performance@postgresql.org; Thu, 23 Sep 2004 17:12:22 GMT +From: Gaetano Mendola +X-Newsgroups: comp.databases.postgresql.performance +Subject: Re: Caching of Queries +Date: Thu, 23 Sep 2004 19:12:16 +0200 +Organization: PYRENET Midi-pyrenees Provider +Lines: 41 +Message-ID: <415303F0.3050409@bigfoot.com> +References: <20040923152925.18234.qmail@web41114.mail.yahoo.com> + <200409231653.i8NGrUaX017580@ms-smtp-02.nyroc.rr.com> +Mime-Version: 1.0 +Content-Type: text/plain; charset=ISO-8859-1; format=flowed +Content-Transfer-Encoding: 7bit +X-Complaints-To: abuse@pyrenet.fr +To: Jason Coene +User-Agent: Mozilla Thunderbird 0.8 (Windows/20040913) +X-Accept-Language: en-us, en +In-Reply-To: <200409231653.i8NGrUaX017580@ms-smtp-02.nyroc.rr.com> +X-Enigmail-Version: 0.86.1.0 +X-Enigmail-Supports: pgp-inline, pgp-mime +To: pgsql-performance@postgresql.org +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/243 +X-Sequence-Number: 8371 + +Jason Coene wrote: +> I'm not an expert, but I've been hunting down a killer performance problem +> for a while now. It seems this may be the cause. +> +> At peak load, our database slows to a trickle. The CPU and disk utilization +> are normal - 20-30% used CPU and disk performance good. + +For a peak load 20-30% used CPU this mean you reached your IO bottleneck. + +> All of our "postgres" processes end up in the "semwai" state - seemingly +> waiting on other queries to complete. If the system isn't taxed in CPU or +> disk, I have a good feeling that this may be the cause. I didn't know that +> planning queries could create such a gridlock, but based on Mr Pink's +> explanation, it sounds like a very real possibility. +> +> We're running on SELECT's, and the number of locks on our "high traffic" +> tables grows to the hundreds. If it's not the SELECT locking (and we don't +> get that many INSERT/UPDATE on these tables), could the planner be doing it? +> +> At peak load (~ 1000 queries/sec on highest traffic table, all very +> similar), the serialized queries pile up and essentially create a DoS on our +> service - requiring a restart of the PG daemon. Upon stop & start, it's +> back to normal. + +Give us informations on this queries, a explain analyze could be a good start +point. + +> I've looked at PREPARE, but apparently it only lasts per-session - that's +> worthless in our case (web based service, one connection per data-requiring +> connection). + +Trust me the PREPARE is not doing miracle in shenarios like yours . If you use postgres +in a web service environment what you can use is a connection pool ( look for pgpoll IIRC ), +if you use a CMS then try to enable the cache in order to avoid to hit the DB for each +request. + + + + +Regards +Gaetano Mendola + +From pgsql-performance-owner@postgresql.org Thu Sep 23 18:18:43 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id A2459329CA4 + for ; + Thu, 23 Sep 2004 18:18:40 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 04565-08 + for ; + Thu, 23 Sep 2004 17:18:37 +0000 (GMT) +Received: from corpmsx.gaiam.com (corp.gaiam.com [12.147.81.200]) + by svr1.postgresql.org (Postfix) with ESMTP id EAAC4329CB7 + for ; + Thu, 23 Sep 2004 18:18:36 +0100 (BST) +X-MimeOLE: Produced By Microsoft Exchange V6.5.6944.0 +Content-class: urn:content-classes:message +MIME-Version: 1.0 +Content-Type: text/plain; + charset="us-ascii" +Content-Transfer-Encoding: quoted-printable +Subject: Re: Caching of Queries +Date: Thu, 23 Sep 2004 11:18:14 -0600 +Message-ID: <8D36D5916571CB4489C2E4D0CAD6E8930486500B@corpmsx.gaiam.com> +X-MS-Has-Attach: +X-MS-TNEF-Correlator: +Thread-Topic: [PERFORM] Caching of Queries +Thread-Index: AcShglXErjddGsQ4QjebVPA8XO1LFQACZEUgAAEQ0kA= +From: +To: +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.3 tagged_above=0.0 required=5.0 tests=NO_REAL_NAME +X-Spam-Level: +X-Archive-Number: 200409/244 +X-Sequence-Number: 8372 + +Scott:=20 + +We have seen similar issues when we have had massive load on our web +server. My determination was that simply the act of spawning and +stopping postgres sessions was very heavy on the box, and by +implementing connection pooling (sqlrelay), we got much higher +throughput, and better response on the server then we would get any +other way.=20 + +-----Original Message----- +From: pgsql-performance-owner@postgresql.org +[mailto:pgsql-performance-owner@postgresql.org] On Behalf Of Jason Coene +Sent: Thursday, September 23, 2004 10:53 AM +To: 'Mr Pink'; 'Scott Kirkwood' +Cc: pgsql-performance@postgresql.org +Subject: Re: [PERFORM] Caching of Queries + +I'm not an expert, but I've been hunting down a killer performance +problem +for a while now. It seems this may be the cause. + +At peak load, our database slows to a trickle. The CPU and disk +utilization +are normal - 20-30% used CPU and disk performance good. + +All of our "postgres" processes end up in the "semwai" state - seemingly +waiting on other queries to complete. If the system isn't taxed in CPU +or +disk, I have a good feeling that this may be the cause. I didn't know +that +planning queries could create such a gridlock, but based on Mr Pink's +explanation, it sounds like a very real possibility. + +We're running on SELECT's, and the number of locks on our "high traffic" +tables grows to the hundreds. If it's not the SELECT locking (and we +don't +get that many INSERT/UPDATE on these tables), could the planner be doing +it? + +At peak load (~ 1000 queries/sec on highest traffic table, all very +similar), the serialized queries pile up and essentially create a DoS on +our +service - requiring a restart of the PG daemon. Upon stop & start, it's +back to normal. + +I've looked at PREPARE, but apparently it only lasts per-session - +that's +worthless in our case (web based service, one connection per +data-requiring +connection). + +Does this sound plausible? Is there an alternative way to do this that +I +don't know about? Additionally, in our case, I personally don't see any +downside to caching and using the same query plan when the only thing +substituted are variables. In fact, I'd imagine it would help +performance +significantly in high-volume web applications. + +Thanks, + +Jason + +> -----Original Message----- +> From: pgsql-performance-owner@postgresql.org +[mailto:pgsql-performance- +> owner@postgresql.org] On Behalf Of Mr Pink +> Sent: Thursday, September 23, 2004 11:29 AM +> To: Scott Kirkwood; pgsql-performance@postgresql.org +> Subject: Re: [PERFORM] Caching of Queries +>=20 +> Not knowing anything about the internals of pg, I don't know how this +> relates, but in theory, +> query plan caching is not just about saving time re-planning queries, +it's +> about scalability. +> Optimizing queries requires shared locks on the database metadata, +which, +> as I understand it +> causes contention and serialization, which kills scalability. +>=20 +> I read this thread from last to first, and I'm not sure if I missed +> something, but if pg isnt +> caching plans, then I would say plan caching should be a top priority +for +> future enhancements. It +> needn't be complex either: if the SQL string is the same, and none of +the +> tables involved in the +> query have changed (in structure), then re-use the cached plan. +Basically, +> DDL and updated +> statistics would have to invalidate plans for affected tables. +>=20 +> Preferably, it should work equally for prepared statements and those +not +> pre-prepared. If you're +> not using prepare (and bind variables) though, your plan caching down +the +> drain anyway... +>=20 +> I don't think that re-optimizing based on values of bind variables is +> needed. It seems like it +> could actually be counter-productive and difficult to asses it's +impact. +>=20 +> That's the way I see it anyway. +>=20 +> :) +>=20 + + +---------------------------(end of broadcast)--------------------------- +TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org + +From pgsql-performance-owner@postgresql.org Thu Sep 23 18:23:06 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 7EE25329C89 + for ; + Thu, 23 Sep 2004 18:23:04 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 08053-04 + for ; + Thu, 23 Sep 2004 17:22:44 +0000 (GMT) +Received: from ms-smtp-02.nyroc.rr.com (ms-smtp-02.nyroc.rr.com [24.24.2.56]) + by svr1.postgresql.org (Postfix) with ESMTP id F2DCC329C63 + for ; + Thu, 23 Sep 2004 18:22:43 +0100 (BST) +Received: from vaio (roc-66-66-153-192.rochester.rr.com [66.66.153.192]) + by ms-smtp-02.nyroc.rr.com (8.12.10/8.12.10) with ESMTP id + i8NHMZaX014707; Thu, 23 Sep 2004 13:22:36 -0400 (EDT) +Message-Id: <200409231722.i8NHMZaX014707@ms-smtp-02.nyroc.rr.com> +From: "Jason Coene" +To: "'Tom Lane'" +Cc: "'Mr Pink'" , + "'Scott Kirkwood'" , + +Subject: Re: Caching of Queries +Date: Thu, 23 Sep 2004 13:22:30 -0400 +MIME-Version: 1.0 +Content-Type: text/plain; + charset="US-ASCII" +Content-Transfer-Encoding: 7bit +X-Mailer: Microsoft Office Outlook, Build 11.0.5510 +In-reply-to: <27437.1095959132@sss.pgh.pa.us> +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 +Thread-Index: AcShj4qLbo55O8Z/TNGioECdKf2v1wAANwkg +X-Virus-Scanned: Symantec AntiVirus Scan Engine +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/245 +X-Sequence-Number: 8373 + +Hi Tom, + +Easily recreated with Apache benchmark, "ab -n 30000 -c 3000 +http://webserver ". This runs 1 query per page, everything else is cached +on webserver. + +The lone query: + +SELECT + id, + gameid, + forumid, + subject + FROM threads + WHERE nuked = 0 + ORDER BY nuked DESC, + lastpost DESC LIMIT 8 + +Limit (cost=0.00..1.99 rows=8 width=39) (actual time=27.865..28.027 rows=8 +loops=1) + -> Index Scan Backward using threads_ix_nuked_lastpost on threads +(cost=0.0 0..16824.36 rows=67511 width=39) (actual time=27.856..27.989 +rows=8 loops=1) + Filter: (nuked = 0) + Total runtime: 28.175 ms + +I'm not sure how I go about getting the stack traceback you need. Any info +on this? Results of "ps" below. System is dual xeon 2.6, 2gb ram, hardware +raid 10 running FreeBSD 5.2.1. + +Jason + +last pid: 96094; load averages: 0.22, 0.35, 0.38 +up 19+20:50:37 13:10:45 +161 processes: 2 running, 151 sleeping, 8 lock +CPU states: 12.2% user, 0.0% nice, 16.9% system, 1.6% interrupt, 69.4% +idle +Mem: 120M Active, 1544M Inact, 194M Wired, 62M Cache, 112M Buf, 2996K Free +Swap: 4096M Total, 4096M Free + + PID USERNAME PRI NICE SIZE RES STATE C TIME WCPU CPU COMMAND +50557 pgsql 98 0 95276K 4860K select 0 24:00 0.59% 0.59% postgres +95969 pgsql 4 0 96048K 34272K sbwait 0 0:00 2.10% 0.29% postgres +95977 pgsql -4 0 96048K 29620K semwai 2 0:00 1.40% 0.20% postgres +96017 pgsql 4 0 96048K 34280K sbwait 0 0:00 2.05% 0.20% postgres +95976 pgsql -4 0 96048K 30564K semwai 3 0:00 1.05% 0.15% postgres +95970 pgsql -4 0 96048K 24404K semwai 1 0:00 1.05% 0.15% postgres +95972 pgsql -4 0 96048K 21060K semwai 1 0:00 1.05% 0.15% postgres +96053 pgsql -4 0 96048K 24140K semwai 3 0:00 1.54% 0.15% postgres +96024 pgsql -4 0 96048K 22192K semwai 3 0:00 1.54% 0.15% postgres +95985 pgsql -4 0 96048K 15208K semwai 3 0:00 1.54% 0.15% postgres +96033 pgsql 98 0 95992K 7812K *Giant 2 0:00 1.54% 0.15% postgres +95973 pgsql -4 0 96048K 30936K semwai 3 0:00 0.70% 0.10% postgres +95966 pgsql 4 0 96048K 34272K sbwait 0 0:00 0.70% 0.10% postgres +95983 pgsql 4 0 96048K 34272K sbwait 2 0:00 1.03% 0.10% postgres +95962 pgsql 4 0 96048K 34268K sbwait 2 0:00 0.70% 0.10% postgres +95968 pgsql -4 0 96048K 26232K semwai 2 0:00 0.70% 0.10% postgres +95959 pgsql 4 0 96048K 34268K sbwait 2 0:00 0.70% 0.10% postgres + +> -----Original Message----- +> From: Tom Lane [mailto:tgl@sss.pgh.pa.us] +> Sent: Thursday, September 23, 2004 1:06 PM +> To: Jason Coene +> Cc: 'Mr Pink'; 'Scott Kirkwood'; pgsql-performance@postgresql.org +> Subject: Re: [PERFORM] Caching of Queries +> +> "Jason Coene" writes: +> > All of our "postgres" processes end up in the "semwai" state - seemingly +> > waiting on other queries to complete. If the system isn't taxed in CPU +> or +> > disk, I have a good feeling that this may be the cause. +> +> Whatever that is, I'll bet lunch that it's got 0 to do with caching +> query plans. Can you get stack tracebacks from some of the stuck +> processes? What do they show in "ps"? +> +> regards, tom lane + + +From pgsql-performance-owner@postgresql.org Thu Sep 23 18:25:37 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id B546E329CB0 + for ; + Thu, 23 Sep 2004 18:25:33 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 07638-07 + for ; + Thu, 23 Sep 2004 17:25:30 +0000 (GMT) +Received: from stark.xeocode.com (gsstark.mtl.istop.com [66.11.160.162]) + by svr1.postgresql.org (Postfix) with ESMTP id 80BA2329C82 + for ; + Thu, 23 Sep 2004 18:25:29 +0100 (BST) +Received: from localhost ([127.0.0.1] helo=stark.xeocode.com) + by stark.xeocode.com with smtp (Exim 3.36 #1 (Debian)) + id 1CAXLR-00008l-00; Thu, 23 Sep 2004 13:25:25 -0400 +To: "Jason Coene" +Cc: "'Mr Pink'" , + "'Scott Kirkwood'" , + +Subject: Re: Caching of Queries +References: <200409231653.i8NGrUaX017580@ms-smtp-02.nyroc.rr.com> +In-Reply-To: <200409231653.i8NGrUaX017580@ms-smtp-02.nyroc.rr.com> +From: Greg Stark +Organization: The Emacs Conspiracy; member since 1992 +Date: 23 Sep 2004 13:25:25 -0400 +Message-ID: <87d60cc2yi.fsf@stark.xeocode.com> +Lines: 46 +User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/246 +X-Sequence-Number: 8374 + + +"Jason Coene" writes: + +> All of our "postgres" processes end up in the "semwai" state - seemingly +> waiting on other queries to complete. If the system isn't taxed in CPU or +> disk, I have a good feeling that this may be the cause. + +Well, it's possible contention of some sort is an issue but it's not clear +that it's planning related contention. + +> We're running on SELECT's, and the number of locks on our "high traffic" +> tables grows to the hundreds. + +Where are you seeing this? What information do you have about these locks? + +> I've looked at PREPARE, but apparently it only lasts per-session - that's +> worthless in our case (web based service, one connection per data-requiring +> connection). + +Well the connection time in postgres is pretty quick. But a lot of other +things, including prepared queries but also including other factors are a lot +more effective if you have long-lived sessions. + +I would strongly recommend you consider some sort of persistent database +connection for your application. Most web based services run queries from a +single source base where all the queries are written in-house. In that +situation you can ensure that one request never leaves the session in an +unusual state (like setting guc variables strangely, or leaving a transaction +open, or whatever). + +That saves you the reconnect time, which as I said is actually small, but +could still be contributing to your problem. I think it also makes the buffer +cache more effective as well. And It also means you can prepare all your +queries and reuse them on subsequent requests. + +The nice thing about web based services is that while each page only executes +each query once, you tend to get the same pages over and over thousands of +times. So if they prepare their queries the first time around they can reuse +those prepared queries thousands of times. + +Using a text cache of the query string on the server side is just a +work-around for failing to do that on the client side. It's much more +efficient and more flexible to do it on the client-side. + +-- +greg + + +From pgsql-performance-owner@postgresql.org Thu Sep 23 18:35:54 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 10444329CD9 + for ; + Thu, 23 Sep 2004 18:35:53 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 10446-05 + for ; + Thu, 23 Sep 2004 17:35:50 +0000 (GMT) +Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) + by svr1.postgresql.org (Postfix) with ESMTP id A1701329CB0 + for ; + Thu, 23 Sep 2004 18:35:49 +0100 (BST) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id i8NHZl15027751; + Thu, 23 Sep 2004 13:35:47 -0400 (EDT) +To: "Jason Coene" +Cc: "'Mr Pink'" , + "'Scott Kirkwood'" , + pgsql-performance@postgresql.org +Subject: Re: Caching of Queries +In-reply-to: <200409231722.i8NHMZaX014707@ms-smtp-02.nyroc.rr.com> +References: <200409231722.i8NHMZaX014707@ms-smtp-02.nyroc.rr.com> +Comments: In-reply-to "Jason Coene" + message dated "Thu, 23 Sep 2004 13:22:30 -0400" +Date: Thu, 23 Sep 2004 13:35:47 -0400 +Message-ID: <27750.1095960947@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/247 +X-Sequence-Number: 8375 + +"Jason Coene" writes: +> I'm not sure how I go about getting the stack traceback you need. Any info +> on this? Results of "ps" below. System is dual xeon 2.6, 2gb ram, hardware +> raid 10 running FreeBSD 5.2.1. + +Hmm. Dual Xeon sets off alarm bells ... + +I think you are probably looking at the same problem previously reported +by Josh Berkus among others. Does the rate of context swaps shown by +vmstat go through the roof when this happens? If you strace or ktrace +one of the backends, do you see lots of semop()s and little else? + +Check the archives for this thread among others: +http://archives.postgresql.org/pgsql-performance/2004-04/msg00249.php +The test case you are talking about is a tight indexscan loop, which +is pretty much the same scenario as here: +http://archives.postgresql.org/pgsql-performance/2004-04/msg00280.php + +The fundamental problem is heavy contention for access to a shared data +structure. We're still looking for good solutions, but in the context +of this thread it's worth pointing out that a shared query-plan cache +would itself be subject to heavy contention, and arguably would make +this sort of problem worse not better. + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Thu Sep 23 18:38:58 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 70158329C82 + for ; + Thu, 23 Sep 2004 18:38:54 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 10666-08 + for ; + Thu, 23 Sep 2004 17:38:35 +0000 (GMT) +Received: from bayswater1.ymogen.net (host-154-240-27-217.pobox.net.uk + [217.27.240.154]) + by svr1.postgresql.org (Postfix) with ESMTP id D09BF329C70 + for ; + Thu, 23 Sep 2004 18:38:34 +0100 (BST) +Received: from solent (unknown [213.165.136.10]) + by bayswater1.ymogen.net (Postfix) with ESMTP + id 58CACA2F6E; Thu, 23 Sep 2004 18:38:32 +0100 (BST) +Reply-To: +From: "Matt Clark" +To: "'Jason Coene'" , + "'Mr Pink'" , + "'Scott Kirkwood'" +Cc: +Subject: Re: Caching of Queries +Date: Thu, 23 Sep 2004 18:38:32 +0100 +Organization: Ymogen Ltd +Message-ID: <002001c4a194$25481810$8300a8c0@solent> +MIME-Version: 1.0 +Content-Type: text/plain; + charset="us-ascii" +Content-Transfer-Encoding: 7bit +X-Priority: 3 (Normal) +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook, Build 10.0.6626 +In-Reply-To: <200409231653.i8NGrUaX017580@ms-smtp-02.nyroc.rr.com> +Importance: Normal +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/248 +X-Sequence-Number: 8376 + +> I've looked at PREPARE, but apparently it only lasts +> per-session - that's worthless in our case (web based +> service, one connection per data-requiring connection). + +That's a non-sequitur. Most 'normal' high volume web apps have persistent +DB connections, one per http server process. Are you really dropping DB +connections and reconnecting each time a new HTTP request comes in? + +M + + +From pgsql-performance-owner@postgresql.org Thu Sep 23 18:45:13 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id ACDEA329CB0 + for ; + Thu, 23 Sep 2004 18:45:06 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 14728-04 + for ; + Thu, 23 Sep 2004 17:44:47 +0000 (GMT) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by svr1.postgresql.org (Postfix) with ESMTP id A06FD329C83 + for ; + Thu, 23 Sep 2004 18:44:47 +0100 (BST) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by news.hub.org (8.12.9/8.12.9) with ESMTP id i8NHijfg016312 + for ; Thu, 23 Sep 2004 17:44:45 GMT + (envelope-from news@news.hub.org) +Received: (from news@localhost) + by news.hub.org (8.12.9/8.12.9/Submit) id i8NHec3g015018 + for pgsql-performance@postgresql.org; Thu, 23 Sep 2004 17:40:38 GMT +From: Gaetano Mendola +X-Newsgroups: comp.databases.postgresql.performance +Subject: Re: Caching of Queries +Date: Thu, 23 Sep 2004 19:40:32 +0200 +Organization: PYRENET Midi-pyrenees Provider +Lines: 20 +Message-ID: <41530A90.1030702@bigfoot.com> +References: <27437.1095959132@sss.pgh.pa.us> + <200409231722.i8NHMZaX014707@ms-smtp-02.nyroc.rr.com> +Mime-Version: 1.0 +Content-Type: text/plain; charset=ISO-8859-1; format=flowed +Content-Transfer-Encoding: 7bit +X-Complaints-To: abuse@pyrenet.fr +To: Jason Coene +User-Agent: Mozilla Thunderbird 0.8 (Windows/20040913) +X-Accept-Language: en-us, en +In-Reply-To: <200409231722.i8NHMZaX014707@ms-smtp-02.nyroc.rr.com> +X-Enigmail-Version: 0.86.1.0 +X-Enigmail-Supports: pgp-inline, pgp-mime +To: pgsql-performance@postgresql.org +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/249 +X-Sequence-Number: 8377 + +Jason Coene wrote: +> Hi Tom, +> +> Easily recreated with Apache benchmark, "ab -n 30000 -c 3000 +> http://webserver ". This runs 1 query per page, everything else is cached +> on webserver. + +That test require 30000 access with 3000 connections that is not a normal +load. Describe us your HW. + +3000 connections means a very huge load, may you provide also the result of +"vmstat 5" my webserver trash already with -c 120 ! + +how many connection your postgres can manage ? + +You have to consider to use a connection pool with that ammount of connections. + + +Regards +Gaetano Mendola + +From pgsql-performance-owner@postgresql.org Thu Sep 23 18:46:52 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 47C14329D7A + for ; + Thu, 23 Sep 2004 18:46:40 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 13589-05 + for ; + Thu, 23 Sep 2004 17:46:37 +0000 (GMT) +Received: from mail.logi-track.com (burro.logi-track.com [213.239.193.212]) + by svr1.postgresql.org (Postfix) with ESMTP id 8A3FE329D3E + for ; + Thu, 23 Sep 2004 18:46:34 +0100 (BST) +Received: from kingfisher.intern.logi-track.com (G6fc4.g.pppool.de + [80.185.111.196]) + by mail.logi-track.com (Postfix) with ESMTP id 83BC13021D; + Thu, 23 Sep 2004 19:46:36 +0200 (CEST) +Received: from kingfisher.intern.logi-track.com (localhost [127.0.0.1]) + by kingfisher.intern.logi-track.com (Postfix) with SMTP id A3742AB352; + Thu, 23 Sep 2004 19:46:28 +0200 (CEST) +Date: Thu, 23 Sep 2004 19:46:26 +0200 +From: Markus Schaber +To: "Jason Coene" +Cc: "'Mr Pink'" , + "'Scott Kirkwood'" , + +Subject: Re: Caching of Queries +Message-ID: <20040923194626.708b7bce@kingfisher.intern.logi-track.com> +In-Reply-To: <200409231653.i8NGrUaX017580@ms-smtp-02.nyroc.rr.com> +References: <20040923152925.18234.qmail@web41114.mail.yahoo.com> + <200409231653.i8NGrUaX017580@ms-smtp-02.nyroc.rr.com> +Organization: logi-track ag, =?ISO-8859-15?Q?z=FCrich?= +X-Mailer: Sylpheed-Claws 0.9.12a (GTK+ 1.2.10; i386-pc-linux-gnu) +X-Face: Nx5T&>Nj$VrVPv}sC3IL&)TqHHOKCz/|)R$i"*r@w0{*I6w; + UNU_hdl1J4NI_m{IMztq=>cmM}1gCLbAF+9\#CGkG8}Y{x%SuQ>1#t:; + Z(|\qdd[i]HStki~#w1$TPF}:0w-7"S\Ev|_a$K wrote: + +> I've looked at PREPARE, but apparently it only lasts per-session - that's +> worthless in our case (web based service, one connection per data-requiri= +ng +> connection). + +This sounds like the loads of connection init and close may be the +reason for the slowdown. Can you use connection pooling in your service? + +HTH, +Markus + + +--=20 +markus schaber | dipl. informatiker +logi-track ag | rennweg 14-16 | ch 8001 z=FCrich +phone +41-43-888 62 52 | fax +41-43-888 62 53 +mailto:schabios@logi-track.com | www.logi-track.com + +From pgsql-performance-owner@postgresql.org Thu Sep 23 19:05:17 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id AD5EC329CD9 + for ; + Thu, 23 Sep 2004 19:05:12 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 19502-07 + for ; + Thu, 23 Sep 2004 18:05:09 +0000 (GMT) +Received: from vt-pe2550-001.VANTAGE.vantage.com (unknown [64.80.203.242]) + by svr1.postgresql.org (Postfix) with ESMTP id 2522A329CB7 + for ; + Thu, 23 Sep 2004 19:05:06 +0100 (BST) +X-MimeOLE: Produced By Microsoft Exchange V6.0.6249.0 +content-class: urn:content-classes:message +MIME-Version: 1.0 +Content-Type: text/plain; + charset="utf-8" +Content-Transfer-Encoding: base64 +Subject: Re: SAN performance +Date: Thu, 23 Sep 2004 14:05:05 -0400 +Message-ID: + <4BAFBB6B9CC46F41B2AD7D9F4BBAF78509853D@vt-pe2550-001.vantage.vantage.com> +X-MS-Has-Attach: +X-MS-TNEF-Correlator: +Thread-Topic: [PERFORM] SAN performance +Thread-Index: AcShg4g9+7raW/GeR6Kdu0mZDX92ZQAE5GhV +From: "Anjan Dave" +To: "Mr Pink" , + +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/251 +X-Sequence-Number: 8379 + +SSBiZWxpZXZlIDEvMCBvciAxKzAgaXMgYWthIFJBSUQtMTAuIENYMzAwIGRv +ZXNuJ3Qgc3VwcG9ydCAwKzEuDQogDQpTbyBmYXIgaSBhbSBhd2FyZSBvZiB0 +d28gdGhpbmdzLCB0aGUgY2FjaGUgcGFnZSBzaXplIGlzIDhLQiAoY2FuIGJl +IGluY3JlYXNlZCBvciBkZWNyZWFzZWQpLCBhbmQgdGhlIHN0cmlwZSBlbGVt +ZW50IHNpemUgb2YgMTI4IHNlY3RvcnMgZGVmYXVsdC4NCiANClRoYW5rcywN +CkFuamFuDQoNCgktLS0tLU9yaWdpbmFsIE1lc3NhZ2UtLS0tLSANCglGcm9t +OiBNciBQaW5rIFttYWlsdG86bXJfcGlua19pc190aGVfb25seV9wcm9AeWFo +b28uY29tXSANCglTZW50OiBUaHUgOS8yMy8yMDA0IDExOjM5IEFNIA0KCVRv +OiBBbmphbiBEYXZlOyBwZ3NxbC1wZXJmb3JtYW5jZUBwb3N0Z3Jlc3FsLm9y +ZyANCglDYzogDQoJU3ViamVjdDogUmU6IFtQRVJGT1JNXSBTQU4gcGVyZm9y +bWFuY2UNCgkNCgkNCg0KCUhpLCANCg0KCUkgZXhwZWN0IHlvdSBtZWFuIFJB +SUQgMS8wIG9yIDErMCBzaW5jZSB0aGUgQ1gzMDAgZGlkbid0IHN1cHBvcnQg +UkFJRCAxMCBsYXN0IHRpbWUgSSBsb29rZWQuIA0KDQoJV2hldGhlciB5b3Ug +YXJlIHVzaW5nIGEgU0FOIG9yIG5vdCwgeW91IHNob3VsZCBjb25zaWRlciBw +dXR0aW5nIHRoZSBXQUwgZmlsZXMgKHBnX3hsb2cgZm9sZGVyKSBvbiANCglz +ZXBlcmF0ZSBkaXNrZXMgZnJvbSB0aGUgREIuIFNpbmNlIHRoZSBsb2cgZmls +ZXMgYXJlIG1vc3RseSB3cml0dGVuIHRvLCBub3QgcmVhZCBmcm9tIHlvdSBj +b3VsZCANCglqdXN0IHVzZSBSQUlEIDEuIA0KDQoJSXQncyBhIHBpdHkgcGcg +ZG9lc24ndCBoYXZlIGEgd2F5IHRvIHVzZSBhIGNsdXN0ZXIgb2Ygc2VydmVy +cyB0byBnZXQgdGhlIG1vc3Qgb3V0IG9mIHlvdXIgDQoJZXhwZW5zaXZlIFNB +Ti4gDQoNCglJIHJlYWQgYSBjb21tZW50IGVhcmxpZXIgYWJvdXQgc2V0dGlu +ZyBibG9jayBzaXplcyB0byA4ayB0byBtYXRoIHBnJ3MgYmxvY2sgc2l6ZS4g +U2VlbXMgdG8gbWFrZSANCglzZW5zZSwgeW91IHNob3VsZCBjaGVjayBpdCBv +dXQuIA0KDQoJSGF2ZSBmdW4sIA0KCU1yIFBpbmsgDQoNCgktLS0gQW5qYW4g +RGF2ZSA8YWRhdmVAdmFudGFnZS5jb20+IHdyb3RlOiANCg0KCT4gSGVsbG8s +IA0KCT4gDQoJPiAgDQoJPiANCgk+IEknbGwgYmUgbW92aW5nIGEgREIgZnJv +bSBpbnRlcm5hbCBSQUlELTEwIFNDU0kgc3RvcmFnZSB0byBhbiBFTUMgQ1gz +MDAgDQoJPiBGQyBSQUlELTEwIExVTiwgYm91bmQgdG8gdGhlIGhvc3QuIEkn +dmUgc2V0dXAgYSB0ZXN0IGhvc3QgbWFjaGluZSBhbmQgYSANCgk+IHRlc3Qg +TFVOLiBUaGUgL3Zhci9saWIvcGdzcWwvZGF0YSBmb2xkZXIgaXMgc3ltLWxp +bmtlZCB0byBhIHBhcnRpdGlvbiBvbiANCgk+IHRoZSBMVU4uIA0KCT4gDQoJ +PiAgDQoJPiANCgk+IE90aGVyIHRoYW4gdGhlIHNoYXJlZF9idWZmZXJzLCBl +ZmZlY3RpdmUgY2FjaGUgc2l6ZSwgYW5kIHNvcnQgbWVtb3J5LCBJIA0KCT4g +YW0gbm90IHN1cmUgaWYgSSBuZWVkIHRvIGNoYW5nZSBhbnkgb3RoZXIgcGFy +YW1ldGVycyBpbiB0aGUgDQoJPiBwb3N0Z3Jlc3FsLmNvbmYgZmlsZSBmb3Ig +Z2V0dGluZyBtYXhpbXVtIHBlcmZvcm1hbmNlIGZyb20gdGhlIEVNQyBib3gu +IA0KCT4gDQoJPiAgDQoJPiANCgk+IElzIHRoZXJlIGEgZ2VuZXJhbCBndWlk +ZWxpbmUgZm9yIHNldHRpbmcgdXAgcG9zdGdyZXMgZGF0YWJhc2UgYW5kIHRo +ZSANCgk+IHR1bmFibGUgcGFyYW1ldGVycyBvbiBhIFNBTiwgZXNwZWNpYWxs +eSBmb3IgRU1DPyANCgk+IA0KCT4gIA0KCT4gDQoJPiBBcHByZWNpYXRlIGFu +eSBoZWxwLCANCgk+IA0KCT4gIA0KCT4gDQoJPiBUaGFua3MsIA0KCT4gQW5q +YW4gDQoJPiANCgk+IA0KDQoNCg0KCSAgICAgICAgDQoJICAgICAgICAgICAg +ICAgIA0KCV9fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18gDQoJ +RG8geW91IFlhaG9vIT8gDQoJTmV3IGFuZCBJbXByb3ZlZCBZYWhvbyEgTWFp +bCAtIDEwME1CIGZyZWUgc3RvcmFnZSEgDQoJaHR0cDovL3Byb21vdGlvbnMu +eWFob28uY29tL25ld19tYWlsIA0KDQo= + +From pgsql-performance-owner@postgresql.org Thu Sep 23 19:57:56 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 7E6CE329D28 + for ; + Thu, 23 Sep 2004 19:57:52 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 37857-06 + for ; + Thu, 23 Sep 2004 18:57:40 +0000 (GMT) +Received: from davinci.ethosmedia.com (server226.ethosmedia.com + [209.128.84.226]) + by svr1.postgresql.org (Postfix) with ESMTP id 83A45329C83 + for ; + Thu, 23 Sep 2004 19:57:40 +0100 (BST) +Received: from [63.195.55.98] (account josh@agliodbs.com HELO spooky) + by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.1.8) + with ESMTP id 6398302; Thu, 23 Sep 2004 11:58:37 -0700 +From: Josh Berkus +Organization: Aglio Database Solutions +To: Tom Lane +Subject: Re: Caching of Queries +Date: Thu, 23 Sep 2004 11:56:31 -0700 +User-Agent: KMail/1.6.2 +Cc: "Jason Coene" , + "'Mr Pink'" , + "'Scott Kirkwood'" , + pgsql-performance@postgresql.org +References: <200409231722.i8NHMZaX014707@ms-smtp-02.nyroc.rr.com> + <27750.1095960947@sss.pgh.pa.us> +In-Reply-To: <27750.1095960947@sss.pgh.pa.us> +MIME-Version: 1.0 +Content-Disposition: inline +Content-Type: text/plain; + charset="utf-8" +Content-Transfer-Encoding: 7bit +Message-Id: <200409231156.31450.josh@agliodbs.com> +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/252 +X-Sequence-Number: 8380 + +Tom, + +> I think you are probably looking at the same problem previously reported +> by Josh Berkus among others. Does the rate of context swaps shown by +> vmstat go through the roof when this happens? If you strace or ktrace +> one of the backends, do you see lots of semop()s and little else? + +That would be interesting. Previously we've only demonstrated the problem on +long-running queries, but I suppose it could also affect massive concurrent +query access. + +-- +Josh Berkus +Aglio Database Solutions +San Francisco + +From pgsql-performance-owner@postgresql.org Thu Sep 23 20:02:21 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id A6AC6329C70 + for ; + Thu, 23 Sep 2004 20:02:05 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 40658-03 + for ; + Thu, 23 Sep 2004 19:02:02 +0000 (GMT) +Received: from mail.copelandconsulting.net + (dsl-24293-ld.customer.centurytel.net [209.142.135.135]) + by svr1.postgresql.org (Postfix) with ESMTP id BEEB0329D9D + for ; + Thu, 23 Sep 2004 20:01:58 +0100 (BST) +Received: from localhost (localhost [127.0.0.1]) + by mail.copelandconsulting.net (Postfix) with ESMTP + id E4F9EC000ED; Thu, 23 Sep 2004 14:01:57 -0500 (CDT) +Received: from mail.copelandconsulting.net ([127.0.0.1]) + by localhost (mouse.copelandconsulting.net [127.0.0.1]) (amavisd-new, + port 10024) + with ESMTP id 06851-03; Thu, 23 Sep 2004 14:01:57 -0500 (CDT) +Received: from [192.168.1.3] (shrew.copelandconsulting.net [192.168.1.3]) + by mail.copelandconsulting.net (Postfix) with ESMTP + id A070DC000E1; Thu, 23 Sep 2004 14:01:57 -0500 (CDT) +Subject: Re: Hyper threading? +From: Greg Copeland +To: Mariusz =?iso-8859-2?Q?Czu=B3ada?= +Cc: pgsql-performance@postgresql.org +In-Reply-To: <200409211054.48574.manieq@idea.net.pl> +References: <200409211054.48574.manieq@idea.net.pl> +Content-Type: text/plain; charset=utf-8 +Organization: Copeland Computer Consulting +Message-Id: <1095966117.3422.12.camel@shrew.copelandconsulting.net> +Mime-Version: 1.0 +X-Mailer: Ximian Evolution 1.4.6-2.1.92mdk +Date: Thu, 23 Sep 2004 14:01:57 -0500 +Content-Transfer-Encoding: 8bit +X-Virus-Scanned: by amavisd-new at copelandconsulting.net +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/253 +X-Sequence-Number: 8381 + +On Tue, 2004-09-21 at 03:54, Mariusz Czułada wrote: +> Hi all, +> +> I searched list archives, but did not found anything about HT of Pentium +> 4/Xeon processors. I wonder if hyperthreading can boost or decrease +> performance. AFAIK for other commercial servers (msssql, oracle) official +> documents state something like "faster, but not always, so probably slower, +> unless faster". User opinions are generaly more clear: better swhitch off HT. +> +> Do you have any experiance or test results regarding hyperthreading? Or what +> additional conditions can make HT useful or pointless? +> + +I think you'll find that HT is very sensitive to both the OS and the +application. Generally speaking, most consider HT to actually slow +things down, unless you can prove that your OS/application combination +is faster with HT enabled. Last I heard, most vendors specifically +disable HT in the BIOS because the defacto is to expect HT to inflict a +negative performance hit. + +IIRC, one of critical paths for good HT performance is an OS that +understands how to schedule processes in a HT friendly manner (as in, +doesn't push processes from a virtual CPU to a different physical CPU, +etc). Secondly, applications which experience a lot of bad branch +predictions tend to do well. I don't recall what impact SSE +instructions have on the pipeline; but memory seems to recall that +applications which use a lot of SSE may be more HT friendly. At any +rate, the notion is, if you are HT'ing, and one application/thread +requires the pipeline to be flushed, the other HT'ing thread is free to +run while the new branch is populating cache, etc. Thusly, you get a +performance gain for the other thread when the CPU makes a bad guess. + +Along these lines, I understand that Intel is planning better HT +implementation in the future, but as a general rule, people simply +expect too much from the current HT implementations. Accordingly, for +most applications, performance generally suffers because they don't tend +to fall into the corner cases where HT helps. + +Long story short, the general rule is, slower unless you having proven +it to be faster. + + +Cheers, + +-- +Greg Copeland, Owner +greg@copelandconsulting.net +Copeland Computer Consulting +940.206.8004 + + + +From pgsql-performance-owner@postgresql.org Thu Sep 23 20:08:02 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 40494329CE3 + for ; + Thu, 23 Sep 2004 20:07:55 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 41359-06 + for ; + Thu, 23 Sep 2004 19:07:44 +0000 (GMT) +Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) + by svr1.postgresql.org (Postfix) with ESMTP id 79E15329CDB + for ; + Thu, 23 Sep 2004 20:07:44 +0100 (BST) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id i8NJ6q2S028415; + Thu, 23 Sep 2004 15:06:52 -0400 (EDT) +To: Josh Berkus +Cc: "Jason Coene" , + "'Mr Pink'" , + "'Scott Kirkwood'" , + pgsql-performance@postgresql.org +Subject: Re: Caching of Queries +In-reply-to: <200409231156.31450.josh@agliodbs.com> +References: <200409231722.i8NHMZaX014707@ms-smtp-02.nyroc.rr.com> + <27750.1095960947@sss.pgh.pa.us> + <200409231156.31450.josh@agliodbs.com> +Comments: In-reply-to Josh Berkus + message dated "Thu, 23 Sep 2004 11:56:31 -0700" +Date: Thu, 23 Sep 2004 15:06:52 -0400 +Message-ID: <28414.1095966412@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/254 +X-Sequence-Number: 8382 + +Josh Berkus writes: +>> I think you are probably looking at the same problem previously reported +>> by Josh Berkus among others. + +> That would be interesting. Previously we've only demonstrated the +> problem on long-running queries, but I suppose it could also affect +> massive concurrent query access. + +Well, the test cases we used were designed to get the system into a +tight loop of grabbing and releasing shared buffers --- a long-running +index scan is certainly one of the best ways to do that, but there are +others. + +I hadn't focused before on the point that Jason is launching a new +connection for every query. In that scenario I think the bulk of the +cycles are going to go into loading the per-backend catalog caches with +the system catalog rows that are needed to parse and plan the query. +The catalog fetches to get those rows are effectively mini-queries +with preset indexscan plans, so it's not hard to believe that they'd be +hitting the BufMgrLock nearly as hard as a tight indexscan loop. Once +all the pages needed are cached in shared buffers, there's no I/O delays +to break the loop, and so you could indeed get into the context swap +storm regime we saw before. + +I concur with the thought that using persistent connections might go a +long way towards alleviating his problem. + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Thu Sep 23 20:08:27 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 46B28329D22 + for ; + Thu, 23 Sep 2004 20:08:14 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 42018-06 + for ; + Thu, 23 Sep 2004 19:08:06 +0000 (GMT) +Received: from ms-smtp-03.nyroc.rr.com (ms-smtp-03.nyroc.rr.com [24.24.2.57]) + by svr1.postgresql.org (Postfix) with ESMTP id 0B743329C83 + for ; + Thu, 23 Sep 2004 20:08:05 +0100 (BST) +Received: from jcoene2 (roc-66-66-153-192.rochester.rr.com [66.66.153.192]) + by ms-smtp-03.nyroc.rr.com (8.12.10/8.12.10) with ESMTP id + i8NJ7rv2004899; Thu, 23 Sep 2004 15:07:54 -0400 (EDT) +Message-Id: <200409231907.i8NJ7rv2004899@ms-smtp-03.nyroc.rr.com> +From: "Jason Coene" +To: +Cc: , , +Subject: Re: Caching of Queries +Date: Thu, 23 Sep 2004 15:07:55 -0400 +MIME-Version: 1.0 +Content-Type: multipart/mixed; + boundary="----=_NextPart_000_0012_01C4A17F.1BB1EB60" +X-Mailer: Microsoft Office Outlook, Build 11.0.5510 +In-Reply-To: <41530A90.1030702@bigfoot.com> +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 +Thread-Index: AcShlHfHCGA3N4JqSiiyHaMXraZADQAAqeFA +X-Virus-Scanned: Symantec AntiVirus Scan Engine +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/255 +X-Sequence-Number: 8383 + +This is a multi-part message in MIME format. + +------=_NextPart_000_0012_01C4A17F.1BB1EB60 +Content-Type: text/plain; + charset="us-ascii" +Content-Transfer-Encoding: 7bit + +Hi All, + +It does sound like we should be pooling connections somehow. I'll be +looking at implementing that shortly. I'd really like to understand what +the actual problem is, though. + +Sorry, I meant 30,000 with 300 connections - not 3,000. The 300 connections +/ second is realistic, if not underestimated. As is the nature of our site +(realtime information about online gaming), there's a huge fan base and as a +big upset happens, we'll do 50,000 page views in a span of 3-5 minutes. + +I get the same results with: + +ab -n 10000 -c 150 http://www.gotfrag.com/portal/news/ + +I've attached results from the above test, showing open locks, top output, +and vmstat 5. + +Tom, I've run the test described in: + +http://archives.postgresql.org/pgsql-performance/2004-04/msg00280.php + +Results attached in mptest.txt. The box did experience the same problems as +we've seen before. I ran it under a separate database (test), and it still +caused our other queries to slow significantly from our production database +(gf) - semwait again. + +It does look like the "cs" column under CPU (which I'd assume is Context +Swap) does bump up significantly (10x or better) during both my ab test, and +the test you suggested in that archived message. + +Reading the first thread you pointed out (2004-04/msg00249.php), Josh Berkus +was questioning the ServerWorks chipsets. We're running on the Intel E7501 +Chipset (MSI board). Our CPU's are 2.66 GHz with 533MHz FSB, Hyperthreading +enabled. Unfortunately, I don't have physical access to the machine to turn +HT off. + + +Thanks, + +Jason + + + +> -----Original Message----- +> From: Gaetano Mendola [mailto:mendola@bigfoot.com] +> Sent: Thursday, September 23, 2004 1:41 PM +> To: Jason Coene +> Subject: Re: Caching of Queries +> +> Jason Coene wrote: +> > Hi Tom, +> > +> > Easily recreated with Apache benchmark, "ab -n 30000 -c 3000 +> > http://webserver ". This runs 1 query per page, everything else is +> cached +> > on webserver. +> +> That test require 30000 access with 3000 connections that is not a normal +> load. Describe us your HW. +> +> 3000 connections means a very huge load, may you provide also the result +> of +> "vmstat 5" my webserver trash already with -c 120 ! +> +> how many connection your postgres can manage ? +> +> You have to consider to use a connection pool with that ammount of +> connections. +> +> +> Regards +> Gaetano Mendola + + +------=_NextPart_000_0012_01C4A17F.1BB1EB60 +Content-Type: text/plain; + name="ab_150conn.txt" +Content-Transfer-Encoding: quoted-printable +Content-Disposition: attachment; + filename="ab_150conn.txt" + +gf=3D# SELECT r.relname, l."mode", count(*) AS numlocks + FROM pg_locks l, pg_class r + WHERE r.oid =3D l.relation + GROUP BY r.relname, l."mode" + ORDER BY count(*) DESC; + + relname | mode | numlocks +----------------------------------+-----------------+---------- + threads | AccessShareLock | 63 + threads_ix_nuked_lastpost | AccessShareLock | 47 + threads_ix_nuked_gameid_lastpost | AccessShareLock | 7 + pg_class | AccessShareLock | 5 + pg_opclass_am_name_nsp_index | AccessShareLock | 3 + pg_opclass | AccessShareLock | 3 + pg_class_oid_index | AccessShareLock | 3 + pg_type | AccessShareLock | 2 + pg_statistic | AccessShareLock | 2 + pg_attribute | AccessShareLock | 2 + pg_amop_opc_strategy_index | AccessShareLock | 2 + pg_attrdef | AccessShareLock | 2 + pg_trigger_tgrelid_tgname_index | AccessShareLock | 2 + pg_trigger | AccessShareLock | 2 + users | AccessShareLock | 2 + pg_statistic_relid_att_index | AccessShareLock | 2 + pg_type_oid_index | AccessShareLock | 2 + pg_amop | AccessShareLock | 2 + pg_attribute_relid_attnum_index | AccessShareLock | 2 + comments | AccessShareLock | 2 + pg_shadow | AccessShareLock | 2 + acls | AccessShareLock | 1 + pg_index_indexrelid_index | AccessShareLock | 1 + pg_attrdef_adrelid_adnum_index | AccessShareLock | 1 + surveyresults_ix_userid | AccessShareLock | 1 + pg_cast | AccessShareLock | 1 + pg_shadow_usesysid_index | AccessShareLock | 1 + pg_index | AccessShareLock | 1 + games | AccessShareLock | 1 + usersessions | AccessShareLock | 1 + surveyoptions | AccessShareLock | 1 + countries | AccessShareLock | 1 + surveyresults | AccessShareLock | 1 + vopenlocks | AccessShareLock | 1 + pg_class_relname_nsp_index | AccessShareLock | 1 + pg_namespace | AccessShareLock | 1 + pg_database | AccessShareLock | 1 + surveys | AccessShareLock | 1 + pg_namespace_nspname_index | AccessShareLock | 1 + community | AccessShareLock | 1 + surveygroups | AccessShareLock | 1 + pg_cast_source_target_index | AccessShareLock | 1 + pg_locks | AccessShareLock | 1 + pg_shadow_usename_index | AccessShareLock | 1 +(44 rows) + +last pid: 27021; load averages: 9.73, 3.68, 1.93 = + up 19+22:06:45 = + 14:26:53 +102 processes: 27 running, 47 sleeping, 28 lock +CPU states: 16.5% user, 0.0% nice, 14.3% system, 0.4% interrupt, 68.8% id= +le +Mem: 95M Active, 1443M Inact, 190M Wired, 94M Cache, 112M Buf, 101M Free +Swap: 4096M Total, 4096M Free + + PID USERNAME PRI NICE SIZE RES STATE C TIME WCPU CPU COMMAND +50557 pgsql 76 0 95276K 4860K select 0 24:33 1.03% 1.03% postgres +26968 pgsql -4 0 96356K 50828K semwai 0 0:00 1.08% 0.20% postgres +26992 pgsql 129 0 96048K 28616K *Giant 0 0:00 2.05% 0.20% postgres +26983 pgsql 127 0 96048K 21800K RUN 3 0:00 1.40% 0.20% postgres +26924 pgsql -4 0 96848K 38912K semwai 2 0:00 0.56% 0.15% postgres +26916 pgsql -4 0 96232K 40876K semwai 0 0:00 0.50% 0.15% postgres +26957 pgsql 126 0 96048K 32544K RUN 2 0:00 0.81% 0.15% postgres +26949 pgsql 125 0 96048K 32796K RUN 1 0:00 0.66% 0.15% postgres +26979 pgsql 128 0 96048K 35240K RUN 0 0:00 1.05% 0.15% postgres +26950 pgsql 126 0 96048K 29676K RUN 1 0:00 0.81% 0.15% postgres +26984 pgsql -4 0 96320K 12100K semwai 0 0:00 1.05% 0.15% postgres +50562 pgsql 76 0 6584K 4724K select 0 14:17 0.10% 0.10% postgres +26921 pgsql 4 0 96984K 58516K sbwait 1 0:00 0.38% 0.10% postgres +26911 pgsql 122 0 96984K 52856K RUN 1 0:00 0.33% 0.10% postgres +26946 pgsql 125 0 96904K 50328K RUN 1 0:00 0.44% 0.10% postgres +26913 pgsql -4 0 96984K 50536K semwai 0 0:00 0.33% 0.10% postgres +26908 pgsql -4 0 96272K 34812K semwai 0 0:00 0.30% 0.10% postgres +26965 pgsql 126 0 97028K 45736K RUN 0 0:00 0.54% 0.10% postgres +26926 pgsql -4 0 96376K 33628K semwai 0 0:00 0.38% 0.10% postgres +26944 pgsql -4 0 96228K 43220K semwai 3 0:00 0.44% 0.10% postgres +26936 pgsql 125 0 96048K 33600K RUN 1 0:00 0.44% 0.10% postgres +26947 pgsql -4 0 96048K 32544K semwai 1 0:00 0.44% 0.10% postgres +26964 pgsql 126 0 96048K 33720K RUN 2 0:00 0.54% 0.10% postgres +26956 pgsql 126 0 96048K 29644K RUN 0 0:00 0.54% 0.10% postgres +26960 pgsql 126 0 96048K 29000K RUN 1 0:00 0.54% 0.10% postgres +26977 pgsql 127 0 96048K 31988K RUN 3 0:00 0.70% 0.10% postgres +26969 pgsql 126 0 96048K 28896K RUN 1 0:00 0.54% 0.10% postgres +26978 pgsql 127 0 96240K 17868K RUN 0 0:00 0.70% 0.10% postgres +26973 pgsql 126 0 96048K 25872K RUN 0 0:00 0.54% 0.10% postgres +26989 pgsql 129 0 96048K 29680K RUN 2 0:00 1.03% 0.10% postgres +26993 pgsql 129 0 96048K 30276K *Giant 3 0:00 1.03% 0.10% postgres +26985 pgsql -4 0 96048K 20272K semwai 3 0:00 1.03% 0.10% postgres +27002 pgsql 131 0 96048K 22392K *Giant 3 0:00 2.00% 0.10% postgres +26997 pgsql 129 0 96240K 10128K RUN 0 0:00 1.03% 0.10% postgres +26998 pgsql 131 0 96008K 8560K *Giant 3 0:00 2.00% 0.10% postgres +27007 pgsql 131 0 96048K 15016K *Giant 3 0:00 2.00% 0.10% postgres +26937 pgsql 125 0 97028K 29152K RUN 3 0:00 0.22% 0.05% postgres +26959 pgsql 126 0 96048K 30932K RUN 1 0:00 0.27% 0.05% postgres +26981 pgsql -4 0 96048K 28652K semwai 0 0:00 0.35% 0.05% postgres +26955 pgsql 126 0 96048K 28892K RUN 2 0:00 0.27% 0.05% postgres +26972 pgsql 126 0 96272K 16792K RUN 3 0:00 0.27% 0.05% postgres +26976 pgsql 127 0 96048K 28860K RUN 0 0:00 0.35% 0.05% postgres +26994 pgsql 129 0 96048K 28648K *Giant 0 0:00 0.51% 0.05% postgres +26996 pgsql 129 0 96048K 29036K *Giant 0 0:00 0.51% 0.05% postgres +26995 pgsql 129 0 96048K 25360K *Giant 2 0:00 0.51% 0.05% postgres +26987 pgsql 129 0 96048K 21732K *Giant 2 0:00 0.51% 0.05% postgres +26991 pgsql 129 0 96048K 25324K *Giant 3 0:00 0.51% 0.05% postgres +26990 pgsql 129 0 96240K 10660K *Giant 0 0:00 0.51% 0.05% postgres +27003 pgsql 131 0 96048K 14644K *Giant 2 0:00 1.00% 0.05% postgres +50564 pgsql 76 0 5912K 3964K select 0 14:06 0.00% 0.00% postgres + 1288 mysql 96 0 51092K 20280K select 1 5:21 0.00% 0.00% mysqld + +d01.int> vmstat 5 + procs memory page disks faults cpu + r b w avm fre flt re pi po fr sr da0 fd0 in sy cs us sy = +id + 2 0 0 187748 268744 2332 0 0 0 1686 1 0 0 722 0 422 5 3= + 91 + 0 0 2 186664 269572 8795 0 0 0 1867 0 2 0 727 0 3190 5 = +4 91 + 0 0 0 183780 271296 8041 0 0 0 1633 0 3 0 665 0 1952 5 = +3 92 + 0 0 0 183780 271296 9555 0 0 0 1814 0 4 0 755 0 2850 5 = +4 90 +[begin ab] + 1 52 14 280896 213092 25974 0 0 0 2980 0 0 0 1202 0 26804 = +14 14 72 + 0 46 23 292164 205220 22854 0 0 0 3606 0 24 0 1082 0 40464 = +14 17 69 + 5 56 19 308216 194320 22839 0 0 0 4010 0 2 0 1102 0 41540 = +15 16 69 + 4 68 12 311540 194384 21314 0 0 0 3925 0 7 0 1038 0 49771 = +16 16 68 + 0 59 27 316904 187996 21678 0 0 0 3752 0 5 0 1057 0 43480 = +15 16 69 + 0 43 46 321064 186856 22168 0 0 0 4041 0 4 0 1047 0 43670 = +15 16 69 + 4 82 5 330776 180308 21773 0 0 0 3354 0 7 0 995 0 47354 1= +3 18 68 +[end ab] + 0 29 5 252440 227260 19208 0 0 0 4966 0 34 0 1086 0 47183 1= +6 19 66 + 0 0 0 183780 271280 10660 0 0 0 3944 0 3 0 760 0 10161 9= + 6 85 +^C + +------=_NextPart_000_0012_01C4A17F.1BB1EB60 +Content-Type: text/plain; + name="mptest.txt" +Content-Transfer-Encoding: quoted-printable +Content-Disposition: attachment; + filename="mptest.txt" + +running two copies of: + +drop table test_data; + +create table test_data(f1 int); + +insert into test_data values (random() * 100); +insert into test_data select random() * 100 from test_data; +insert into test_data select random() * 100 from test_data; +insert into test_data select random() * 100 from test_data; +insert into test_data select random() * 100 from test_data; +insert into test_data select random() * 100 from test_data; +insert into test_data select random() * 100 from test_data; +insert into test_data select random() * 100 from test_data; +insert into test_data select random() * 100 from test_data; +insert into test_data select random() * 100 from test_data; +insert into test_data select random() * 100 from test_data; +insert into test_data select random() * 100 from test_data; +insert into test_data select random() * 100 from test_data; +insert into test_data select random() * 100 from test_data; +insert into test_data select random() * 100 from test_data; +insert into test_data select random() * 100 from test_data; +insert into test_data select random() * 100 from test_data; + +create index test_index on test_data(f1); + +vacuum verbose analyze test_data; +checkpoint; + +-- force nestloop indexscan plan +set enable_seqscan to 0; +set enable_mergejoin to 0; +set enable_hashjoin to 0; + +explain +select count(*) from test_data a, test_data b, test_data c +where a.f1 =3D b.f1 and b.f1 =3D c.f1; + +select count(*) from test_data a, test_data b, test_data c +where a.f1 =3D b.f1 and b.f1 =3D c.f1; + +-- + +Result from 1 of 2 executions: + +d01.int> psql -U test; +Welcome to psql 7.4.5, the PostgreSQL interactive terminal. + +Type: \copyright for distribution terms + \h for help with SQL commands + \? for help on internal slash commands + \g or terminate with semicolon to execute query + \q to quit + +test=3D> \i test.sql +DROP TABLE +CREATE TABLE +INSERT 11296941 1 +INSERT 11296942 1 +INSERT 0 2 +INSERT 0 4 +INSERT 0 8 +INSERT 0 16 +INSERT 0 32 +INSERT 0 64 +INSERT 0 128 +INSERT 0 256 +INSERT 0 512 +INSERT 0 1024 +INSERT 0 2048 +INSERT 0 4096 +INSERT 0 8192 +INSERT 0 16384 +INSERT 0 32768 +psql:test.sql:23: ERROR: relation "test_index" already exists +psql:test.sql:25: INFO: vacuuming "public.test_data" +psql:test.sql:25: INFO: index "test_index" now contains 65536 row versions= + in 198 pages +DETAIL: 0 index pages have been deleted, 0 are currently reusable. +CPU 0.00s/0.00u sec elapsed 1.74 sec. +psql:test.sql:25: INFO: "test_data": found 0 removable, 65536 nonremovable= + row versions in 289 pages +DETAIL: 0 dead row versions cannot be removed yet. +There were 0 unused item pointers. +0 pages are entirely empty. +CPU 0.00s/0.01u sec elapsed 1.75 sec. +psql:test.sql:25: INFO: analyzing "public.test_data" +psql:test.sql:25: INFO: "test_data": 289 pages, 3000 rows sampled, 65603 e= +stimated total rows +VACUUM +CHECKPOINT +SET +SET +SET + QUERY PLAN=20=20=20=20=20=20= +=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 +---------------------------------------------------------------------------= +---------------------------- + Aggregate (cost=3D50844039917.94..50844039917.94 rows=3D1 width=3D0) + -> Nested Loop (cost=3D0.00..50773112976.11 rows=3D28370776731 width= +=3D0) + -> Nested Loop (cost=3D0.00..77053124.16 rows=3D43119685 width= +=3D8) + -> Index Scan using test_index on test_data b (cost=3D0.00= +..2074.77 rows=3D65536 width=3D4) + -> Index Scan using test_index on test_data c (cost=3D0.00= +..1167.59 rows=3D649 width=3D4) + Index Cond: ("outer".f1 =3D c.f1) + -> Index Scan using test_index on test_data a (cost=3D0.00..1167= +.59 rows=3D649 width=3D4) + Index Cond: ("outer".f1 =3D a.f1) +(8 rows) + +^CCancel request sent +psql:test.sql:38: ERROR: canceling query due to user request +test=3D> + + +--- + + +d01.int> vmstat 5 + procs memory page disks faults cpu + r b w avm fre flt re pi po fr sr da0 fd0 in sy cs us sy = +id + 0 0 0 196360 258572 2336 0 0 0 1687 1 0 0 722 0 424 5 3= + 91 + 0 2 3 208792 249976 9917 0 0 0 1440 0 2 0 720 0 3958 5 = +4 91 + 1 0 0 202056 254900 14728 0 0 0 2844 0 12 0 1128 0 5755 9 = + 7 84 + 3 0 0 199960 252148 13975 0 1 0 3009 0 47 0 1126 0 13410 15= + 8 77 + 0 2 3 203568 247276 8469 0 0 0 1603 0 42 0 906 0 8774 26 = +5 69 + 0 10 7 225508 232968 10533 0 0 0 1023 0 13 0 710 0 11756 2= +8 765 + 0 1 4 202724 248416 8847 0 0 0 2374 0 1 0 697 0 8671 30 = +5 65 + 0 15 14 245484 220092 11856 0 0 0 1176 0 9 0 917 0 13885 = +26 8 66 + 0 20 7 243836 222684 13190 0 0 0 2208 0 7 0 831 0 17925 2= +4 10 67 + 0 4 7 217928 240192 10879 0 0 0 3026 0 10 0 954 0 14428 28= + 7 65 + 0 3 10 223192 236708 10570 0 0 0 2042 0 35 0 872 0 10530 2= +9 6 66 + 3 12 1 225916 235372 11205 0 0 0 2048 0 6 0 809 0 12919 2= +6 7 67 + 0 9 8 224092 236468 12562 0 0 0 2116 0 6 0 882 0 11334 26= + 7 67 + 4 2 0 208728 246880 9979 0 0 0 2224 0 3 0 758 0 9319 28 = +6 66 + 4 5 6 217832 241144 11436 0 0 0 1995 0 9 0 852 0 10787 26= + 6 67 + 5 3 4 216452 241404 10989 0 0 0 2256 0 11 0 831 0 12633 27= + 7 66 + 1 0 0 198896 255112 10958 0 0 0 2281 0 45 0 855 0 14768 20= + 7 73 + 0 0 0 197204 256160 9382 0 0 0 1701 0 6 0 727 0 3634 5 = +4 91 +^C + +------=_NextPart_000_0012_01C4A17F.1BB1EB60-- + + +From pgsql-performance-owner@postgresql.org Thu Sep 23 20:25:07 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id A7BE0329CE3 + for ; + Thu, 23 Sep 2004 20:24:51 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 47336-07 + for ; + Thu, 23 Sep 2004 19:24:41 +0000 (GMT) +Received: from ms-smtp-04.nyroc.rr.com (ms-smtp-04.nyroc.rr.com [24.24.2.58]) + by svr1.postgresql.org (Postfix) with ESMTP id EED17329CF8 + for ; + Thu, 23 Sep 2004 20:24:41 +0100 (BST) +Received: from jcoene2 (roc-66-66-153-192.rochester.rr.com [66.66.153.192]) + by ms-smtp-04.nyroc.rr.com (8.12.10/8.12.10) with ESMTP id + i8NJOVIh012218; Thu, 23 Sep 2004 15:24:31 -0400 (EDT) +Message-Id: <200409231924.i8NJOVIh012218@ms-smtp-04.nyroc.rr.com> +From: "Jason Coene" +To: +Cc: , , +Subject: Re: Caching of Queries +Date: Thu, 23 Sep 2004 15:24:33 -0400 +MIME-Version: 1.0 +Content-Type: multipart/mixed; + boundary="----=_NextPart_000_001E_01C4A181.6F763F10" +X-Mailer: Microsoft Office Outlook, Build 11.0.5510 +In-Reply-To: <200409231907.i8NJ7rv2004899@ms-smtp-03.nyroc.rr.com> +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 +Thread-Index: AcShlHfHCGA3N4JqSiiyHaMXraZADQAAqeFAAALOeiA= +X-Virus-Scanned: Symantec AntiVirus Scan Engine +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/256 +X-Sequence-Number: 8384 + +This is a multi-part message in MIME format. + +------=_NextPart_000_001E_01C4A181.6F763F10 +Content-Type: text/plain; + charset="us-ascii" +Content-Transfer-Encoding: 7bit + +Update: + +I just tried running the same test (ab with 150 concurrent connections) +while connecting to postgres through 35 persistent connections (PHP +library), and had roughly the same type of results. This should eliminate +the "new connection" overhead. I've attached top and vmstat. I let it run +until it had completed 800 requests. Unless I'm missing something, there's +more than the "new connection" IO load here. + +Jason + +> -----Original Message----- +> From: Jason Coene [mailto:jcoene@gotfrag.com] +> Sent: Thursday, September 23, 2004 3:08 PM +> To: pgsql-performance@postgresql.org +> Cc: mendola@bigfoot.com; tgl@sss.pgh.pa.us; josh@agliodbs.com +> Subject: RE: Caching of Queries +> +> Hi All, +> +> It does sound like we should be pooling connections somehow. I'll be +> looking at implementing that shortly. I'd really like to understand what +> the actual problem is, though. +> +> Sorry, I meant 30,000 with 300 connections - not 3,000. The 300 +> connections +> / second is realistic, if not underestimated. As is the nature of our +> site +> (realtime information about online gaming), there's a huge fan base and as +> a +> big upset happens, we'll do 50,000 page views in a span of 3-5 minutes. +> +> I get the same results with: +> +> ab -n 10000 -c 150 http://www.gotfrag.com/portal/news/ +> +> I've attached results from the above test, showing open locks, top output, +> and vmstat 5. +> +> Tom, I've run the test described in: +> +> http://archives.postgresql.org/pgsql-performance/2004-04/msg00280.php +> +> Results attached in mptest.txt. The box did experience the same problems +> as +> we've seen before. I ran it under a separate database (test), and it +> still +> caused our other queries to slow significantly from our production +> database +> (gf) - semwait again. +> +> It does look like the "cs" column under CPU (which I'd assume is Context +> Swap) does bump up significantly (10x or better) during both my ab test, +> and +> the test you suggested in that archived message. +> +> Reading the first thread you pointed out (2004-04/msg00249.php), Josh +> Berkus +> was questioning the ServerWorks chipsets. We're running on the Intel +> E7501 +> Chipset (MSI board). Our CPU's are 2.66 GHz with 533MHz FSB, +> Hyperthreading +> enabled. Unfortunately, I don't have physical access to the machine to +> turn +> HT off. +> +> +> Thanks, +> +> Jason +> +> +> +> > -----Original Message----- +> > From: Gaetano Mendola [mailto:mendola@bigfoot.com] +> > Sent: Thursday, September 23, 2004 1:41 PM +> > To: Jason Coene +> > Subject: Re: Caching of Queries +> > +> > Jason Coene wrote: +> > > Hi Tom, +> > > +> > > Easily recreated with Apache benchmark, "ab -n 30000 -c 3000 +> > > http://webserver ". This runs 1 query per page, everything else is +> > cached +> > > on webserver. +> > +> > That test require 30000 access with 3000 connections that is not a +> normal +> > load. Describe us your HW. +> > +> > 3000 connections means a very huge load, may you provide also the result +> > of +> > "vmstat 5" my webserver trash already with -c 120 ! +> > +> > how many connection your postgres can manage ? +> > +> > You have to consider to use a connection pool with that ammount of +> > connections. +> > +> > +> > Regards +> > Gaetano Mendola + + +------=_NextPart_000_001E_01C4A181.6F763F10 +Content-Type: text/plain; + name="ab_150conn_35persistconn.txt" +Content-Transfer-Encoding: quoted-printable +Content-Disposition: attachment; + filename="ab_150conn_35persistconn.txt" + +last pid: 48239; load averages: 5.83, 2.43, 1.50 up 19+22:59:04 15:1= +9:12 +127 processes: 16 running, 111 sleeping +CPU states: 17.7% user, 0.0% nice, 20.0% system, 1.0% interrupt, 61.3% id= +le +Mem: 125M Active, 1456M Inact, 193M Wired, 96M Cache, 112M Buf, 54M Free +Swap: 4096M Total, 4096M Free + + PID USERNAME PRI NICE SIZE RES STATE C TIME WCPU CPU COMMAND +48190 pgsql -4 0 97408K 86416K semwai 1 0:01 3.35% 1.32% postgres +47761 pgsql -4 0 96816K 56708K semwai 2 0:01 0.90% 0.88% postgres +47765 pgsql 4 0 96816K 56708K sbwait 3 0:01 0.90% 0.88% postgres +47754 pgsql -4 0 96816K 56708K semwai 2 0:01 0.85% 0.83% postgres +47763 pgsql -4 0 96816K 56708K semwai 0 0:01 0.85% 0.83% postgres +47741 pgsql 4 0 96816K 56708K sbwait 3 0:01 0.75% 0.73% postgres +47674 pgsql -4 0 96264K 38992K semwai 1 0:01 0.74% 0.73% postgres +47753 pgsql -4 0 96816K 56708K semwai 1 0:00 0.65% 0.63% postgres +48204 pgsql -4 0 96856K 46752K semwai 0 0:00 2.15% 0.63% postgres +47698 pgsql 4 0 96240K 37792K sbwait 3 0:01 0.59% 0.59% postgres +47757 pgsql -4 0 96816K 56708K semwai 3 0:01 0.60% 0.59% postgres +47740 pgsql 4 0 96240K 37768K sbwait 0 0:01 0.55% 0.54% postgres +47759 pgsql 4 0 96816K 56708K sbwait 0 0:01 0.50% 0.49% postgres +47735 pgsql -4 0 96240K 37772K semwai 0 0:00 0.50% 0.49% postgres +48223 pgsql -4 0 96984K 55980K semwai 1 0:00 2.69% 0.49% postgres +48102 pgsql 4 0 96136K 54956K sbwait 0 0:00 0.69% 0.44% postgres +47718 pgsql 4 0 96816K 56716K sbwait 1 0:01 0.40% 0.39% postgres +48225 pgsql 123 0 96272K 57156K RUN 0 0:00 2.80% 0.39% postgres +48053 pgsql -4 0 96136K 55040K semwai 0 0:00 0.48% 0.34% postgres +48041 pgsql 4 0 96136K 54992K sbwait 1 0:00 0.47% 0.34% postgres +48222 pgsql -4 0 96872K 57676K semwai 1 0:00 1.88% 0.34% postgres +48216 pgsql -4 0 96800K 54596K semwai 0 0:00 1.54% 0.34% postgres +48050 pgsql 4 0 96136K 56592K sbwait 3 0:00 0.41% 0.29% postgres +48232 pgsql 126 0 96048K 31192K RUN 3 0:00 3.08% 0.29% postgres +48091 pgsql -4 0 96136K 54956K semwai 3 0:00 0.39% 0.24% postgres +48095 pgsql 98 0 96048K 34880K RUN 1 0:00 0.39% 0.24% postgres +48136 pgsql 4 0 96136K 54956K sbwait 0 0:00 0.43% 0.24% postgres +48214 pgsql -4 0 96376K 43628K semwai 3 0:00 1.10% 0.24% postgres +48221 pgsql 121 0 96904K 47788K RUN 3 0:00 1.35% 0.24% postgres +48230 pgsql 126 0 96984K 44964K RUN 2 0:00 2.56% 0.24% postgres +48234 pgsql -4 0 97028K 27496K semwai 3 0:00 5.00% 0.24% postgres +48059 pgsql 4 0 96048K 34916K sbwait 2 0:00 0.28% 0.20% postgres +48057 pgsql 4 0 96136K 54992K sbwait 1 0:00 0.28% 0.20% postgres +48131 pgsql 4 0 96136K 54956K sbwait 0 0:00 0.33% 0.20% postgres +48142 pgsql -4 0 96136K 54956K semwai 0 0:00 0.34% 0.20% postgres +48148 pgsql 102 0 96136K 54956K RUN 1 0:00 0.35% 0.20% postgres +48118 pgsql 4 0 96048K 34884K sbwait 0 0:00 0.33% 0.20% postgres +47708 pgsql 4 0 96916K 49324K sbwait 2 0:00 0.20% 0.20% postgres +48226 pgsql 4 0 96048K 34884K sbwait 2 0:00 1.40% 0.20% postgres +48075 pgsql -4 0 96048K 34884K semwai 1 0:00 0.22% 0.15% postgres +48117 pgsql 4 0 96136K 58208K sbwait 0 0:00 0.25% 0.15% postgres + +d01.int> vmstat 5 + procs memory page disks faults cpu + r b w avm fre flt re pi po fr sr da0 fd0 in sy cs us sy = +id + 0 0 0 212652 241296 2348 0 0 0 1687 1 0 0 723 0 431 5 3= + 91 + 0 0 0 212720 241228 9198 0 0 0 1970 0 2 0 749 0 2400 5 = +5 91 +[begins] + 1 0 0 227828 232504 8948 0 0 0 1353 0 8 0 1170 0 29669 17 = + 9 75 + 0 2 8 297908 190496 17897 0 0 0 1439 0 2 0 1222 0 18880 17= + 9 74 + 5 43 4 341412 160524 18352 0 0 0 1372 0 8 0 1481 0 32656 1= +9 12 68 + 0 48 13 347956 156412 13473 0 0 0 1727 0 28 0 1109 0 60976 = +19 17 64 + 5 54 6 357700 150248 14142 0 0 0 1495 0 3 0 1104 0 52658 1= +9 16 65 + 0 53 8 338828 162376 9523 0 0 0 2361 0 2 0 1029 0 68759 21= + 18 61 + 1 0 0 317496 175964 13612 0 0 0 2902 0 4 0 1132 0 44194 18= + 14 68 +[ends] + 0 0 0 314544 177624 10144 0 0 0 2014 0 4 0 754 0 2590 6 = + 4 90 + 0 0 0 195372 253776 7211 0 0 0 5269 0 5 0 717 0 2719 4 = +4 91 + 0 0 0 190812 256580 11132 0 0 0 2380 0 33 0 875 0 3014 6 = + 5 89 +^C + +------=_NextPart_000_001E_01C4A181.6F763F10-- + + +From pgsql-performance-owner@postgresql.org Thu Sep 23 23:45:06 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 311BC329CD9 + for ; + Thu, 23 Sep 2004 23:45:00 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 10681-07 + for ; + Thu, 23 Sep 2004 22:44:48 +0000 (GMT) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by svr1.postgresql.org (Postfix) with ESMTP id 99789329E45 + for ; + Thu, 23 Sep 2004 23:44:49 +0100 (BST) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by news.hub.org (8.12.9/8.12.9) with ESMTP id i8NMijfg013667 + for ; Thu, 23 Sep 2004 22:44:45 GMT + (envelope-from news@news.hub.org) +Received: (from news@localhost) + by news.hub.org (8.12.9/8.12.9/Submit) id i8NMGPaY006309 + for pgsql-performance@postgresql.org; Thu, 23 Sep 2004 22:16:25 GMT +From: Martin Foster +Organization: Ethereal Realms +User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; + rv:1.7.3) Gecko/20040910 +X-Accept-Language: en-us, en +MIME-Version: 1.0 +X-Newsgroups: comp.databases.postgresql.performance +Subject: Cleaning up indexes +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit +Lines: 20 +Message-ID: <0XH4d.41061$yW6.30251@clgrps12> +Date: Thu, 23 Sep 2004 22:16:28 GMT +To: pgsql-performance@postgresql.org +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/257 +X-Sequence-Number: 8385 + +My database was converted from MySQL a while back and has maintained all +of the indexes which were previously used. Tt the time however, there +were limitations on the way PostgreSQL handled the indexes compared to +MySQL. + +Meaning that under MySQL, it would make use of a multi-column index even +if the rows within did not match. When the conversion was made more +indexes were created overall to correct this and proceed with the +conversion. + +Now the time has come to clean up the used indexes. Essentially, I +want to know if there is a way in which to determine which indexes are +being used and which are not. This will allow me to drop off the +unneeded ones and reduce database load as a result. + +And have things changed as to allow for mismatched multi-column indexes +in version 7.4.x or even the upcoming 8.0.x? + + Martin Foster + martin@ethereal-realms.org + +From pgsql-performance-owner@postgresql.org Fri Sep 24 00:06:05 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 9716E329D7A + for ; + Fri, 24 Sep 2004 00:05:39 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 16380-04 + for ; + Thu, 23 Sep 2004 23:05:26 +0000 (GMT) +Received: from loki.globexplorer.com (unknown [208.35.14.101]) + by svr1.postgresql.org (Postfix) with ESMTP id 2C99E329CD9 + for ; + Fri, 24 Sep 2004 00:05:23 +0100 (BST) +X-MimeOLE: Produced By Microsoft Exchange V6.0.6249.0 +content-class: urn:content-classes:message +MIME-Version: 1.0 +Content-Type: text/plain; + charset="Windows-1252" +Content-Transfer-Encoding: quoted-printable +Subject: Re: Cleaning up indexes +Date: Thu, 23 Sep 2004 16:05:22 -0700 +Message-ID: + <71E37EF6B7DCC1499CEA0316A256832801D4B846@loki.wc.globexplorer.net> +X-MS-Has-Attach: +X-MS-TNEF-Correlator: +Thread-Topic: [PERFORM] Cleaning up indexes +Thread-Index: AcShv19b+oLFVkumRFSeSOApsJ8s2QAAfp3H +From: "Gregory S. Williamson" +To: "Martin Foster" , + +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/258 +X-Sequence-Number: 8386 + + +If you have set up the postgres instance to write stats, the tables pg_stat= +_user_indexes, pg_statio_all_indexes and so (use the \dS option at the psql= + prompt to see these system tables); also check the pg_stat_user_tables tab= +le and similar beasts for information on total access, etc. Between these y= +ou can get a good idea of what indexes are not being used, and from the seq= +uentail scan info on tables perhaps some idea of what may need some indexes. + +HTH, + +Greg Williamson +DBA +GlobeXplorer LLC=20 + +-----Original Message----- +From: Martin Foster [mailto:martin@ethereal-realms.org] +Sent: Thu 9/23/2004 3:16 PM +To: pgsql-performance@postgresql.org +Cc:=09 +Subject: [PERFORM] Cleaning up indexes +My database was converted from MySQL a while back and has maintained all=20 +of the indexes which were previously used. Tt the time however, there=20 +were limitations on the way PostgreSQL handled the indexes compared to=20 +MySQL. + +Meaning that under MySQL, it would make use of a multi-column index even=20 +if the rows within did not match. When the conversion was made more=20 +indexes were created overall to correct this and proceed with the=20 +conversion. + +Now the time has come to clean up the used indexes. Essentially, I=20 +want to know if there is a way in which to determine which indexes are=20 +being used and which are not. This will allow me to drop off the=20 +unneeded ones and reduce database load as a result. + +And have things changed as to allow for mismatched multi-column indexes=20 +in version 7.4.x or even the upcoming 8.0.x? + + Martin Foster + martin@ethereal-realms.org + +---------------------------(end of broadcast)--------------------------- +TIP 9: the planner will ignore your desire to choose an index scan if your + joining column's datatypes do not match + + + + +From pgsql-performance-owner@postgresql.org Fri Sep 24 00:22:33 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id D86F8329E4A + for ; + Fri, 24 Sep 2004 00:22:27 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 20688-06 + for ; + Thu, 23 Sep 2004 23:22:15 +0000 (GMT) +Received: from mail63.csoft.net (leary3.csoft.net [63.111.22.74]) + by svr1.postgresql.org (Postfix) with SMTP id 402C2329E49 + for ; + Fri, 24 Sep 2004 00:22:15 +0100 (BST) +Received: (qmail 23664 invoked by uid 1112); 23 Sep 2004 23:22:15 -0000 +Date: Thu, 23 Sep 2004 18:22:15 -0500 (EST) +From: Kris Jurka +X-X-Sender: books@leary.csoft.net +To: Stephen Crowley +Cc: pgsql-performance@postgresql.org +Subject: Re: Large # of rows in query extremely slow, not using +In-Reply-To: <3f71fdf104091323047de7bb01@mail.gmail.com> +Message-ID: +References: <3f71fdf104091317515c756512@mail.gmail.com> + <28088.1095124267@sss.pgh.pa.us> + <3f71fdf104091318228099815@mail.gmail.com> + <28432.1095126554@sss.pgh.pa.us> + <3f71fdf104091323047de7bb01@mail.gmail.com> +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/259 +X-Sequence-Number: 8387 + + + +On Tue, 14 Sep 2004, Stephen Crowley wrote: + +> Problem solved.. I set the fetchSize to a reasonable value instead of +> the default of unlimited in the PreparedStatement and now the query +> is . After some searching it seeems this is a common problem, would it +> make sense to change the default value to something other than 0 in +> the JDBC driver? + +In the JDBC driver, setting the fetch size to a non-zero value means that +the query will be run using what the frontend/backend protocol calls a +named statement. What this means on the backend is that the planner will +not be able to use the values from the query parameters to generate the +optimum query plan and must use generic placeholders and create a generic +plan. For this reason we have decided not to default to a non-zero +fetch size. This is something whose default value could be set by a URL +parameter if you think that is something that is really required. + +Kris Jurka + + +From pgsql-performance-owner@postgresql.org Fri Sep 24 00:37:04 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 7FE4D329E2C + for ; + Fri, 24 Sep 2004 00:37:01 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 23736-07 + for ; + Thu, 23 Sep 2004 23:36:49 +0000 (GMT) +Received: from mproxy.gmail.com (rproxy.gmail.com [64.233.170.197]) + by svr1.postgresql.org (Postfix) with ESMTP id 645F2329E12 + for ; + Fri, 24 Sep 2004 00:36:50 +0100 (BST) +Received: by mproxy.gmail.com with SMTP id v30so92907rnb + for ; + Thu, 23 Sep 2004 16:36:49 -0700 (PDT) +Received: by 10.38.179.69 with SMTP id b69mr255241rnf; + Thu, 23 Sep 2004 16:36:49 -0700 (PDT) +Received: by 10.38.8.71 with HTTP; Thu, 23 Sep 2004 16:36:49 -0700 (PDT) +Message-ID: <3f71fdf104092316367c5f3052@mail.gmail.com> +Date: Thu, 23 Sep 2004 18:36:49 -0500 +From: Stephen Crowley +Reply-To: Stephen Crowley +To: pgsql-performance@postgresql.org +Subject: Re: Large # of rows in query extremely slow, not using index +Cc: Kris Jurka +In-Reply-To: +Mime-Version: 1.0 +Content-Type: text/plain; charset=US-ASCII +Content-Transfer-Encoding: 7bit +References: <3f71fdf104091317515c756512@mail.gmail.com> + <28088.1095124267@sss.pgh.pa.us> + <3f71fdf104091318228099815@mail.gmail.com> + <28432.1095126554@sss.pgh.pa.us> + <3f71fdf104091323047de7bb01@mail.gmail.com> + +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/260 +X-Sequence-Number: 8388 + +Thanks for the explanation. So what sort of changes need to be made to +the client/server protocol to fix this problem? + + + +On Thu, 23 Sep 2004 18:22:15 -0500 (EST), Kris Jurka wrote: +> +> +> On Tue, 14 Sep 2004, Stephen Crowley wrote: +> +> > Problem solved.. I set the fetchSize to a reasonable value instead of +> > the default of unlimited in the PreparedStatement and now the query +> > is . After some searching it seeems this is a common problem, would it +> > make sense to change the default value to something other than 0 in +> > the JDBC driver? +> +> In the JDBC driver, setting the fetch size to a non-zero value means that +> the query will be run using what the frontend/backend protocol calls a +> named statement. What this means on the backend is that the planner will +> not be able to use the values from the query parameters to generate the +> optimum query plan and must use generic placeholders and create a generic +> plan. For this reason we have decided not to default to a non-zero +> fetch size. This is something whose default value could be set by a URL +> parameter if you think that is something that is really required. +> +> Kris Jurka +> +> + +From pgsql-performance-owner@postgresql.org Fri Sep 24 00:48:45 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 1C0A9329CA4 + for ; + Fri, 24 Sep 2004 00:48:39 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 27822-05 + for ; + Thu, 23 Sep 2004 23:48:26 +0000 (GMT) +Received: from mail63.csoft.net (leary3.csoft.net [63.111.22.74]) + by svr1.postgresql.org (Postfix) with SMTP id 964A5329E4C + for ; + Fri, 24 Sep 2004 00:48:26 +0100 (BST) +Received: (qmail 27753 invoked by uid 1112); 23 Sep 2004 23:47:59 -0000 +Date: Thu, 23 Sep 2004 18:47:59 -0500 (EST) +From: Kris Jurka +X-X-Sender: books@leary.csoft.net +To: Stephen Crowley +Cc: pgsql-performance@postgresql.org +Subject: Re: Large # of rows in query extremely slow, not using +In-Reply-To: <3f71fdf104092316367c5f3052@mail.gmail.com> +Message-ID: +References: <3f71fdf104091317515c756512@mail.gmail.com> + <28088.1095124267@sss.pgh.pa.us> + <3f71fdf104091318228099815@mail.gmail.com> + <28432.1095126554@sss.pgh.pa.us> + <3f71fdf104091323047de7bb01@mail.gmail.com> + + <3f71fdf104092316367c5f3052@mail.gmail.com> +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/261 +X-Sequence-Number: 8389 + + + +On Thu, 23 Sep 2004, Stephen Crowley wrote: + +> Thanks for the explanation. So what sort of changes need to be made to +> the client/server protocol to fix this problem? + +The problem is that there is no way to indicate why you are using a +particular statement in the extended query protocol. For the JDBC driver +there are two potential reasons, streaming a ResultSet and using a server +prepared statement. For the streaming as default case you desire there +needs to be a way to indicate that you don't want to create a generic +server prepared statement and that this query is really just for one time +use, so it can generate the best plan possible. + +Additionally you can only stream ResultSets that are of type FORWARD_ONLY. +It would also be nice to be able to specify scrollability and holdability +when creating a statement and the offset/direction when streaming data +from a scrollable one. + +Kris Jurka + +From pgsql-performance-owner@postgresql.org Fri Sep 24 01:04:52 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 8749B329E32 + for ; + Fri, 24 Sep 2004 01:04:43 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 30919-08 + for ; + Fri, 24 Sep 2004 00:04:37 +0000 (GMT) +Received: from davinci.ethosmedia.com (server226.ethosmedia.com + [209.128.84.226]) + by svr1.postgresql.org (Postfix) with ESMTP id 23D6E329CDD + for ; + Fri, 24 Sep 2004 01:04:38 +0100 (BST) +Received: by davinci.ethosmedia.com (CommuniGate Pro PIPE 4.1.8) + with PIPE id 6399643; Thu, 23 Sep 2004 17:06:00 -0700 +Received: from [66.167.72.154] (account josh@agliodbs.com) + by davinci.ethosmedia.com (CommuniGate Pro WebUser 4.1.8) + with HTTP id 6399646; Thu, 23 Sep 2004 17:05:58 -0700 +From: "Josh Berkus" +Subject: Re: Caching of Queries +To: "Jason Coene" , + +Cc: , , +X-Mailer: CommuniGate Pro WebUser Interface v.4.1.8 +Date: Thu, 23 Sep 2004 17:05:58 -0700 +Message-ID: +In-Reply-To: <200409231907.i8NJ7rv2004899@ms-smtp-03.nyroc.rr.com> +MIME-Version: 1.0 +Content-Type: text/plain; charset="ISO-8859-1" +Content-Transfer-Encoding: 8bit +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/262 +X-Sequence-Number: 8390 + +Jason, + +> Sorry, I meant 30,000 with 300 connections - not 3,000. The 300 +> connections +> / second is realistic, if not underestimated. As is the nature of +> our site +> (realtime information about online gaming), there's a huge fan base +> and as a +> big upset happens, we'll do 50,000 page views in a span of 3-5 +> minutes. + +First, your posts show no evidences of the CS storm bug. + +Second, 300 *new* connections a second is a lot. Each new connection +requires a significant amount of both database and OS overhead. This +is why all the other web developers use a connection pool. + +In fact, I wouldn't be surprised if your lockups are on the OS level, +even; I don't recall that you cited what OS you're using, but I can +imagine locking up Linux 2.4 trying to spawn 300 new processes a +second. + +--Josh + +From pgsql-performance-owner@postgresql.org Fri Sep 24 01:41:53 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 13A81329E3A + for ; + Fri, 24 Sep 2004 01:40:16 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 38602-08 + for ; + Fri, 24 Sep 2004 00:40:10 +0000 (GMT) +Received: from hosting.commandprompt.com (128.commandprompt.com + [207.173.200.128]) + by svr1.postgresql.org (Postfix) with ESMTP id 16E10329E32 + for ; + Fri, 24 Sep 2004 01:40:12 +0100 (BST) +Received: from [192.168.1.20] (clbb-248.saw.net [64.146.135.248]) + (authenticated) + by hosting.commandprompt.com (8.11.6/8.11.6) with ESMTP id i8O0e1818250; + Thu, 23 Sep 2004 17:40:01 -0700 +Message-ID: <41536C4A.2010702@commandprompt.com> +Date: Thu, 23 Sep 2004 17:37:30 -0700 +From: "Joshua D. Drake" +Organization: Command Prompt, Inc. +User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: Josh Berkus +Cc: Jason Coene , + pgsql-performance@postgresql.org, mendola@bigfoot.com, tgl@sss.pgh.pa.us +Subject: Re: Caching of Queries +References: +In-Reply-To: +Content-Type: multipart/alternative; + boundary="------------070605060102080306070907" +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.5 tagged_above=0.0 required=5.0 tests=HTML_MESSAGE, + HTML_TITLE_EMPTY +X-Spam-Level: +X-Archive-Number: 200409/263 +X-Sequence-Number: 8391 + +This is a multi-part message in MIME format. +--------------070605060102080306070907 +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit + + +>>Sorry, I meant 30,000 with 300 connections - not 3,000. The 300 +>>connections +>>/ second is realistic, if not underestimated. As is the nature of +>>our site +>>(realtime information about online gaming), there's a huge fan base +>>and as a +>>big upset happens, we'll do 50,000 page views in a span of 3-5 +>>minutes. +>> +>> +> +>First, your posts show no evidences of the CS storm bug. +> +>Second, 300 *new* connections a second is a lot. Each new connection +>requires a significant amount of both database and OS overhead. This +>is why all the other web developers use a connection pool. +> +> +> +I would second this. You need to be running a connection pool and +probably multiple web servers in +front of that. You are talking about a huge amount of connections in +that amount of time. + +Josh Drake + + + +>In fact, I wouldn't be surprised if your lockups are on the OS level, +>even; I don't recall that you cited what OS you're using, but I can +>imagine locking up Linux 2.4 trying to spawn 300 new processes a +>second. +> +>--Josh +> +>---------------------------(end of broadcast)--------------------------- +>TIP 8: explain analyze is your friend +> +> + + +-- +Command Prompt, Inc., home of Mammoth PostgreSQL - S/ODBC and S/JDBC +Postgresql support, programming shared hosting and dedicated hosting. ++1-503-667-4564 - jd@commandprompt.com - http://www.commandprompt.com +PostgreSQL Replicator -- production quality replication for PostgreSQL + + +--------------070605060102080306070907 +Content-Type: text/html; charset=us-ascii +Content-Transfer-Encoding: 7bit + + + + + + + + +
+
+
+
Sorry, I meant 30,000 with 300 connections - not 3,000.  The 300
+connections
+/ second is realistic, if not underestimated.  As is the nature of
+our site
+(realtime information about online gaming), there's a huge fan base
+and as a
+big upset happens, we'll do 50,000 page views in a span of 3-5
+minutes.
+    
+
+

+First, your posts show no evidences of the CS storm bug.
+
+Second, 300 *new* connections a second is a lot.   Each new connection
+requires a significant amount of both database and OS overhead.   This
+is why all the other web developers use a connection pool.
+
+  
+
+I would second this. You need to be running a connection pool and +probably multiple web servers in
+front of that. You are talking about a huge amount of connections in +that amount of time.
+
+Josh Drake
+
+
+
+
+
In fact, I wouldn't be surprised if your lockups are on the OS level,
+even; I don't recall that you cited what OS you're using, but I can
+imagine locking up Linux 2.4 trying to spawn 300 new processes a
+second.
+
+--Josh
+
+---------------------------(end of broadcast)---------------------------
+TIP 8: explain analyze is your friend
+  
+
+
+
+
-- 
+Command Prompt, Inc., home of Mammoth PostgreSQL - S/ODBC and S/JDBC
+Postgresql support, programming shared hosting and dedicated hosting.
++1-503-667-4564 - jd@commandprompt.com - http://www.commandprompt.com
+PostgreSQL Replicator -- production quality replication for PostgreSQL
+ + + +--------------070605060102080306070907-- + +From pgsql-performance-owner@postgresql.org Fri Sep 24 02:24:17 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 83C62329CA4 + for ; + Fri, 24 Sep 2004 02:24:13 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 49505-05 + for ; + Fri, 24 Sep 2004 01:23:59 +0000 (GMT) +Received: from ms-smtp-02.nyroc.rr.com (ms-smtp-02.nyroc.rr.com [24.24.2.56]) + by svr1.postgresql.org (Postfix) with ESMTP id 6B636329C70 + for ; + Fri, 24 Sep 2004 02:24:00 +0100 (BST) +Received: from jcoene2 (roc-66-66-153-192.rochester.rr.com [66.66.153.192]) + by ms-smtp-02.nyroc.rr.com (8.12.10/8.12.10) with ESMTP id + i8O1NmaX011755; Thu, 23 Sep 2004 21:23:49 -0400 (EDT) +Message-Id: <200409240123.i8O1NmaX011755@ms-smtp-02.nyroc.rr.com> +From: "Jason Coene" +To: "'Josh Berkus'" , + +Cc: , +Subject: Re: Caching of Queries (now with pgpool) +Date: Thu, 23 Sep 2004 21:23:51 -0400 +MIME-Version: 1.0 +Content-Type: multipart/mixed; + boundary="----=_NextPart_000_0000_01C4A1B3.9FF5CAC0" +X-Mailer: Microsoft Office Outlook, Build 11.0.5510 +In-Reply-To: +Thread-Index: AcShymQ2XAMLJ5HFSJGIwJ7Anb68agAB16Rw +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 +X-Virus-Scanned: Symantec AntiVirus Scan Engine +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 + tests=LINES_OF_YELLING +X-Spam-Level: +X-Archive-Number: 200409/264 +X-Sequence-Number: 8392 + +This is a multi-part message in MIME format. + +------=_NextPart_000_0000_01C4A1B3.9FF5CAC0 +Content-Type: text/plain; + charset="us-ascii" +Content-Transfer-Encoding: 7bit + +Hi Josh, + +I just tried using pgpool to pool the connections, and ran: + +ab -n 1000 -c 50 http://wstg.int/portal/news/ + +I ran some previous queries to get pgpool to pre-establish all the +connections, and ab ran for a few minutes (with one query per page, eek!). +It was still exhibiting the same problems as before. While so many new +connections at once can surely make the problem worse (and pgpool will +surely help there), shouldn't this prove that it's not the only issue? + +We're running FreeBSD 5.2.1 + +I've attached open locks, running queries, query plans, top output and +vmstat 5 output for while ab was running, from start to finish. + +Any ideas? + +Jason + + +> -----Original Message----- +> From: pgsql-performance-owner@postgresql.org [mailto:pgsql-performance- +> owner@postgresql.org] On Behalf Of Josh Berkus +> Sent: Thursday, September 23, 2004 8:06 PM +> To: Jason Coene; pgsql-performance@postgresql.org +> Cc: mendola@bigfoot.com; tgl@sss.pgh.pa.us; josh@agliodbs.com +> Subject: Re: [PERFORM] Caching of Queries +> +> Jason, +> +> > Sorry, I meant 30,000 with 300 connections - not 3,000. The 300 +> > connections +> > / second is realistic, if not underestimated. As is the nature of +> > our site +> > (realtime information about online gaming), there's a huge fan base +> > and as a +> > big upset happens, we'll do 50,000 page views in a span of 3-5 +> > minutes. +> +> First, your posts show no evidences of the CS storm bug. +> +> Second, 300 *new* connections a second is a lot. Each new connection +> requires a significant amount of both database and OS overhead. This +> is why all the other web developers use a connection pool. +> +> In fact, I wouldn't be surprised if your lockups are on the OS level, +> even; I don't recall that you cited what OS you're using, but I can +> imagine locking up Linux 2.4 trying to spawn 300 new processes a +> second. +> +> --Josh +> +> ---------------------------(end of broadcast)--------------------------- +> TIP 8: explain analyze is your friend + +------=_NextPart_000_0000_01C4A1B3.9FF5CAC0 +Content-Type: text/plain; + name="ab_50conn_withpgpool.txt" +Content-Transfer-Encoding: quoted-printable +Content-Disposition: attachment; + filename="ab_50conn_withpgpool.txt" + +OPEN LOCKS: + + +gf=3D# SELECT r.relname, l."mode", count(*) AS numlocks + FROM pg_locks l, pg_class r + WHERE r.oid =3D l.relation + GROUP BY r.relname, l."mode" + ORDER BY count(*) DESC; + + relname | mode | numlocks +----------------------------------+---------------------------- + threads | AccessShareLock | 43 + threads_ix_nuked_lastpost | AccessShareLock | 35 + threads_ix_nuked_gameid_lastpost | AccessShareLock | 7 + pg_attribute | AccessShareLock | 1 + v_locks | AccessShareLock | 1 + pg_class | AccessShareLock | 1 + usersessions | AccessShareLock | 1 + countries | AccessShareLock | 1 + users | AccessShareLock | 1 + userstats_ix_id | AccessShareLock | 1 + pg_statistic_relid_att_index | AccessShareLock | 1 + pg_attribute_relid_attnum_index | AccessShareLock | 1 + userstats | AccessShareLock | 1 + demos | AccessShareLock | 1 + pg_cast_source_target_index | AccessShareLock | 1 + pg_locks | AccessShareLock | 1 + users_ix_id | AccessShareLock | 1 + buddies | AccessShareLock | 1 + buddies_ix_userid | AccessShareLock | 1 + pg_cast | AccessShareLock | 1 + pg_statistic | AccessShareLock | 1 +(21 rows) + +RUNNING QUERIES (AND HOW LONG FOR): + +gf=3D# SELECT pg_stat_activity.usename, round(date_part('epoch'::text, now(= +) - pg_stat_activity.query_start)) AS duration, pg_stat_activity.current_qu= +ery + FROM pg_stat_activity + ORDER BY round(date_part('epoch'::text, now() - pg_stat_activity.query_st= +art)) DESC; + + usename | duration | + current_query + + +---------+----------+------------------------------------------------------= +----- +---------------------------------------------------------------------------= +----- +---------------------------------------------------------------------------= +----- +-------------------------------------- + gf | 4 | SELECT id, gameid, forumid, subject FROM threads WHER= +E nuked =3D 0 AND gameid =3D 1 ORDER BY nuked DESC, gameid DESC, lastpost D= +ESC LIMIT 8 + gf | 3 | SELECT id, gameid, forumid, subject FROM threads WHER= +E nuked =3D 0 ORDER BY nuked DESC, lastpost DESC LIMIT 8 + gf | 3 | SELECT id, gameid, forumid, subject FROM threads WHER= +E nuked =3D 0 ORDER BY nuked DESC, lastpost DESC LIMIT 8 + gf | 3 | SELECT id, gameid, forumid, subject FROM threads WHER= +E nuked =3D 0 ORDER BY nuked DESC, lastpost DESC LIMIT 8 + gf | 3 | + gf | 3 | SELECT id, gameid, forumid, subject FROM threads WHER= +E nuked =3D 0 ORDER BY nuked DESC, lastpost DESC LIMIT 8 + gf | 3 | SELECT id, gameid, forumid, subject FROM threads WHER= +E nuked =3D 0 ORDER BY nuked DESC, lastpost DESC LIMIT 8 + gf | 2 | SELECT id, gameid, forumid, subject FROM threads WHER= +E nuked =3D 0 AND gameid =3D 3 ORDER BY nuked DESC, gameid DESC, lastpost D= +ESC LIMIT 8 + gf | 2 | SELECT id, gameid, forumid, subject FROM threads WHER= +E nuked =3D 0 ORDER BY nuked DESC, lastpost DESC LIMIT 8 + gf | 2 | SELECT id, gameid, forumid, subject FROM threads WHER= +E nuked =3D 0 ORDER BY nuked DESC, lastpost DESC LIMIT 8 + gf | 2 | SELECT id, gameid, forumid, subject FROM threads WHER= +E nuked =3D 0 ORDER BY nuked DESC, lastpost DESC LIMIT 8 + gf | 2 | SELECT id, gameid, forumid, subject FROM threads WHER= +E nuked =3D 0 AND gameid =3D 7 ORDER BY nuked DESC, gameid DESC, lastpost D= +ESC LIMIT 8 + gf | 2 | SELECT id, gameid, forumid, subject FROM threads WHER= +E nuked =3D 0 ORDER BY nuked DESC, lastpost DESC LIMIT 8 + gf | 2 | SELECT id, gameid, forumid, subject FROM threads WHER= +E nuked =3D 0 ORDER BY nuked DESC, lastpost DESC LIMIT 8 + gf | 2 | SELECT id, gameid, forumid, subject FROM threads WHER= +E nuked =3D 0 ORDER BY nuked DESC, lastpost DESC LIMIT 8 + gf | 2 | SELECT id, gameid, forumid, subject FROM threads WHER= +E nuked =3D 0 ORDER BY nuked DESC, lastpost DESC LIMIT 8 + gf | 2 | SELECT id, gameid, forumid, subject FROM threads WHER= +E nuked =3D 0 ORDER BY nuked DESC, lastpost DESC LIMIT 8 + gf | 2 | SELECT id, gameid, forumid, subject FROM threads WHER= +E nuked =3D 0 ORDER BY nuked DESC, lastpost DESC LIMIT 8 + gf | 1 | SELECT id, gameid, forumid, subject FROM threads WHER= +E nuked =3D 0 ORDER BY nuked DESC, lastpost DESC LIMIT 8 + gf | 1 | SELECT id, gameid, forumid, subject FROM threads WHER= +E nuked =3D 0 ORDER BY nuked DESC, lastpost DESC LIMIT 8 + gf | 1 | SELECT id, gameid, forumid, subject FROM threads WHER= +E nuked =3D 0 ORDER BY nuked DESC, lastpost DESC LIMIT 8 + gf | 1 | SELECT id, gameid, forumid, subject FROM threads WHER= +E nuked =3D 0 ORDER BY nuked DESC, lastpost DESC LIMIT 8 + gf | 1 | SELECT id, gameid, forumid, subject FROM threads WHER= +E nuked =3D 0 ORDER BY nuked DESC, lastpost DESC LIMIT 8 + gf | 1 | SELECT id, gameid, forumid, subject FROM threads WHER= +E nuked =3D 0 ORDER BY nuked DESC, lastpost DESC LIMIT 8 + gf | 1 | SELECT id, gameid, forumid, subject FROM threads WHER= +E nuked =3D 0 AND gameid =3D 2 ORDER BY nuked DESC, gameid DESC, lastpost D= +ESC LIMIT 8 + gf | 1 | SELECT id, gameid, forumid, subject FROM threads WHER= +E nuked =3D 0 ORDER BY nuked DESC, lastpost DESC LIMIT 8 + gf | 1 | SELECT id, gameid, forumid, subject FROM threads WHER= +E nuked =3D 0 ORDER BY nuked DESC, lastpost DESC LIMIT 8 + gf | 1 | SELECT id, gameid, forumid, subject FROM threads WHER= +E nuked =3D 0 ORDER BY nuked DESC, lastpost DESC LIMIT 8 + gf | 1 | SELECT id, gameid, forumid, subject FROM threads WHER= +E nuked =3D 0 ORDER BY nuked DESC, lastpost DESC LIMIT 8 + gf | 1 | SELECT id, gameid, forumid, subject FROM threads WHER= +E nuked =3D 0 ORDER BY nuked DESC, lastpost DESC LIMIT 8 + gf | 1 | SELECT id, gameid, forumid, subject FROM threads WHER= +E nuked =3D 0 AND gameid =3D 2 ORDER BY nuked DESC, gameid DESC, lastpost D= +ESC LIMIT 8 + gf | 1 | SELECT id, gameid, forumid, subject FROM threads WHER= +E nuked =3D 0 AND gameid =3D 2 ORDER BY nuked DESC, gameid DESC, lastpost D= +ESC LIMIT 8 + gf | 0 | + gf | 0 | SELECT id, gameid, forumid, subject FROM threads WHER= +E nuked =3D 0 ORDER BY nuked DESC, lastpost DESC LIMIT 8 + gf | 0 | + gf | 0 | SELECT id, gameid, forumid, subject FROM threads WHER= +E nuked =3D 0 ORDER BY nuked DESC, lastpost DESC LIMIT 8 + gf | 0 | SELECT id, gameid, forumid, subject FROM threads WHER= +E nuked =3D 0 ORDER BY nuked DESC, lastpost DESC LIMIT 8 + gf | 0 | SELECT id, gameid, forumid, subject FROM threads WHER= +E nuked =3D 0 AND gameid =3D 2 ORDER BY nuked DESC, gameid DESC, lastpost D= +ESC LIMIT 8 + gf | 0 | + gf | 0 | SELECT id, gameid, forumid, subject FROM threads WHER= +E nuked =3D 0 ORDER BY nuked DESC, lastpost DESC LIMIT 8 + gf | 0 | SELECT id, gameid, forumid, subject FROM threads WHER= +E nuked =3D 0 ORDER BY nuked DESC, lastpost DESC LIMIT 8 + gf | 0 | SELECT id, gameid, forumid, subject FROM threads WHER= +E nuked =3D 0 ORDER BY nuked DESC, lastpost DESC LIMIT 8 + gf | 0 | + gf | 0 | + gf | 0 | +(46 rows) + +QUERY PLAN: + +gf-# SELECT id, gameid, forumid, subject FROM threads WHERE nuked =3D 0 ORD= +ER BY nuked DESC, lastpost DESC LIMIT 8; + QU= +ERY PLAN +---------------------------------------------------------------------------= +---------------------------------------------------------------------------= +------- + Limit (cost=3D0.00..1.99 rows=3D8 width=3D39) (actual time=3D32.174..32.3= +36 rows=3D8 loops=3D1) + -> Index Scan Backward using threads_ix_nuked_lastpost on threads (cos= +t=3D0.00..16824.36 rows=3D67511 width=3D39) (actual time=3D32.164..32.298 r= +ows=3D8 loops=3D1) + Filter: (nuked =3D 0) + Total runtime: 32.446 ms +(4 rows) + +VMSTAT 5 + +d01.int> vmstat 5 + procs memory page disks faults cpu + r b w avm fre flt re pi po fr sr da0 fd0 in sy cs us sy = +id + 2 0 0 211536 691068 2449 0 0 0 1693 1 0 0 724 0 482 5 3= + 91 + 0 0 2 213688 689700 9772 0 0 0 2221 0 32 0 895 0 3376 7 = +4 89 + 0 1 2 212900 690588 12264 0 0 0 3233 0 3 0 997 0 9096 9 = + 7 84 + 0 0 0 207552 693696 11579 0 0 0 2749 0 47 0 1030 0 9517 8 = + 7 85 + 2 0 0 212688 690580 9031 0 0 0 2150 0 6 0 839 0 3206 6 = +4 90 + 0 0 0 209172 692644 10863 0 0 0 2789 0 8 0 933 0 5356 8 = + 5 87 + 1 0 0 213060 690040 12255 0 0 0 3213 0 12 0 1154 0 6508 9 = + 5 86 + 0 0 0 207552 693640 12229 0 0 0 2169 0 28 0 861 0 5764 7 = + 6 87 + 2 0 0 211632 690812 7772 0 0 0 1963 0 5 0 786 0 2787 5 = +4 91 + 0 0 1 211432 691160 12525 0 0 0 2881 0 15 0 1003 0 4029 8 = + 5 87 + 0 0 0 208320 693168 9280 0 0 0 2262 0 2 0 832 0 3390 7 = +5 89 + 5 7 0 231384 679220 15424 0 0 0 2408 0 7 0 1035 0 7909 10 = + 7 83 +begin AB + 0 50 5 298548 637676 16323 0 0 0 1123 0 2 0 1341 0 50716 1= +8 14 68 + 0 43 6 290120 641824 10121 0 0 0 2464 0 3 0 1254 0 66648 1= +8 16 65 + 5 40 1 279568 649060 5221 0 0 0 1790 0 29 0 1273 0 102972 2= +1 23 56 + 2 35 11 281128 647952 8595 0 0 0 1894 0 10 0 1461 0 65727 2= +0 15 65 + 1 12 14 264744 658852 7410 0 0 0 2058 0 1 0 1347 0 67184 2= +1 16 63 + 0 2 5 258092 662808 9405 0 0 0 2667 0 7 0 1543 0 43952 20 = +12 68 + 5 3 0 268944 656192 9765 0 0 0 1905 0 7 0 1479 0 37269 21 = +10 70 + 4 8 3 268076 656292 9561 0 0 0 2223 0 6 0 1485 0 29425 18 = + 8 73 + 0 45 3 287296 643892 10656 0 0 0 1914 0 24 0 1542 0 58277 2= +3 13 65 + 5 41 0 283708 646428 9064 0 0 0 2218 0 12 0 1447 0 64764 20= + 15 65 + 0 49 4 296012 638116 10023 0 0 0 2314 0 8 0 1397 0 64031 1= +9 17 64 + 5 36 3 299804 635440 9287 0 0 0 2048 0 3 0 1177 0 81789 19= + 20 61 +end AB + 0 1 1 260944 660812 13731 0 0 0 3377 0 11 0 999 0 11240 9= + 8 83 + 0 0 0 256324 663836 8794 0 0 0 2318 0 2 0 796 0 3622 6 = +4 90 + 1 0 0 256956 663632 7928 0 0 0 1941 0 37 0 853 0 2717 5 = +3 91 + 0 0 0 256176 664044 9236 0 0 0 2159 0 5 0 847 0 2620 6 = +4 90 + 0 0 3 257784 663008 10665 0 0 0 2521 0 4 0 844 0 4582 7 = + 6 87 + 0 0 0 254572 665016 16023 0 0 0 2689 0 10 0 1027 0 9869 8 = + 8 84 + +TOP: + + +last pid: 97030; load averages: 5.33, 2.30, 1.55 up 20+04:55:04= + 21:15:12 +118 processes: 4 running, 110 sleeping, 4 lock +CPU states: 19.4% user, 0.0% nice, 13.2% system, 0.8% interrupt, 66.7% id= +le +Mem: 86M Active, 1008M Inact, 204M Wired, 59M Cache, 112M Buf, 566M Free +Swap: 4096M Total, 4096M Free + + PID USERNAME PRI NICE SIZE RES STATE C TIME WCPU CPU COMMAND +96626 pgsql -4 0 96048K 21076K semwai 0 0:02 2.19% 2.05% postgres +96649 pgsql -4 0 96048K 21076K semwai 3 0:01 2.15% 2.00% postgres +96638 pgsql -4 0 96048K 21076K semwai 0 0:02 2.09% 1.95% postgres +96627 pgsql 4 0 96048K 21076K sbwait 0 0:02 2.09% 1.95% postgres +96635 pgsql -4 0 96048K 21076K semwai 0 0:01 1.88% 1.76% postgres +96647 pgsql -4 0 96048K 21076K semwai 1 0:01 1.88% 1.76% postgres +96652 pgsql -4 0 96048K 21076K semwai 0 0:02 1.73% 1.61% postgres +96640 pgsql -4 0 96048K 21144K semwai 3 0:02 1.73% 1.61% postgres +95637 pgsql -4 0 96240K 31868K semwai 1 0:02 1.61% 1.61% postgres +96637 pgsql -4 0 96048K 21076K semwai 1 0:01 1.73% 1.61% postgres +96645 pgsql -4 0 96048K 21076K semwai 0 0:02 1.67% 1.56% postgres +96630 pgsql -4 0 96048K 21076K semwai 3 0:01 1.67% 1.56% postgres +95549 pgsql -4 0 96240K 32364K semwai 0 0:02 1.51% 1.51% postgres +96629 pgsql -4 0 96048K 21076K semwai 0 0:01 1.62% 1.51% postgres +96648 pgsql -4 0 96048K 21076K semwai 0 0:01 1.62% 1.51% postgres +96661 pgsql -4 0 96048K 21076K semwai 1 0:01 1.57% 1.46% postgres +96644 pgsql -4 0 96048K 21076K semwai 3 0:01 1.57% 1.46% postgres +96653 pgsql 4 0 96048K 21076K sbwait 0 0:01 1.47% 1.37% postgres +96651 pgsql -4 0 96048K 21076K semwai 3 0:02 1.41% 1.32% postgres +96657 pgsql -4 0 96048K 21076K semwai 0 0:01 1.41% 1.32% postgres +96646 pgsql -4 0 96048K 21076K semwai 0 0:01 1.36% 1.27% postgres +96643 pgsql -4 0 96048K 21076K semwai 3 0:01 1.36% 1.27% postgres +96654 pgsql -4 0 96048K 21076K semwai 3 0:01 1.36% 1.27% postgres +96632 pgsql -4 0 96048K 21076K semwai 1 0:01 1.30% 1.22% postgres +96659 pgsql -4 0 96048K 21076K semwai 0 0:01 1.20% 1.12% postgres +96655 pgsql -4 0 96048K 21076K semwai 1 0:01 1.15% 1.07% postgres +96660 pgsql -4 0 96048K 21076K semwai 3 0:01 1.10% 1.03% postgres +96636 pgsql -4 0 96048K 21076K semwai 1 0:01 1.04% 0.98% postgres +96650 pgsql -4 0 96048K 21076K semwai 0 0:01 1.05% 0.98% postgres +96656 pgsql -4 0 96048K 21076K semwai 3 0:01 1.05% 0.98% postgres +96658 pgsql -4 0 96048K 21076K semwai 0 0:01 0.99% 0.93% postgres +96631 pgsql -4 0 96048K 21076K semwai 0 0:01 0.99% 0.93% postgres +97004 pgsql -4 0 96356K 41576K semwai 3 0:00 3.50% 0.49% postgres +97009 pgsql -4 0 97028K 24004K semwai 3 0:00 2.56% 0.24% postgres + +------=_NextPart_000_0000_01C4A1B3.9FF5CAC0-- + + +From pgsql-performance-owner@postgresql.org Fri Sep 24 03:02:05 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id A9AD7329E3C + for ; + Fri, 24 Sep 2004 03:01:14 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 57665-07 + for ; + Fri, 24 Sep 2004 02:00:59 +0000 (GMT) +Received: from mail1.panix.com (mail1.panix.com [166.84.1.72]) + by svr1.postgresql.org (Postfix) with ESMTP id B7008329E4B + for ; + Fri, 24 Sep 2004 03:01:01 +0100 (BST) +Received: from panix2.panix.com (panix2.panix.com [166.84.1.2]) + by mail1.panix.com (Postfix) with ESMTP id 84DA748703; + Thu, 23 Sep 2004 22:00:59 -0400 (EDT) +Received: (from adler@localhost) + by panix2.panix.com (8.11.6p2-a/8.8.8/PanixN1.1) id i8O20xN02483; + Thu, 23 Sep 2004 22:00:59 -0400 (EDT) +Date: Thu, 23 Sep 2004 22:00:59 -0400 +From: Michael Adler +To: Jason Coene +Cc: "'Josh Berkus'" , + pgsql-performance@postgresql.org, mendola@bigfoot.com, tgl@sss.pgh.pa.us +Subject: Re: Caching of Queries (now with pgpool) +Message-ID: <20040924020058.GA11703@pobox.com> +References: + <200409240123.i8O1NmaX011755@ms-smtp-02.nyroc.rr.com> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <200409240123.i8O1NmaX011755@ms-smtp-02.nyroc.rr.com> +User-Agent: Mutt/1.4.2.1i +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/265 +X-Sequence-Number: 8393 + +On Thu, Sep 23, 2004 at 09:23:51PM -0400, Jason Coene wrote: +> I ran some previous queries to get pgpool to pre-establish all the +> connections, and ab ran for a few minutes (with one query per page, eek!). +> It was still exhibiting the same problems as before. While so many new +> connections at once can surely make the problem worse (and pgpool will +> surely help there), shouldn't this prove that it's not the only issue? + +> Any ideas? + +Now that your connections are persistent, you may benefit from using +PREPAREd queries. + +-Mike + +From pgsql-performance-owner@postgresql.org Fri Sep 24 16:07:16 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 59655329C6B + for ; + Fri, 24 Sep 2004 16:07:13 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 95827-10 + for ; + Fri, 24 Sep 2004 15:07:11 +0000 (GMT) +Received: from mail.osdl.org (fw.osdl.org [65.172.181.6]) + by svr1.postgresql.org (Postfix) with ESMTP id C5271329C65 + for ; + Fri, 24 Sep 2004 16:07:09 +0100 (BST) +Received: (from markw@localhost) + by mail.osdl.org (8.11.6/8.11.6) id i8OF73u28616; + Fri, 24 Sep 2004 08:07:03 -0700 +Date: Fri, 24 Sep 2004 08:07:03 -0700 +From: Mark Wong +To: Guy Thornley +Cc: pgsql-performance@postgresql.org +Subject: Re: O_DIRECT setting +Message-ID: <20040924080703.A27640@osdl.org> +References: <20040920075734.GK21733@conker.esphion.com> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +User-Agent: Mutt/1.2.5i +In-Reply-To: <20040920075734.GK21733@conker.esphion.com>; + from guy@esphion.com on Mon, Sep 20, 2004 at 07:57:34PM +1200 +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/266 +X-Sequence-Number: 8394 + +On Mon, Sep 20, 2004 at 07:57:34PM +1200, Guy Thornley wrote: +[snip] +> +> Incidentally, postgres heap files suffer really, really bad fragmentation, +> which affects sequential scan operations (VACUUM, ANALYZE, REINDEX ...) +> quite drastically. We have in-house patches that somewhat alleiviate this, +> but they are not release quality. Has anybody else suffered this? +> + +Any chance I could give those patches a try? I'm interested in seeing +how they may affect our DBT-3 workload, which execute DSS type queries. + +Thanks, +Mark + +From pgsql-performance-owner@postgresql.org Fri Sep 24 20:23:12 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 0E436329E91 + for ; + Fri, 24 Sep 2004 20:23:08 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 89305-06 + for ; + Fri, 24 Sep 2004 19:23:05 +0000 (GMT) +Received: from leo.supplyfx.com (h-67-100-199-42.lsanca54.covad.net + [67.100.199.42]) + by svr1.postgresql.org (Postfix) with ESMTP id 59A8C329E82 + for ; + Fri, 24 Sep 2004 20:23:05 +0100 (BST) +Received: from [10.0.100.21] (leo6.supplyfx.com [10.0.100.21]) + by leo.supplyfx.com (Postfix) with ESMTP + id 37EE83A80E8; Fri, 24 Sep 2004 12:23:04 -0700 (PDT) +Mime-Version: 1.0 (Apple Message framework v619) +Content-Type: text/plain; charset=US-ASCII; format=flowed +Message-Id: <27CAD89B-0E5F-11D9-8B00-000A95AB8896@supplyfx.com> +Content-Transfer-Encoding: 7bit +Cc: Kai Mildenberger , + Partha Roy +From: Qing Zhao +Subject: performance of PostgreSQL on 64 bit MAC OS X G5! +Date: Fri, 24 Sep 2004 12:23:03 -0700 +To: 'Postgresql Performance' +X-Mailer: Apple Mail (2.619) +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/267 +X-Sequence-Number: 8395 + +Hi, + +We have been running PostgreSQL 7.3.4 on 64 bit MAC OS X G5 dual +processors with 8GB of RAM for a while. +Lately, we realized that consistently only about 4GB of RAM is used +even when CPUs have maxed out +for postgtres processes and pageouts starts to happen. Here is a +portion of the output from TOP: + +MemRegions: num = 3761, resident = 41.5M + 7.61M private, 376M shared +PhysMem: 322M wired, 1.83G active, 1.41G inactive, 3.56G used, 4.44G +free +VM: 14.0G + 69.9M 277034(0) pageins, 1461(0) pageouts + +Is it because PostgreSQL 7.3.4 can't take advantage of the 64 bit +hardware or is it something else? + +Thanks a lot! + +Qing + + +From pgsql-performance-owner@postgresql.org Sat Sep 25 01:58:03 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 2D6A4329C67 + for ; + Sat, 25 Sep 2004 01:57:23 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 79823-10 + for ; + Sat, 25 Sep 2004 00:57:16 +0000 (GMT) +Received: from tht.net (vista.tht.net [216.126.88.2]) + by svr1.postgresql.org (Postfix) with ESMTP id 8683A329E66 + for ; + Sat, 25 Sep 2004 01:57:18 +0100 (BST) +Received: from [134.22.69.205] (dyn-69-205.tor.dsl.tht.net [134.22.69.205]) + by tht.net (Postfix) with ESMTP id CE4D276A11 + for ; + Fri, 24 Sep 2004 20:57:18 -0400 (EDT) +Subject: Getting rid of nested loop +From: Rod Taylor +To: Postgresql Performance +Content-Type: text/plain +Message-Id: <1096073834.40463.41.camel@jester> +Mime-Version: 1.0 +X-Mailer: Ximian Evolution 1.4.6 +Date: Fri, 24 Sep 2004 20:57:15 -0400 +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/268 +X-Sequence-Number: 8396 + +I set nested_loop = off, which is why I have the high cost. + +@ is a postgis operator between 2 geomotries (both polygons). It's the @ +operator which is expensive. Is there a way to force a cheaper way of +doing that join? + + -> Nested Loop (cost=100001905.94..100001906.08 rows=1 +width=68) (actual time=1739.368..17047.422 rows=100 loops=1) + Join Filter: ((COALESCE("outer".geom, "outer".geom) @ +COALESCE("inner".geom, "inner".geom)) AND ("outer".region_id <> +"inner".region_id)) + + + +From pgsql-performance-owner@postgresql.org Sat Sep 25 17:58:48 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 273BD329E47 + for ; + Sat, 25 Sep 2004 17:58:46 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 71048-01 + for ; + Sat, 25 Sep 2004 16:58:41 +0000 (GMT) +Received: from pns.mm.eutelsat.org (pns.mm.eutelsat.org [194.214.173.227]) + by svr1.postgresql.org (Postfix) with ESMTP id EAB73329D87 + for ; + Sat, 25 Sep 2004 17:58:40 +0100 (BST) +Received: from nts-03.mm.eutelsat.org (localhost [127.0.0.1]) + by pns.mm.eutelsat.org (8.11.6/linuxconf) with ESMTP id i8PGurD21582; + Sat, 25 Sep 2004 18:56:55 +0200 +Received: from [127.0.0.1] (accesspoint.mm.eutelsat.org [194.214.173.4]) + by nts-03.mm.eutelsat.org (8.11.6/linuxconf) with ESMTP id i8PGwMV11809; + Sat, 25 Sep 2004 18:58:22 +0200 +Message-ID: <4155A3A1.7050905@bigfoot.com> +Date: Sat, 25 Sep 2004 18:58:09 +0200 +From: Gaetano Mendola +User-Agent: Mozilla Thunderbird 0.8 (Windows/20040913) +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: "Joshua D. Drake" +Cc: Josh Berkus , + Jason Coene , pgsql-performance@postgresql.org, + tgl@sss.pgh.pa.us +Subject: Re: Caching of Queries +References: + <41536C4A.2010702@commandprompt.com> +In-Reply-To: <41536C4A.2010702@commandprompt.com> +X-Enigmail-Version: 0.86.1.0 +X-Enigmail-Supports: pgp-inline, pgp-mime +Content-Type: text/plain; charset=ISO-8859-1; format=flowed +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/269 +X-Sequence-Number: 8397 + +-----BEGIN PGP SIGNED MESSAGE----- +Hash: SHA1 + +Joshua D. Drake wrote: +| +|>>Sorry, I meant 30,000 with 300 connections - not 3,000. The 300 +|>>connections +|>>/ second is realistic, if not underestimated. As is the nature of +|>>our site +|>>(realtime information about online gaming), there's a huge fan base +|>>and as a +|>>big upset happens, we'll do 50,000 page views in a span of 3-5 +|>>minutes. +|>> +|>> +|> +|>First, your posts show no evidences of the CS storm bug. +|> +|>Second, 300 *new* connections a second is a lot. Each new connection +|>requires a significant amount of both database and OS overhead. This +|>is why all the other web developers use a connection pool. +|> +|> +|> +| I would second this. You need to be running a connection pool and +| probably multiple web servers in +| front of that. You are talking about a huge amount of connections in +| that amount of time. +| +| Josh Drake +| +| +| +|>In fact, I wouldn't be surprised if your lockups are on the OS level, +|>even; I don't recall that you cited what OS you're using, but I can +|>imagine locking up Linux 2.4 trying to spawn 300 new processes a +|>second. + +Not to mention that a proxy squid mounted in reverse proxy mode will +help a lot. + + +Regards +Gaetano Mendola + + + + + + +-----BEGIN PGP SIGNATURE----- +Version: GnuPG v1.2.5 (MingW32) +Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org + +iD8DBQFBVaOg7UpzwH2SGd4RAnW4AJ9TYV0oSjYcv8Oxt4Ot/T/nJikoRgCg1Egx +r4KKm14ziu/KWFb3SnTK/U8= +=xgmw +-----END PGP SIGNATURE----- + + +From pgsql-performance-owner@postgresql.org Sat Sep 25 18:27:44 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 42A05329E66 + for ; + Sat, 25 Sep 2004 18:27:40 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 75177-05 + for ; + Sat, 25 Sep 2004 17:27:35 +0000 (GMT) +Received: from pns.mm.eutelsat.org (pns.mm.eutelsat.org [194.214.173.227]) + by svr1.postgresql.org (Postfix) with ESMTP id DABC6329DFC + for ; + Sat, 25 Sep 2004 18:27:35 +0100 (BST) +Received: from nts-03.mm.eutelsat.org (localhost [127.0.0.1]) + by pns.mm.eutelsat.org (8.11.6/linuxconf) with ESMTP id i8PHPwF21698; + Sat, 25 Sep 2004 19:25:58 +0200 +Received: from [127.0.0.1] (accesspoint.mm.eutelsat.org [194.214.173.4]) + by nts-03.mm.eutelsat.org (8.11.6/linuxconf) with ESMTP id i8PHQkV11949; + Sat, 25 Sep 2004 19:26:59 +0200 +Message-ID: <4155A9F4.1010807@bigfoot.com> +Date: Sat, 25 Sep 2004 19:25:08 +0200 +From: Gaetano Mendola +User-Agent: Mozilla Thunderbird 0.8 (Windows/20040913) +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: Michael Adler +Cc: Jason Coene , "'Josh Berkus'" , + pgsql-performance@postgresql.org, tgl@sss.pgh.pa.us +Subject: Re: Caching of Queries (now with pgpool) +References: + <200409240123.i8O1NmaX011755@ms-smtp-02.nyroc.rr.com> + <20040924020058.GA11703@pobox.com> +In-Reply-To: <20040924020058.GA11703@pobox.com> +X-Enigmail-Version: 0.86.1.0 +X-Enigmail-Supports: pgp-inline, pgp-mime +Content-Type: text/plain; charset=ISO-8859-1; format=flowed +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/270 +X-Sequence-Number: 8398 + +-----BEGIN PGP SIGNED MESSAGE----- +Hash: SHA1 + +Michael Adler wrote: +| On Thu, Sep 23, 2004 at 09:23:51PM -0400, Jason Coene wrote: +| +|>I ran some previous queries to get pgpool to pre-establish all the +|>connections, and ab ran for a few minutes (with one query per page, eek!). +|>It was still exhibiting the same problems as before. While so many new +|>connections at once can surely make the problem worse (and pgpool will +|>surely help there), shouldn't this prove that it's not the only issue? +| +| +|>Any ideas? +| +| +| Now that your connections are persistent, you may benefit from using +| PREPAREd queries. +| +| -Mike + +With his load will not change anything. + + +Regards +Gaetano Mendola + + + +-----BEGIN PGP SIGNATURE----- +Version: GnuPG v1.2.5 (MingW32) +Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org + +iD8DBQFBVany7UpzwH2SGd4RAj9UAJ0SO3VE7zMbwrgdwPQc+HP5PHClMACgtTvn +KIp1TK2lVbmXZ+s62fpJ46U= +=sjT0 +-----END PGP SIGNATURE----- + + +From pgsql-hackers-win32-owner@postgresql.org Sat Sep 25 20:39:12 2004 +X-Original-To: pgsql-hackers-win32-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 311D3329CB0 + for ; + Sat, 25 Sep 2004 20:39:10 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 03693-07 + for ; + Sat, 25 Sep 2004 19:39:03 +0000 (GMT) +Received: from trolak.mydnsbox2.com (ns1.mydnsbox2.com [207.44.142.118]) + by svr1.postgresql.org (Postfix) with ESMTP id 82934329C63 + for ; + Sat, 25 Sep 2004 20:39:03 +0100 (BST) +Received: from dunslane.net (cpe-024-211-141-025.nc.rr.com [24.211.141.25]) + (authenticated (0 bits)) + by trolak.mydnsbox2.com (8.11.6/8.11.6) with ESMTP id i8PJlJL10140 + for ; + Sat, 25 Sep 2004 14:47:19 -0500 +Message-ID: <4155C955.40808@dunslane.net> +Date: Sat, 25 Sep 2004 15:39:01 -0400 +From: Andrew Dunstan +User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040116 +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: pgsql-hackers-win32 +Subject: automated builds? +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/145 +X-Sequence-Number: 2275 + + +Is everyone still building interactively? I'm looking for nice ways to +automate building on Windows without any human action required, as part +of the buildfarm project. Ideas on how to do this nicely for Windows +would be appreciated. Can one run the MSys shell without it firing up an +emulated xterm? + +cheers + +andrew + +From pgsql-performance-owner@postgresql.org Sun Sep 26 02:29:46 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id D1530329E2C + for ; + Sun, 26 Sep 2004 02:28:36 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 70162-08 + for ; + Sun, 26 Sep 2004 01:28:29 +0000 (GMT) +Received: from candle.pha.pa.us (candle.pha.pa.us [207.106.42.251]) + by svr1.postgresql.org (Postfix) with ESMTP id CD698329D9F + for ; + Sun, 26 Sep 2004 02:28:30 +0100 (BST) +Received: (from pgman@localhost) + by candle.pha.pa.us (8.11.6/8.11.6) id i8Q1SII16060; + Sat, 25 Sep 2004 21:28:18 -0400 (EDT) +From: Bruce Momjian +Message-Id: <200409260128.i8Q1SII16060@candle.pha.pa.us> +Subject: Re: Cleaning up indexes +In-Reply-To: <0XH4d.41061$yW6.30251@clgrps12> +To: Martin Foster +Date: Sat, 25 Sep 2004 21:28:18 -0400 (EDT) +Cc: pgsql-performance@postgresql.org +X-Mailer: ELM [version 2.4ME+ PL108 (25)] +MIME-Version: 1.0 +Content-Transfer-Encoding: 7bit +Content-Type: text/plain; charset=US-ASCII +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/271 +X-Sequence-Number: 8399 + +Martin Foster wrote: +> My database was converted from MySQL a while back and has maintained all +> of the indexes which were previously used. Tt the time however, there +> were limitations on the way PostgreSQL handled the indexes compared to +> MySQL. +> +> Meaning that under MySQL, it would make use of a multi-column index even +> if the rows within did not match. When the conversion was made more +> indexes were created overall to correct this and proceed with the +> conversion. +> +> Now the time has come to clean up the used indexes. Essentially, I +> want to know if there is a way in which to determine which indexes are +> being used and which are not. This will allow me to drop off the +> unneeded ones and reduce database load as a result. + +Just for clarification, PostgreSQL will use an a,b,c index for a, (a,b), +and (a,b,c), but not for (a,c). Are you saying MySQL uses the index for +(a,c)? This item is on our TODO list: + + * Use index to restrict rows returned by multi-key index when used with + non-consecutive keys to reduce heap accesses + + For an index on col1,col2,col3, and a WHERE clause of col1 = 5 and + col3 = 9, spin though the index checking for col1 and col3 matches, + rather than just col1 + +> And have things changed as to allow for mismatched multi-column indexes +> in version 7.4.x or even the upcoming 8.0.x? + +As someone already pointed out, the pg_stat* tables will show you what +indexes are used. + +-- + Bruce Momjian | http://candle.pha.pa.us + pgman@candle.pha.pa.us | (610) 359-1001 + + If your life is a hard drive, | 13 Roberts Road + + Christ can be your backup. | Newtown Square, Pennsylvania 19073 + +From pgsql-performance-owner@postgresql.org Sun Sep 26 21:37:35 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 10820329C6B + for ; + Sun, 26 Sep 2004 21:37:34 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 85944-06 + for ; + Sun, 26 Sep 2004 20:37:28 +0000 (GMT) +Received: from mail.libertyrms.com (unknown [207.219.45.62]) + by svr1.postgresql.org (Postfix) with ESMTP id D8D61329D41 + for ; + Sun, 26 Sep 2004 21:37:28 +0100 (BST) +Received: from ahammond-vpn.int.libertyrms.com ([10.1.7.26]) + by mail.libertyrms.com with esmtp (Exim 4.22) + id 1CBflu-0002If-W8; Sun, 26 Sep 2004 16:37:27 -0400 +Message-ID: <41572881.1020406@ca.afilias.info> +Date: Sun, 26 Sep 2004 16:37:21 -0400 +From: Andrew Hammond +User-Agent: Mozilla Thunderbird 0.7.2 (Windows/20040707) +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: Anjan Dave +Cc: Mr Pink , + pgsql-performance@postgresql.org +Subject: Re: SAN performance +References: + <4BAFBB6B9CC46F41B2AD7D9F4BBAF78509853D@vt-pe2550-001.vantage.vantage.com> +In-Reply-To: + <4BAFBB6B9CC46F41B2AD7D9F4BBAF78509853D@vt-pe2550-001.vantage.vantage.com> +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit +X-SA-Exim-Mail-From: ahammond@ca.afilias.info +X-SA-Exim-Scanned: No; SAEximRunCond expanded to false +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/273 +X-Sequence-Number: 8401 + +I'm about to do a whole bunch of testing here on various DA element +sizes, and datablock sizes and how the affect pg performance. It doesn't +appear possible to get > 4kb filesystem blocks under linux due to the +limitation of the pagesize. We're running AMD64 for these tests, but the +DA configuration should be pretty much identical for IA32. + +My best guess right now is that recompiling pg with a 4kb datablock +size, and using 4kb filesystem blocks with an 8 sector (4kb) element +size is probably the way to go for an active database. + +Contact me off-list if you want a copy of the EMC CLARiiON "Best +Practices for Fiber Channel Storage" white paper. Haven't read it since +I only got my copy this morning, but... looks promising. + +Drew + + +Anjan Dave wrote: + +> I believe 1/0 or 1+0 is aka RAID-10. CX300 doesn't support 0+1. +> +> So far i am aware of two things, the cache page size is 8KB (can be increased or decreased), and the stripe element size of 128 sectors default. +> +> Thanks, +> Anjan +> +> -----Original Message----- +> From: Mr Pink [mailto:mr_pink_is_the_only_pro@yahoo.com] +> Sent: Thu 9/23/2004 11:39 AM +> To: Anjan Dave; pgsql-performance@postgresql.org +> Cc: +> Subject: Re: [PERFORM] SAN performance +> +> +> +> Hi, +> +> I expect you mean RAID 1/0 or 1+0 since the CX300 didn't support RAID 10 last time I looked. +> +> Whether you are using a SAN or not, you should consider putting the WAL files (pg_xlog folder) on +> seperate diskes from the DB. Since the log files are mostly written to, not read from you could +> just use RAID 1. +> +> It's a pity pg doesn't have a way to use a cluster of servers to get the most out of your +> expensive SAN. +> +> I read a comment earlier about setting block sizes to 8k to math pg's block size. Seems to make +> sense, you should check it out. +> +> Have fun, +> Mr Pink +> +> --- Anjan Dave wrote: +> +> > Hello, +> > +> > +> > +> > I'll be moving a DB from internal RAID-10 SCSI storage to an EMC CX300 +> > FC RAID-10 LUN, bound to the host. I've setup a test host machine and a +> > test LUN. The /var/lib/pgsql/data folder is sym-linked to a partition on +> > the LUN. +> > +> > +> > +> > Other than the shared_buffers, effective cache size, and sort memory, I +> > am not sure if I need to change any other parameters in the +> > postgresql.conf file for getting maximum performance from the EMC box. +> > +> > +> > +> > Is there a general guideline for setting up postgres database and the +> > tunable parameters on a SAN, especially for EMC? +> > +> > +> > +> > Appreciate any help, +> > +> > +> > +> > Thanks, +> > Anjan +> > +> > +> +> +> +> +> +> __________________________________ +> Do you Yahoo!? +> New and Improved Yahoo! Mail - 100MB free storage! +> http://promotions.yahoo.com/new_mail +> +> +> ---------------------------(end of broadcast)--------------------------- +> TIP 8: explain analyze is your friend + + +From pgsql-performance-owner@postgresql.org Mon Sep 27 01:15:36 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 07A59329DC4 + for ; + Mon, 27 Sep 2004 01:15:36 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 39073-03 + for ; + Mon, 27 Sep 2004 00:15:25 +0000 (GMT) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by svr1.postgresql.org (Postfix) with ESMTP id 3518D329E39 + for ; + Mon, 27 Sep 2004 01:15:27 +0100 (BST) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by news.hub.org (8.12.9/8.12.9) with ESMTP id i8R0FOfg039420 + for ; Mon, 27 Sep 2004 00:15:24 GMT + (envelope-from news@news.hub.org) +Received: (from news@localhost) + by news.hub.org (8.12.9/8.12.9/Submit) id i8QNnxLt034206 + for pgsql-performance@postgresql.org; Sun, 26 Sep 2004 23:49:59 GMT +From: Christopher Browne +X-Newsgroups: comp.databases.postgresql.performance +Subject: Re: performance of PostgreSQL on 64 bit MAC OS X G5! +Date: Sun, 26 Sep 2004 19:31:21 -0400 +Organization: cbbrowne Computing Inc +Lines: 25 +Message-ID: +References: <27CAD89B-0E5F-11D9-8B00-000A95AB8896@supplyfx.com> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Complaints-To: usenet@news.hub.org +X-message-flag: Outlook is rather hackable, isn't it? +X-Home-Page: http://www.cbbrowne.com/info/ +X-Affero: http://svcs.affero.net/rm.php?r=cbbrowne +User-Agent: Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.4 (Security Through + Obscurity, + linux) +Cancel-Lock: sha1:h/DBvSmnsBChljMSC2aGQW4ae8Y= +To: pgsql-performance@postgresql.org +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/274 +X-Sequence-Number: 8402 + +Oops! qzhao@supplyfx.com (Qing Zhao) was seen spray-painting on a wall: +> Is it because PostgreSQL 7.3.4 can't take advantage of the 64 bit +> hardware or is it something else? + +PostgreSQL has been able to take advantage of 64 bit hardware WHEN THE +OS SUPPORTS IT, for quite a few versions now. + +As far as I was aware, Mac OS-X was still deployed as a 32 bit +operating system. Apple's advertising material seems deliberately +ambiguous in this regard; it seems to imply there is no difference +between 32- and 64-bit applications. To wit: + + "... This means that 32-bit applications that run on Mac OS X today + will run natively on 64-bit PowerPC G5 Processor-based Macintosh + computers, without the need for recompiling or additional + optimizations." + +There are quite likely to be some additional "compiler incantations" +required in order to compile applications as 64 bit apps that will be +able to reference, internally, more than 4GB of RAM. +-- +wm(X,Y):-write(X),write('@'),write(Y). wm('cbbrowne','acm.org'). +http://www3.sympatico.ca/cbbrowne/sgml.html +Tell a man that there are 400 billion stars, and he'll believe you. +Tell him a bench has wet paint, and he has to touch it. + +From pgsql-performance-owner@postgresql.org Mon Sep 27 06:03:31 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 6DA15329DC4 + for ; + Mon, 27 Sep 2004 06:03:30 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 10252-03 + for ; + Mon, 27 Sep 2004 05:03:26 +0000 (GMT) +Received: from sue.samurai.com (sue.samurai.com [205.207.28.74]) + by svr1.postgresql.org (Postfix) with ESMTP id 97390329D83 + for ; + Mon, 27 Sep 2004 06:03:25 +0100 (BST) +Received: from localhost (localhost [127.0.0.1]) + by sue.samurai.com (Postfix) with ESMTP id 861803F2F; + Mon, 27 Sep 2004 01:03:25 -0400 (EDT) +Received: from sue.samurai.com ([127.0.0.1]) + by localhost (sue.samurai.com [127.0.0.1]) (amavisd-new, port 10024) + with LMTP id 71755-01-6; Mon, 27 Sep 2004 01:03:24 -0400 (EDT) +Received: from localhost (unknown [61.88.101.19]) + by sue.samurai.com (Postfix) with ESMTP id A68E53EFD; + Mon, 27 Sep 2004 01:03:23 -0400 (EDT) +Subject: Re: Caching of Queries +From: Neil Conway +To: Aaron Werman +Cc: Scott Kirkwood , + pgsql-performance@postgresql.org +In-Reply-To: +References: + +Content-Type: text/plain +Message-Id: <1096261381.25688.741.camel@localhost.localdomain> +Mime-Version: 1.0 +X-Mailer: Ximian Evolution 1.4.6 +Date: Mon, 27 Sep 2004 15:03:01 +1000 +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at mailbox.samurai.com +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/275 +X-Sequence-Number: 8403 + +On Thu, 2004-09-23 at 07:43, Aaron Werman wrote: +> MySQL stores a statement with its results. This is optional and when a +> client allows this type of processing, the SQL is hashed and matched to the +> statement - and the stored *result* is returned. The point is that a lot of +> systems do lots of static queries, such as a pick list on a web page - but +> if the data changes the prior result is returned. This (plus a stable jdbc +> driver) was the reason MySQL did well in the eWeek database comparison. + +I think the conclusion of past discussions about this feature is that +it's a bad idea. Last I checked, MySQL has to clear the *entire* query +cache when a single DML statement modifying the table in question is +issued. Not to mention that the feature is broken for non-deterministic +queries (like now(), ORDER BY random(), or nextval('some_seq'), and so +on). That makes the feature close to useless for a lot of situations, +albeit not every situation. + +-Neil + + + +From pgsql-performance-owner@postgresql.org Mon Sep 27 06:19:09 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 76254329E7C + for ; + Mon, 27 Sep 2004 06:19:08 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 14757-01 + for ; + Mon, 27 Sep 2004 05:19:04 +0000 (GMT) +Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) + by svr1.postgresql.org (Postfix) with ESMTP id 9A3E0329E45 + for ; + Mon, 27 Sep 2004 06:19:01 +0100 (BST) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id i8R5IuZx018767; + Mon, 27 Sep 2004 01:18:56 -0400 (EDT) +To: Neil Conway +Cc: Aaron Werman , + Scott Kirkwood , pgsql-performance@postgresql.org +Subject: Re: Caching of Queries +In-reply-to: <1096261381.25688.741.camel@localhost.localdomain> +References: + + <1096261381.25688.741.camel@localhost.localdomain> +Comments: In-reply-to Neil Conway + message dated "Mon, 27 Sep 2004 15:03:01 +1000" +Date: Mon, 27 Sep 2004 01:18:56 -0400 +Message-ID: <18766.1096262336@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/277 +X-Sequence-Number: 8405 + +Neil Conway writes: +> I think the conclusion of past discussions about this feature is that +> it's a bad idea. Last I checked, MySQL has to clear the *entire* query +> cache when a single DML statement modifying the table in question is +> issued. + +Do they actually make a rigorous guarantee that the cached result is +still accurate when/if it is returned to the client? (That's an honest +question --- I don't know how MySQL implements this.) + +IIRC, in our past threads on this topic, it was suggested that if you +can tolerate not-necessarily-up-to-date results, you should be doing +this sort of caching on the client side and not in the DB server at all. +I wouldn't try that in a true "client" scenario, but when the DB client +is application-server middleware, it would make some sense to cache in +the application server. + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Mon Sep 27 06:15:47 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 27D23329E86 + for ; + Mon, 27 Sep 2004 06:15:45 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 11117-07 + for ; + Mon, 27 Sep 2004 05:15:36 +0000 (GMT) +Received: from mithi.com (mithi.com [203.197.88.81]) + by svr1.postgresql.org (Postfix) with SMTP id 9D467329E80 + for ; + Mon, 27 Sep 2004 06:15:33 +0100 (BST) +Received: (qmail 14090 invoked by uid 0); 27 Sep 2004 05:20:50 -0000 +Received: from unknown (HELO mithi.com) (219.65.92.169) + by 0 with SMTP; 27 Sep 2004 05:20:50 -0000 +Received: (qmail 2864 invoked by uid 0); 27 Sep 2004 05:26:33 -0000 +Received: from unknown (HELO MithiConnectServerScanner) (192.168.0.124) + by 0 with SMTP; 27 Sep 2004 05:26:33 -0000 +Received: (qmail 2860 invoked by uid 504); 27 Sep 2004 05:26:32 -0000 +Received: from amol@mithi.com by mailmithi by uid 0 with qmail-scanner-1.21 + (clamscan: 0.60. spamassassin: 2.31. + Clear:RC:1(192.168.0.124):SA:0(-2.4/5.0):. + Processed in 9.062566 secs); 27 Sep 2004 05:26:32 -0000 +Received: from unknown (HELO 0.0.0.0) ([192.168.0.124]) + (envelope-sender ) by 0 (qmail-ldap-1.03) with SMTP + for ; 27 Sep 2004 05:26:22 -0000 +Message-ID: <4574760.1096262782226.JavaMail.javamailuser@localhost> +Date: Mon, 27 Sep 2004 10:56:21 +0530 (IST) +From: Amol Bhutada +To: pgsql-performance@postgresql.org +Subject: unsubscribe +Mime-Version: 1.0 +X-Mithi-ILSubject: unsubscribe +X-MithiMail: MithiMail +X-Mithi-SubHasIL: 0 +X-Mithi-MsgHasIL: 0 +X-Mithi-NoOfAttachments: 0 +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.8 tagged_above=0.0 required=5.0 tests=HTML_40_50, + HTML_MESSAGE, RCVD_NUMERIC_HELO +X-Spam-Level: +Content-Type: multipart/alternative; + boundary="----=_Part_123_18559324.1096262781617" +X-Archive-Number: 200409/276 +X-Sequence-Number: 8404 + +------=_Part_123_18559324.1096262781617 +Content-Type: text/plain +Content-Transfer-Encoding: quoted-printable + +unsubscribe= + +------=_Part_123_18559324.1096262781617 +Content-Type: text/html +Content-Transfer-Encoding: quoted-printable + +unsubscribe
= + +------=_Part_123_18559324.1096262781617-- + +From pgsql-performance-owner@postgresql.org Mon Sep 27 09:50:44 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id CC4F0329C89 + for ; + Mon, 27 Sep 2004 09:50:43 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 70114-07 + for ; + Mon, 27 Sep 2004 08:50:38 +0000 (GMT) +Received: from web41529.mail.yahoo.com (web41529.mail.yahoo.com + [66.218.94.136]) + by svr1.postgresql.org (Postfix) with SMTP id 330EF329E80 + for ; + Mon, 27 Sep 2004 09:50:38 +0100 (BST) +Message-ID: <20040927085037.99255.qmail@web41529.mail.yahoo.com> +Received: from [68.158.12.137] by web41529.mail.yahoo.com via HTTP; + Mon, 27 Sep 2004 01:50:37 PDT +Date: Mon, 27 Sep 2004 01:50:37 -0700 (PDT) +From: Mark Cotner +Subject: Performance/Functional Analysis Complete +To: pgsql-performance@postgresql.org +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/278 +X-Sequence-Number: 8406 + +I finished the write-up I mentioned a few weeks ago. + +Feedback is welcome. + +Thanks to everyone on this list and especially to all +the folks in IRC who helped me get up to speed on +PostgreSQL in a very short period of time. + +I've already migrated one of the applications I +cowrote with CableLabs to PostgreSQL. It isn't quite +as demanding as the app in the review, but will serve +as a great test bed for the migration work that is +just beginning. + +Here's the write-up . . . +http://www.opensourcecable.org/PostgreSQL_Performance_Analysis_Cox.pdf + +I think that you'll find a lot of people like myself +who develop applications using MySQL because their +skillset requires a simple database, and want more +when the application and their skills grow. I was(and +still am to an extent) a little frustrated by the +perceived ease of use of the PG client compared to +MySQL's client. I really think it would be a good +idea to at least implement "quit" and "exit". The \ +commands take some getting used to and have more +flexibility, but will never be as easy as MySQL show +commands. With that said, after only three weeks, I'm +not put-off by the client interface at all now. + +'njoy, +Mark + +From pgsql-performance-owner@postgresql.org Mon Sep 27 13:59:37 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 510AA329ED6 + for ; + Mon, 27 Sep 2004 13:59:36 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 58215-05 + for ; + Mon, 27 Sep 2004 12:59:28 +0000 (GMT) +Received: from stark.xeocode.com (gsstark.mtl.istop.com [66.11.160.162]) + by svr1.postgresql.org (Postfix) with ESMTP id CA8BC329ED5 + for ; + Mon, 27 Sep 2004 13:59:31 +0100 (BST) +Received: from localhost ([127.0.0.1] helo=stark.xeocode.com) + by stark.xeocode.com with smtp (Exim 3.36 #1 (Debian)) + id 1CBv6G-0004Sc-00; Mon, 27 Sep 2004 08:59:28 -0400 +To: Neil Conway +Cc: Aaron Werman , + Scott Kirkwood , pgsql-performance@postgresql.org +Subject: Re: Caching of Queries +References: + + <1096261381.25688.741.camel@localhost.localdomain> +In-Reply-To: <1096261381.25688.741.camel@localhost.localdomain> +From: Greg Stark +Organization: The Emacs Conspiracy; member since 1992 +Date: 27 Sep 2004 08:59:27 -0400 +Message-ID: <87fz5398b4.fsf@stark.xeocode.com> +Lines: 29 +User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/279 +X-Sequence-Number: 8407 + +Neil Conway writes: + +> I think the conclusion of past discussions about this feature is that +> it's a bad idea. Last I checked, MySQL has to clear the *entire* query +> cache when a single DML statement modifying the table in question is +> issued. Not to mention that the feature is broken for non-deterministic +> queries (like now(), ORDER BY random(), or nextval('some_seq'), and so +> on). That makes the feature close to useless for a lot of situations, +> albeit not every situation. + +Well there's no reason to assume that just because other implementations are +weak that postgres would have to slavishly copy them. + +I've often wondered whether it would make sense to cache the intermediate +results in queries. Any time there's a Materialize node, the database is +storing all those data somewhere; it could note the plan and parameters that +generated the data and reuse them if it sees the same plan and parameters -- +including keeping track of whether the source tables have changed or whether +there were any non-immutable functions of course. + +This could be quite helpful as people often do a series of queries on the same +basic data. Things like calculating the total number of records matching the +user's query then fetching only the records that fit on the current page. Or +fetching records for a report then having to calculate subtotals and totals +for that same report. Or even generating multiple reports breaking down the +same data along different axes. + +-- +greg + + +From pgsql-performance-owner@postgresql.org Mon Sep 27 14:00:23 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id A9EE0329EA8 + for ; + Mon, 27 Sep 2004 14:00:22 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 56344-07 + for ; + Mon, 27 Sep 2004 13:00:12 +0000 (GMT) +Received: from mproxy.gmail.com (rproxy.gmail.com [64.233.170.198]) + by svr1.postgresql.org (Postfix) with ESMTP id 6157D329DB1 + for ; + Mon, 27 Sep 2004 14:00:14 +0100 (BST) +Received: by mproxy.gmail.com with SMTP id 77so3633678rnk + for ; + Mon, 27 Sep 2004 06:00:14 -0700 (PDT) +Received: by 10.38.171.19 with SMTP id t19mr258615rne; + Mon, 27 Sep 2004 06:00:14 -0700 (PDT) +Received: by 10.38.73.17 with HTTP; Mon, 27 Sep 2004 06:00:14 -0700 (PDT) +Message-ID: +Date: Mon, 27 Sep 2004 10:00:14 -0300 +From: Scott Kirkwood +Reply-To: Scott Kirkwood +To: pgsql-performance@postgresql.org +Subject: Re: Caching of Queries +In-Reply-To: <1096261381.25688.741.camel@localhost.localdomain> +Mime-Version: 1.0 +Content-Type: text/plain; charset=US-ASCII +Content-Transfer-Encoding: 7bit +References: + + <1096261381.25688.741.camel@localhost.localdomain> +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/280 +X-Sequence-Number: 8408 + +On Mon, 27 Sep 2004 15:03:01 +1000, Neil Conway wrote: +> I think the conclusion of past discussions about this feature is that +> it's a bad idea. Last I checked, MySQL has to clear the *entire* query +> cache when a single DML statement modifying the table in question is +> issued. Not to mention that the feature is broken for non-deterministic +> queries (like now(), ORDER BY random(), or nextval('some_seq'), and so +> on). That makes the feature close to useless for a lot of situations, +> albeit not every situation. + +I think it's important to demark three levels of possible caching: +1) Caching of the parsed query tree +2) Caching of the query execute plan +3) Caching of the query results + +I think caching the query results (3) is pretty dangerous and +difficult to do correctly. + +Caching of the the execute plan (2) is not dangerous but may actually +execute more slowly by caching a bad plan (i.e. a plan not suited to +the current data) + +Caching of the query tree (1) to me has very little downsides (except +extra coding). But may not have a lot of win either, depending how +much time/resources are required to parse the SQL and lookup the +objects in the system tables (something I've never gotten a +satisfactory answer about). Also, some of the query cache would have +to be cleared when DDL statements are performed. + +-Scott + +From pgsql-performance-owner@postgresql.org Mon Sep 27 14:30:09 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 2AF3B329EDF + for ; + Mon, 27 Sep 2004 14:30:08 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 68022-05 + for ; + Mon, 27 Sep 2004 13:30:00 +0000 (GMT) +Received: from mproxy.gmail.com (mproxy.gmail.com [216.239.56.248]) + by svr1.postgresql.org (Postfix) with ESMTP id 99940329E77 + for ; + Mon, 27 Sep 2004 14:30:02 +0100 (BST) +Received: by mproxy.gmail.com with SMTP id u52so231170cwc + for ; + Mon, 27 Sep 2004 06:29:58 -0700 (PDT) +Received: by 10.11.117.26 with SMTP id p26mr12961cwc; + Mon, 27 Sep 2004 06:29:58 -0700 (PDT) +Received: by 10.11.119.12 with HTTP; Mon, 27 Sep 2004 06:29:58 -0700 (PDT) +Message-ID: <330532b6040927062938c1d596@mail.gmail.com> +Date: Mon, 27 Sep 2004 09:29:58 -0400 +From: Mitch Pirtle +Reply-To: Mitch Pirtle +To: Tom Lane +Subject: Re: Caching of Queries +Cc: Neil Conway , Aaron Werman , + Scott Kirkwood , pgsql-performance@postgresql.org +In-Reply-To: <18766.1096262336@sss.pgh.pa.us> +Mime-Version: 1.0 +Content-Type: text/plain; charset=US-ASCII +Content-Transfer-Encoding: 7bit +References: + + <1096261381.25688.741.camel@localhost.localdomain> + <18766.1096262336@sss.pgh.pa.us> +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/281 +X-Sequence-Number: 8409 + +On Mon, 27 Sep 2004 01:18:56 -0400, Tom Lane wrote: +> IIRC, in our past threads on this topic, it was suggested that if you +> can tolerate not-necessarily-up-to-date results, you should be doing +> this sort of caching on the client side and not in the DB server at all. +> I wouldn't try that in a true "client" scenario, but when the DB client +> is application-server middleware, it would make some sense to cache in +> the application server. + +I'd also like to add that when one of the Mambo community members +started running benchmarks of popular Content Management Systems +(CMS), the ones that implemented page-level caching were significantly +more scalable as a result of the decreased load on the database (and +application server, as a result): + +http://forum.mamboserver.com/showthread.php?t=11782 + +Caching at the database level provides the smallest possible +performance boost (at least regarding caching), as caching the query +on the webserver (via ADOdb's query cache) avoids the database server +altogether; and page-level caching gives you the biggest possible +benefit. + +Yes, you have to be careful how you cache your data, but for many +applications it is easy to implement a trigger that clears the cache +when certain data is updated. + +-- Mitch + +From pgsql-performance-owner@postgresql.org Mon Sep 27 15:19:19 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id EB5A3329CFB + for ; + Mon, 27 Sep 2004 15:19:17 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 91400-01 + for ; + Mon, 27 Sep 2004 14:19:08 +0000 (GMT) +Received: from candle.pha.pa.us (candle.pha.pa.us [207.106.42.251]) + by svr1.postgresql.org (Postfix) with ESMTP id 40301329EBB + for ; + Mon, 27 Sep 2004 15:19:10 +0100 (BST) +Received: (from pgman@localhost) + by candle.pha.pa.us (8.11.6/8.11.6) id i8REHuc28214; + Mon, 27 Sep 2004 10:17:56 -0400 (EDT) +From: Bruce Momjian +Message-Id: <200409271417.i8REHuc28214@candle.pha.pa.us> +Subject: Re: Caching of Queries +In-Reply-To: +To: Scott Kirkwood +Date: Mon, 27 Sep 2004 10:17:56 -0400 (EDT) +Cc: pgsql-performance@postgresql.org +X-Mailer: ELM [version 2.4ME+ PL108 (25)] +MIME-Version: 1.0 +Content-Transfer-Encoding: 7bit +Content-Type: text/plain; charset=US-ASCII +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/282 +X-Sequence-Number: 8410 + + +Added to TODO: + +* Consider automatic caching of queries at various levels: + o Parsed query tree + o Query execute plan + o Query results + + +--------------------------------------------------------------------------- + +Scott Kirkwood wrote: +> On Mon, 27 Sep 2004 15:03:01 +1000, Neil Conway wrote: +> > I think the conclusion of past discussions about this feature is that +> > it's a bad idea. Last I checked, MySQL has to clear the *entire* query +> > cache when a single DML statement modifying the table in question is +> > issued. Not to mention that the feature is broken for non-deterministic +> > queries (like now(), ORDER BY random(), or nextval('some_seq'), and so +> > on). That makes the feature close to useless for a lot of situations, +> > albeit not every situation. +> +> I think it's important to demark three levels of possible caching: +> 1) Caching of the parsed query tree +> 2) Caching of the query execute plan +> 3) Caching of the query results +> +> I think caching the query results (3) is pretty dangerous and +> difficult to do correctly. +> +> Caching of the the execute plan (2) is not dangerous but may actually +> execute more slowly by caching a bad plan (i.e. a plan not suited to +> the current data) +> +> Caching of the query tree (1) to me has very little downsides (except +> extra coding). But may not have a lot of win either, depending how +> much time/resources are required to parse the SQL and lookup the +> objects in the system tables (something I've never gotten a +> satisfactory answer about). Also, some of the query cache would have +> to be cleared when DDL statements are performed. +> +> -Scott +> +> ---------------------------(end of broadcast)--------------------------- +> TIP 7: don't forget to increase your free space map settings +> + +-- + Bruce Momjian | http://candle.pha.pa.us + pgman@candle.pha.pa.us | (610) 359-1001 + + If your life is a hard drive, | 13 Roberts Road + + Christ can be your backup. | Newtown Square, Pennsylvania 19073 + +From pgsql-performance-owner@postgresql.org Mon Sep 27 17:15:52 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 29C02329EBF + for ; + Mon, 27 Sep 2004 17:15:51 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 36236-05 + for ; + Mon, 27 Sep 2004 16:15:46 +0000 (GMT) +Received: from main.gmane.org (main.gmane.org [80.91.229.2]) + by svr1.postgresql.org (Postfix) with ESMTP id 333A4329E93 + for ; + Mon, 27 Sep 2004 17:15:45 +0100 (BST) +Received: from list by main.gmane.org with local (Exim 3.35 #1 (Debian)) + id 1CByAB-00042H-00 + for ; Mon, 27 Sep 2004 18:15:43 +0200 +Received: from srv.protecting.net ([212.126.218.242]) + by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) + id 1AlnuQ-0007hv-00 + for ; Mon, 27 Sep 2004 18:15:38 +0200 +Received: from hf0722x by srv.protecting.net with local (Gmexim 0.1 (Debian)) + id 1AlnuQ-0007hv-00 + for ; Mon, 27 Sep 2004 18:15:38 +0200 +X-Injected-Via-Gmane: http://gmane.org/ +To: pgsql-performance@postgresql.org +From: Harald Fuchs +Subject: Re: Caching of Queries +Date: 27 Sep 2004 18:15:35 +0200 +Organization: Linux Private Site +Lines: 15 +Message-ID: +References: + + <1096261381.25688.741.camel@localhost.localdomain> +Reply-To: hf0722x@protecting.net +Mime-Version: 1.0 +Content-Type: text/plain; charset=US-ASCII +X-Complaints-To: usenet@sea.gmane.org +X-Gmane-NNTP-Posting-Host: srv.protecting.net +User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/283 +X-Sequence-Number: 8411 + +In article <1096261381.25688.741.camel@localhost.localdomain>, +Neil Conway writes: + +> I think the conclusion of past discussions about this feature is that +> it's a bad idea. Last I checked, MySQL has to clear the *entire* query +> cache when a single DML statement modifying the table in question is +> issued. + +Nope, it deletes only queries using that table. + +> Not to mention that the feature is broken for non-deterministic +> queries (like now(), ORDER BY random(), or nextval('some_seq'), and so +> on). + +Queries containing now(), rand(), or similar functions aren't cached by MySQL. + + +From pgsql-performance-owner@postgresql.org Mon Sep 27 17:44:42 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id BFDB1329EAA + for ; + Mon, 27 Sep 2004 17:44:35 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 45004-10 + for ; + Mon, 27 Sep 2004 16:44:29 +0000 (GMT) +Received: from hotmail.com (bay18-dav6.bay18.hotmail.com [65.54.187.186]) + by svr1.postgresql.org (Postfix) with ESMTP id 935F2329CD9 + for ; + Mon, 27 Sep 2004 17:44:28 +0100 (BST) +Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; + Mon, 27 Sep 2004 09:44:01 -0700 +Received: from 67.81.98.198 by bay18-dav6.bay18.hotmail.com with DAV; + Mon, 27 Sep 2004 16:43:22 +0000 +X-Originating-IP: [67.81.98.198] +X-Originating-Email: [awerman2@hotmail.com] +X-Sender: awerman2@hotmail.com +From: "Aaron Werman" +To: "Scott Kirkwood" , + +References: + + <1096261381.25688.741.camel@localhost.localdomain> + +Subject: Re: Caching of Queries +Date: Mon, 27 Sep 2004 12:43:38 -0400 +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 6.00.2800.1437 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 +Message-ID: +X-OriginalArrivalTime: 27 Sep 2004 16:44:01.0628 (UTC) + FILETIME=[314971C0:01C4A4B1] +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/284 +X-Sequence-Number: 8412 + +From: "Scott Kirkwood" + +> On Mon, 27 Sep 2004 15:03:01 +1000, Neil Conway wrote: +> > I think the conclusion of past discussions about this feature is that +> > it's a bad idea. Last I checked, MySQL has to clear the *entire* query +> > cache when a single DML statement modifying the table in question is +> > issued. Not to mention that the feature is broken for non-deterministic +> > queries (like now(), ORDER BY random(), or nextval('some_seq'), and so +> > on). That makes the feature close to useless for a lot of situations, +> > albeit not every situation. + +Only the cache of changed tables are cleared. MySQL sanely doesn't cache +statements with unstable results. The vast majority of statements are +stable. The feature is likely to dramatically improve performance of most +applications; ones with lots of queries are obvious, but even data +warehouses have lots of (expensive) repetitious queries against static data. + +> +> I think it's important to demark three levels of possible caching: +> 1) Caching of the parsed query tree +> 2) Caching of the query execute plan +> 3) Caching of the query results +> +> I think caching the query results (3) is pretty dangerous and +> difficult to do correctly. + +I think it's very hard to cache results on the client side without guidance +because it is expensive to notify the client of change events. A changing +table couldn't be cached on client side without a synchronous check to the +db - defeating the purpose. + +Guidance should work, though - I also think an optional client configuration +table which specified static tables would work and the cost of a sparse XOR +hash of statements to find match candidate statements would be negligible. +The list of tables would be a contract that they won't change. The fact is +that there often are a lot of completely static tables in high volume +transaction systems, and the gain of SQUID style proxying could be an +enormous performance gain (effort, network overhead, latency, DB server cont +ext switching, ...) especially in web farm and multi tiered applications +(and middleware doing caching invests so many cycles to do so). + +Caching results on the server would also dramatically improve performance of +high transaction rate applications, but less than at the client. The +algorithm of only caching small result sets for tables that haven't changed +recently is trivial, and the cost of first pass filtering of candidate +statements to use a cache result through sparse XOR hashes is low. The +statement/results cache would need to be invalidated when any referenced +table is changed. This option seems like a big win. + +> +> Caching of the the execute plan (2) is not dangerous but may actually +> execute more slowly by caching a bad plan (i.e. a plan not suited to +> the current data) + +This concern could be resolved by aging plans out of cache. + +This concern relates to an idiosyncrasy of pg, that vacuum has such a +profound effect. Anyone who has designed very high transaction rate systems +appreciates DB2 static binding, where a plan is determined and stored in the +database, and precompiled code uses those plans - and is both stable and +free of plan cost. The fact is that at a high transaction rate, we often see +the query parse and optimization as the most expensive activity. The planner +design has to be "dumbed down" to reduce overhead (and even forced to geqo +choice). + +The common development philosophy in pg is expecting explicit prepares and +executes against bind variables (relatively rare, but useful in high volume +situations), and otherwise (commonly) using explicit literals in statements. +The problem here is the prepare/execute only works in monolithic +applications, and the chance of reuse of SQL statements with literals is +much lower. + +(On a blue sky note, I would love to see a planner that dynamically changed +search depth of execution paths, so it could exhaustively build best plans +at low usage times and be less sophisticated when the load was higher... or +better yet, try alternatively for very high transaction frequency plans +until it found the best one in practice! The identified correct plan would +be used subsequently.) + +> +> Caching of the query tree (1) to me has very little downsides (except +> extra coding). But may not have a lot of win either, depending how +> much time/resources are required to parse the SQL and lookup the +> objects in the system tables (something I've never gotten a +> satisfactory answer about). Also, some of the query cache would have +> to be cleared when DDL statements are performed. + +Parse cache is obviously easy - just store the parse tree with a hash and +the SQL string. This would only help some very specific types of transaction +mixes. The issue is why go through all this trouble without caching the +plan? The same issues exist in both - the cost of matching, the need to +invalidate if objects definitions change, but the win would be so much less. + +> +> -Scott +> +> ---------------------------(end of broadcast)--------------------------- +> TIP 7: don't forget to increase your free space map settings +> + + + + +From pgsql-performance-owner@postgresql.org Mon Sep 27 18:20:58 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 75FA9329D2A + for ; + Mon, 27 Sep 2004 18:20:57 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 59752-05 + for ; + Mon, 27 Sep 2004 17:20:51 +0000 (GMT) +Received: from bayswater1.ymogen.net (host-154-240-27-217.pobox.net.uk + [217.27.240.154]) + by svr1.postgresql.org (Postfix) with ESMTP id 4D231329F0B + for ; + Mon, 27 Sep 2004 18:20:50 +0100 (BST) +Received: from solent (unknown [213.165.136.10]) + by bayswater1.ymogen.net (Postfix) with ESMTP + id EB0469EA32; Mon, 27 Sep 2004 18:20:48 +0100 (BST) +Reply-To: +From: "Matt Clark" +To: "'Aaron Werman'" , + "'Scott Kirkwood'" , + +Subject: Re: Caching of Queries +Date: Mon, 27 Sep 2004 18:20:48 +0100 +Organization: Ymogen Ltd +Message-ID: <00e801c4a4b6$5526dd30$8300a8c0@solent> +MIME-Version: 1.0 +Content-Type: text/plain; + charset="us-ascii" +Content-Transfer-Encoding: quoted-printable +X-Priority: 3 (Normal) +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook, Build 10.0.6626 +X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 +In-Reply-To: +Importance: Normal +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/285 +X-Sequence-Number: 8413 + +> I think it's very hard to cache results on the client side=20 +> without guidance because it is expensive to notify the client=20 +> of change events. A changing table couldn't be cached on=20 +> client side without a synchronous check to the db - defeating=20 +> the purpose. + +This is very true. Client side caching is an enormous win for apps, but it +requires quite a lot of logic, triggers to update last-modified fields on +relevant tables, etc etc. Moving some of this logic to the DB would perhaps +not usually be quite as efficient as a bespoke client caching solution, but +it will above all be a lot easier for the application developer! + +The other reason why it is god for the DB to support this feature is that in +typical web apps there are multiple web/app servers in a farm, but mostly +just one live DB instance, so effective client side caching requires a +distributed cache, or a SQL proxy, both of which are the kind of middleware +that tends to give cautious people cause to fret. + +As a side effect, this would also satisfy the common gotcha of count(), +max() and other aggregates always needing a scan. There are _so_ many +occasions where 'select count(*) from bar' really does not need to be that +accurate. + +So yeah, here's another vote for this feature. It doesn't even need to +happen automagically to be honest, so long as it's really simple for the +client to turn on (preferably per-statement or per-table). + +Actually, that gives me an implementation idea. How about cacheable views? +So you might do: + +CREATE [ CACHEABLE ] VIEW view=20 + [ MAXSTALEDATA seconds ] + [ MAXSTALEPLAN seconds ] +AS ...=20 + +That would be tidy I think... + +M + + +From pgsql-performance-owner@postgresql.org Mon Sep 27 18:37:59 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id E6DC1329F03 + for ; + Mon, 27 Sep 2004 18:37:57 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 67203-07 + for ; + Mon, 27 Sep 2004 17:37:52 +0000 (GMT) +Received: from tht.net (vista.tht.net [216.126.88.2]) + by svr1.postgresql.org (Postfix) with ESMTP id 9A126329D15 + for ; + Mon, 27 Sep 2004 18:37:51 +0100 (BST) +Received: from [134.22.69.205] (dyn-69-205.tor.dsl.tht.net [134.22.69.205]) + by tht.net (Postfix) with ESMTP + id 0F03A76AE0; Mon, 27 Sep 2004 13:37:51 -0400 (EDT) +Subject: Re: Caching of Queries +From: Rod Taylor +To: matt@ymogen.net +Cc: 'Aaron Werman' , + 'Scott Kirkwood' , + Postgresql Performance +In-Reply-To: <00e801c4a4b6$5526dd30$8300a8c0@solent> +References: <00e801c4a4b6$5526dd30$8300a8c0@solent> +Content-Type: text/plain +Message-Id: <1096306670.40463.173.camel@jester> +Mime-Version: 1.0 +X-Mailer: Ximian Evolution 1.4.6 +Date: Mon, 27 Sep 2004 13:37:51 -0400 +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/286 +X-Sequence-Number: 8414 + +> So yeah, here's another vote for this feature. It doesn't even need to +> happen automagically to be honest, so long as it's really simple for the +> client to turn on (preferably per-statement or per-table). + +It might be easiest to shove the caching logic into pgpool instead. + +Create an extension of EXPLAIN which returns data in an easy to +understand format for computers so that pgpool can retrieve information +such as a list of tables involved, + +Extend LISTEN to be able to listen for a SELECT on a table -- +replacement for dynamically adding triggers to send a notify on inserts, +updates, deletes. + +Create some kind of generic LISTEN for structural changes. I know SLONY +could make use of triggers on ALTER TABLE, and friends as well. + + +When pg_pool is told to cache a query, it can get a table list and +monitor for changes. When it gets changes, simply dumps the cache. + + +From pgsql-performance-owner@postgresql.org Mon Sep 27 19:15:47 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id D7098329F64 + for ; + Mon, 27 Sep 2004 19:15:45 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 82087-01 + for ; + Mon, 27 Sep 2004 18:15:40 +0000 (GMT) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by svr1.postgresql.org (Postfix) with ESMTP id 098D0329CFB + for ; + Mon, 27 Sep 2004 19:15:40 +0100 (BST) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by news.hub.org (8.12.9/8.12.9) with ESMTP id i8RIFbfg083001 + for ; Mon, 27 Sep 2004 18:15:37 GMT + (envelope-from news@news.hub.org) +Received: (from news@localhost) + by news.hub.org (8.12.9/8.12.9/Submit) id i8RI9wDs080947 + for pgsql-performance@postgresql.org; Mon, 27 Sep 2004 18:09:58 GMT +From: Gaetano Mendola +X-Newsgroups: comp.databases.postgresql.performance +Subject: best statistic target for boolean columns +Date: Mon, 27 Sep 2004 20:09:46 +0200 +Organization: PYRENET Midi-pyrenees Provider +Lines: 9 +Message-ID: +Mime-Version: 1.0 +Content-Type: text/plain; charset=ISO-8859-1; format=flowed +Content-Transfer-Encoding: 7bit +X-Complaints-To: abuse@pyrenet.fr +User-Agent: Mozilla Thunderbird 0.8 (Windows/20040913) +X-Accept-Language: en-us, en +X-Enigmail-Version: 0.86.1.0 +X-Enigmail-Supports: pgp-inline, pgp-mime +To: pgsql-performance@postgresql.org +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/287 +X-Sequence-Number: 8415 + +Hi all, +don't you think the best statistic target for a boolean +column is something like 2? Or in general the is useless +have a statistics target > data type cardinality ? + + + +Regards +Gaetano Mendola + +From pgsql-performance-owner@postgresql.org Mon Sep 27 19:25:39 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 13B41329C63 + for ; + Mon, 27 Sep 2004 19:25:37 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 83957-02 + for ; + Mon, 27 Sep 2004 18:25:29 +0000 (GMT) +Received: from dhcp-7-248.ma.lycos.com (waltham-nat.ma.lycos.com + [209.202.205.1]) + by svr1.postgresql.org (Postfix) with SMTP id 709BA329CBC + for ; + Mon, 27 Sep 2004 19:25:28 +0100 (BST) +Received: (qmail 13960 invoked from network); 27 Sep 2004 18:55:32 -0000 +Received: from dhcp-7-186.ma.lycos.com (HELO ?10.124.7.186?) (10.124.7.186) + by dhcp-7-248.ma.lycos.com with SMTP; 27 Sep 2004 18:55:32 -0000 +In-Reply-To: <330532b6040927062938c1d596@mail.gmail.com> +References: + + <1096261381.25688.741.camel@localhost.localdomain> + <18766.1096262336@sss.pgh.pa.us> + <330532b6040927062938c1d596@mail.gmail.com> +Mime-Version: 1.0 (Apple Message framework v619) +Content-Type: text/plain; charset=US-ASCII; format=flowed +Message-Id: +Content-Transfer-Encoding: 7bit +Cc: Aaron Werman , + Scott Kirkwood , + Neil Conway , pgsql-performance@postgresql.org, + Tom Lane +From: Jeff +Subject: Re: Caching of Queries +Date: Mon, 27 Sep 2004 14:25:55 -0400 +To: Mitch Pirtle +X-Mailer: Apple Mail (2.619) +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/288 +X-Sequence-Number: 8416 + +[ discussion of server side result caching ] + +and lets not forget PG's major fork it will throw into things: MVCC +The results of query A may hold true for txn 1, but not txn 2 and so on +. +That would have to be taken into account as well and would greatly +complicate things. + +It is always possible to do a "poor man"'s query cache with triggers.. +which would just leave you with basically a materialized view. + +-- +Jeff Trout +http://www.jefftrout.com/ +http://www.stuarthamm.net/ + + +From pgsql-performance-owner@postgresql.org Mon Sep 27 19:29:41 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id E5A26329C63 + for ; + Mon, 27 Sep 2004 19:29:39 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 81621-07 + for ; + Mon, 27 Sep 2004 18:29:32 +0000 (GMT) +Received: from davinci.ethosmedia.com (server226.ethosmedia.com + [209.128.84.226]) + by svr1.postgresql.org (Postfix) with ESMTP id 11E44329E80 + for ; + Mon, 27 Sep 2004 19:29:32 +0100 (BST) +Received: from [64.81.245.111] (account josh@agliodbs.com HELO + temoku.sf.agliodbs.com) + by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.1.8) + with ESMTP id 6420762; Mon, 27 Sep 2004 11:30:52 -0700 +From: Josh Berkus +Reply-To: josh@agliodbs.com +Organization: Aglio Database Solutions +To: Gaetano Mendola +Subject: Re: best statistic target for boolean columns +Date: Mon, 27 Sep 2004 11:31:09 -0700 +User-Agent: KMail/1.6.2 +Cc: pgsql-performance@postgresql.org +References: +In-Reply-To: +MIME-Version: 1.0 +Content-Disposition: inline +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +Message-Id: <200409271131.09932.josh@agliodbs.com> +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/289 +X-Sequence-Number: 8417 + +Gaetano, + +> don't you think the best statistic target for a boolean +> column is something like 2? Or in general the is useless +> have a statistics target > data type cardinality ? + +It depends, really, on the proportionality of the boolean values; if they're +about equal, I certainly wouldn't raise Stats from the default of 10. If, +however, it's very dispraportionate -- like 2% true and 98% false -- then it +may pay to have better statistics so that the planner doesn't assume 50% +hits, which it otherwise might. + +-- +--Josh + +Josh Berkus +Aglio Database Solutions +San Francisco + +From pgsql-performance-owner@postgresql.org Mon Sep 27 19:59:25 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id D031E329F8B + for ; + Mon, 27 Sep 2004 19:59:23 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 97273-04 + for ; + Mon, 27 Sep 2004 18:59:17 +0000 (GMT) +Received: from mproxy.gmail.com (mproxy.gmail.com [216.239.56.240]) + by svr1.postgresql.org (Postfix) with ESMTP id 1C8B6329F99 + for ; + Mon, 27 Sep 2004 19:59:16 +0100 (BST) +Received: by mproxy.gmail.com with SMTP id w67so235194cwb + for ; + Mon, 27 Sep 2004 11:59:15 -0700 (PDT) +Received: by 10.11.117.63 with SMTP id p63mr28155cwc; + Mon, 27 Sep 2004 11:59:15 -0700 (PDT) +Received: by 10.11.119.12 with HTTP; Mon, 27 Sep 2004 11:59:13 -0700 (PDT) +Message-ID: <330532b604092711591491303a@mail.gmail.com> +Date: Mon, 27 Sep 2004 14:59:13 -0400 +From: Mitch Pirtle +Reply-To: Mitch Pirtle +To: pgsql-performance@postgresql.org +Subject: Re: Caching of Queries +In-Reply-To: <00e801c4a4b6$5526dd30$8300a8c0@solent> +Mime-Version: 1.0 +Content-Type: text/plain; charset=US-ASCII +Content-Transfer-Encoding: 7bit +References: + <00e801c4a4b6$5526dd30$8300a8c0@solent> +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/290 +X-Sequence-Number: 8418 + +On Mon, 27 Sep 2004 18:20:48 +0100, Matt Clark wrote: +> This is very true. Client side caching is an enormous win for apps, but it +> requires quite a lot of logic, triggers to update last-modified fields on +> relevant tables, etc etc. Moving some of this logic to the DB would perhaps +> not usually be quite as efficient as a bespoke client caching solution, but +> it will above all be a lot easier for the application developer! + +In the world of PHP it is trivial thanks to PEAR's Cache_Lite. The +project lead for Mambo implemented page-level caching in a day, and +had all the triggers for clearing the cache included in the content +management interface - not difficult at all. + +Basically you set a default in seconds for the HTML results to be +cached, and then have triggers set that force the cache to regenerate +(whenever CRUD happens to the content, for example). + +Can't speak for Perl/Python/Ruby/.Net/Java, but Cache_Lite sure made a +believer out of me! + +-- Mitch + +From pgsql-performance-owner@postgresql.org Mon Sep 27 20:13:55 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id CAEC6329F01 + for ; + Mon, 27 Sep 2004 20:13:53 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 01474-06 + for ; + Mon, 27 Sep 2004 19:13:47 +0000 (GMT) +Received: from stark.xeocode.com (gsstark.mtl.istop.com [66.11.160.162]) + by svr1.postgresql.org (Postfix) with ESMTP id 6BBB2329F41 + for ; + Mon, 27 Sep 2004 20:13:47 +0100 (BST) +Received: from localhost ([127.0.0.1] helo=stark.xeocode.com) + by stark.xeocode.com with smtp (Exim 3.36 #1 (Debian)) + id 1CC0wU-0005YZ-00 + for ; Mon, 27 Sep 2004 15:13:46 -0400 +To: PostgreSQL Performance List +Subject: Re: best statistic target for boolean columns +From: Gregory Stark +Date: 27 Sep 2004 15:13:45 -0400 +Message-ID: <87k6uf7ceu.fsf@stark.xeocode.com> +Lines: 28 +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/291 +X-Sequence-Number: 8419 + + +> Gaetano, +> +> > don't you think the best statistic target for a boolean +> > column is something like 2? Or in general the is useless +> > have a statistics target > data type cardinality ? +> +> It depends, really, on the proportionality of the boolean values; if they're +> about equal, I certainly wouldn't raise Stats from the default of 10. If, +> however, it's very dispraportionate -- like 2% true and 98% false -- then it +> may pay to have better statistics so that the planner doesn't assume 50% +> hits, which it otherwise might. + +No, actually the stats table keeps the n most common values and their +frequency (usually in percentage). So really a target of 2 ought to be enough +for boolean values. In fact that's all I see in pg_statistic; I'm assuming +there's a full histogram somewhere but I don't see it. Where would it be? + +However the target also dictates how large a sample of the table to take. A +target of two represents a very small sample. So the estimations could be +quite far off. + +I ran the experiment and for a table with 2036 false rows out of 204,624 the +estimate was 1720. Not bad. But then I did vacuum full analyze and got an +estimate of 688. Which isn't so good. + +-- +greg + + +From pgsql-performance-owner@postgresql.org Mon Sep 27 20:18:46 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id D9E85329F0A + for ; + Mon, 27 Sep 2004 20:18:44 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 03866-05 + for ; + Mon, 27 Sep 2004 19:18:38 +0000 (GMT) +Received: from flake.decibel.org (flake.decibel.org [66.143.173.58]) + by svr1.postgresql.org (Postfix) with ESMTP id 984ED329F0C + for ; + Mon, 27 Sep 2004 20:18:38 +0100 (BST) +Received: by flake.decibel.org (Postfix, from userid 1001) + id E7B7F1C8F0; Mon, 27 Sep 2004 19:18:36 +0000 (GMT) +Date: Mon, 27 Sep 2004 14:18:36 -0500 +From: "Jim C. Nasby" +To: Mr Pink +Cc: Scott Kirkwood , + pgsql-performance@postgresql.org +Subject: Re: Caching of Queries +Message-ID: <20040927191836.GS1297@decibel.org> +References: + <20040923152925.18234.qmail@web41114.mail.yahoo.com> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <20040923152925.18234.qmail@web41114.mail.yahoo.com> +X-Operating-System: FreeBSD 4.10-RELEASE-p2 i386 +X-Distributed: Join the Effort! http://www.distributed.net +User-Agent: Mutt/1.5.6i +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/292 +X-Sequence-Number: 8420 + +On Thu, Sep 23, 2004 at 08:29:25AM -0700, Mr Pink wrote: +> Not knowing anything about the internals of pg, I don't know how this relates, but in theory, +> query plan caching is not just about saving time re-planning queries, it's about scalability. +> Optimizing queries requires shared locks on the database metadata, which, as I understand it +> causes contention and serialization, which kills scalability. + +One of the guru's can correct me if I'm wrong here, but AFAIK metadata +lookups use essentially the same access methods as normal queries. This +means MVCC is used and no locking is required. Even if locks were +required, they would be shared read locks which wouldn't block each +other. +-- +Jim C. Nasby, Database Consultant decibel@decibel.org +Give your computer some brain candy! www.distributed.net Team #1828 + +Windows: "Where do you want to go today?" +Linux: "Where do you want to go tomorrow?" +FreeBSD: "Are you guys coming, or what?" + +From pgsql-performance-owner@postgresql.org Mon Sep 27 20:26:42 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id D1592329FB3 + for ; + Mon, 27 Sep 2004 20:26:40 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 07255-05 + for ; + Mon, 27 Sep 2004 19:26:34 +0000 (GMT) +Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) + by svr1.postgresql.org (Postfix) with ESMTP id 337EA329F97 + for ; + Mon, 27 Sep 2004 20:26:34 +0100 (BST) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id i8RJQWPx003482; + Mon, 27 Sep 2004 15:26:33 -0400 (EDT) +To: Gregory Stark +Cc: PostgreSQL Performance List +Subject: Re: best statistic target for boolean columns +In-reply-to: <87k6uf7ceu.fsf@stark.xeocode.com> +References: <87k6uf7ceu.fsf@stark.xeocode.com> +Comments: In-reply-to Gregory Stark + message dated "27 Sep 2004 15:13:45 -0400" +Date: Mon, 27 Sep 2004 15:26:32 -0400 +Message-ID: <3481.1096313192@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/293 +X-Sequence-Number: 8421 + +Gregory Stark writes: +> No, actually the stats table keeps the n most common values and their +> frequency (usually in percentage). So really a target of 2 ought to be enough +> for boolean values. In fact that's all I see in pg_statistic; I'm assuming +> there's a full histogram somewhere but I don't see it. Where would it be? + +It's not going to be there. The histogram only covers values that are +not in the most-frequent-values list, and therefore it won't exist for a +column that is completely describable by most-frequent-values. + +> However the target also dictates how large a sample of the table to take. A +> target of two represents a very small sample. So the estimations could be +> quite far off. + +Right. The real point of stats target for such columns is that it +determines how many rows to sample, and thereby indirectly implies +the accuracy of the statistics. For a heavily skewed boolean column +you'd want a high target so that the number of occurrences of the +infrequent value would be estimated accurately. + +It's also worth noting that the number of rows sampled is driven by the +largest per-column stats target in the table, and so reducing stats +target to 2 for a boolean column will save *zero* effort unless all the +columns in the table are booleans. + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Fri Oct 1 17:49:28 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id D0DAE329FD7 + for ; + Mon, 27 Sep 2004 21:12:10 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 23171-05 + for ; + Mon, 27 Sep 2004 20:12:03 +0000 (GMT) +Received: from hotmail.com (bay9-dav22.bay9.hotmail.com [64.4.46.79]) + by svr1.postgresql.org (Postfix) with ESMTP id 85F89329FD3 + for ; + Mon, 27 Sep 2004 21:12:01 +0100 (BST) +Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; + Mon, 27 Sep 2004 13:12:00 -0700 +Received: from 67.81.98.198 by bay9-dav22.bay9.hotmail.com with DAV; + Mon, 27 Sep 2004 20:11:54 +0000 +X-Originating-IP: [67.81.98.198] +X-Originating-Email: [awerman@hotmail.com] +X-Sender: awerman@hotmail.com +From: "Aaron Werman" +To: "Jeff" +Cc: +References: + + <1096261381.25688.741.camel@localhost.localdomain> + <18766.1096262336@sss.pgh.pa.us> + <330532b6040927062938c1d596@mail.gmail.com> + +Subject: Re: Caching of Queries +Date: Mon, 27 Sep 2004 16:11:53 -0400 +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 6.00.2800.1437 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 +Message-ID: +X-OriginalArrivalTime: 27 Sep 2004 20:12:00.0625 (UTC) + FILETIME=[3F594610:01C4A4CE] +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200410/10 +X-Sequence-Number: 8486 + +The context of the discussion was a hack to speed queries against static +tables, so MVCC is not relevent. As soon as any work unit against a +referenced table commits, the cache is invalid, and in fact the table +shouldn't be a candidate for this caching for a while. In fact, this cache +would reduce some the MVCC 'select count(*) from us_states' type of horrors. + +(The attraction of a server side cache is obviously that it could *with no +server or app changes* dramatically improve performance. A materialized view +is a specialized denormalization-ish mechanism to optimize a category of +queries and requires the DBA to sweat the details. It is very hard to cache +things stochastically without writing a server. Trigger managed extracts +won't help you execute 1,000 programs issuing the query "select sec_level +from sec where division=23" each second or a big table loaded monthly.) + + + +----- Original Message ----- +From: "Jeff" +To: "Mitch Pirtle" +Cc: "Aaron Werman" ; "Scott Kirkwood" +; "Neil Conway" ; +; "Tom Lane" +Sent: Monday, September 27, 2004 2:25 PM +Subject: Re: [PERFORM] Caching of Queries + + +> [ discussion of server side result caching ] +> +> and lets not forget PG's major fork it will throw into things: MVCC +> The results of query A may hold true for txn 1, but not txn 2 and so on +> . +> That would have to be taken into account as well and would greatly +> complicate things. +> +> It is always possible to do a "poor man"'s query cache with triggers.. +> which would just leave you with basically a materialized view. +> +> -- +> Jeff Trout +> http://www.jefftrout.com/ +> http://www.stuarthamm.net/ +> +> +> ---------------------------(end of broadcast)--------------------------- +> TIP 8: explain analyze is your friend +> + +From pgsql-performance-owner@postgresql.org Mon Sep 27 21:21:55 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 77CC2329F89 + for ; + Mon, 27 Sep 2004 21:21:53 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 24746-05 + for ; + Mon, 27 Sep 2004 20:21:46 +0000 (GMT) +Received: from bayswater1.ymogen.net (host-154-240-27-217.pobox.net.uk + [217.27.240.154]) + by svr1.postgresql.org (Postfix) with ESMTP id E8533329EE0 + for ; + Mon, 27 Sep 2004 21:21:46 +0100 (BST) +Received: from [82.68.132.233] (82-68-132-233.dsl.in-addr.zen.co.uk + [82.68.132.233]) by bayswater1.ymogen.net (Postfix) with ESMTP + id 1EA959E36A; Mon, 27 Sep 2004 21:21:46 +0100 (BST) +Message-ID: <415875C0.3010805@ymogen.net> +Date: Mon, 27 Sep 2004 21:19:12 +0100 +From: Matt Clark +User-Agent: Mozilla Thunderbird 0.7.3 (Windows/20040803) +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: Mitch Pirtle +Cc: pgsql-performance@postgresql.org +Subject: Re: Caching of Queries +References: + <00e801c4a4b6$5526dd30$8300a8c0@solent> + <330532b604092711591491303a@mail.gmail.com> +In-Reply-To: <330532b604092711591491303a@mail.gmail.com> +Content-Type: text/plain; charset=ISO-8859-1; format=flowed +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/294 +X-Sequence-Number: 8422 + + +>Basically you set a default in seconds for the HTML results to be +>cached, and then have triggers set that force the cache to regenerate +>(whenever CRUD happens to the content, for example). +> +>Can't speak for Perl/Python/Ruby/.Net/Java, but Cache_Lite sure made a +>believer out of me! +> +> +> +Nice to have it in a library, but if you want to be that simplistic then +it's easy in any language. What if a process on server B modifies a n +important value that server A has cached though? Coherency (albeit that +the client may choose to not use it) is a must for a general solution. + +From pgsql-performance-owner@postgresql.org Mon Sep 27 21:33:18 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 581EF329F45 + for ; + Mon, 27 Sep 2004 21:33:13 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 31264-05 + for ; + Mon, 27 Sep 2004 20:33:04 +0000 (GMT) +Received: from bayswater1.ymogen.net (host-154-240-27-217.pobox.net.uk + [217.27.240.154]) + by svr1.postgresql.org (Postfix) with ESMTP id 57A8B329CD9 + for ; + Mon, 27 Sep 2004 21:33:06 +0100 (BST) +Received: from [82.68.132.233] (82-68-132-233.dsl.in-addr.zen.co.uk + [82.68.132.233]) by bayswater1.ymogen.net (Postfix) with ESMTP + id 59BC99EA7A; Mon, 27 Sep 2004 21:33:05 +0100 (BST) +Message-ID: <41587867.4090505@ymogen.net> +Date: Mon, 27 Sep 2004 21:30:31 +0100 +From: Matt Clark +User-Agent: Mozilla Thunderbird 0.7.3 (Windows/20040803) +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: Rod Taylor +Cc: 'Aaron Werman' , + 'Scott Kirkwood' , + Postgresql Performance +Subject: Re: Caching of Queries +References: <00e801c4a4b6$5526dd30$8300a8c0@solent> + <1096306670.40463.173.camel@jester> +In-Reply-To: <1096306670.40463.173.camel@jester> +Content-Type: text/plain; charset=ISO-8859-1; format=flowed +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/295 +X-Sequence-Number: 8423 + + +>It might be easiest to shove the caching logic into pgpool instead. +> +>... +> +>When pg_pool is told to cache a query, it can get a table list and +>monitor for changes. When it gets changes, simply dumps the cache. +> +> +> +> +It's certainly the case that the typical web app (which, along with +warehouses, seems to be one half of the needy apps), could probably do +worse than use pooling as well. I'm not well up enough on pooling to +know how bulletproof it is though, which is why I included it in my list +of things that make me go 'hmm....'. It would be really nice not to +have to take both things together. + +More to the point though, I think this is a feature that really really +should be in the DB, because then it's trivial for people to use. +Taking an existing production app and justifying a switch to an extra +layer of pooling software is relatively hard compared with grabbing data +from a view instead of a table (or setting a variable, or adding a tweak +to a query, or however else it might be implemented). + +Eminiently doable in pgpool though, and just the right thing for anyone +already using it. + +M + +From pgsql-performance-owner@postgresql.org Mon Sep 27 21:37:46 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 71A2C329FA1 + for ; + Mon, 27 Sep 2004 21:37:38 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 32447-02 + for ; + Mon, 27 Sep 2004 20:37:31 +0000 (GMT) +Received: from tht.net (vista.tht.net [216.126.88.2]) + by svr1.postgresql.org (Postfix) with ESMTP id 00207329F7E + for ; + Mon, 27 Sep 2004 21:37:32 +0100 (BST) +Received: from [134.22.69.205] (dyn-69-205.tor.dsl.tht.net [134.22.69.205]) + by tht.net (Postfix) with ESMTP + id 5551376AA7; Mon, 27 Sep 2004 16:37:35 -0400 (EDT) +Subject: Re: Caching of Queries +From: Rod Taylor +To: Matt Clark +Cc: 'Aaron Werman' , + 'Scott Kirkwood' , + Postgresql Performance +In-Reply-To: <41587867.4090505@ymogen.net> +References: <00e801c4a4b6$5526dd30$8300a8c0@solent> + <1096306670.40463.173.camel@jester> <41587867.4090505@ymogen.net> +Content-Type: text/plain +Message-Id: <1096317453.40463.226.camel@jester> +Mime-Version: 1.0 +X-Mailer: Ximian Evolution 1.4.6 +Date: Mon, 27 Sep 2004 16:37:34 -0400 +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/296 +X-Sequence-Number: 8424 + +> More to the point though, I think this is a feature that really really +> should be in the DB, because then it's trivial for people to use. + +How does putting it into PGPool make it any less trivial for people to +use? + + +From pgsql-performance-owner@postgresql.org Mon Sep 27 21:41:58 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id CC4CE32A009 + for ; + Mon, 27 Sep 2004 21:41:56 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 32733-07 + for ; + Mon, 27 Sep 2004 20:41:49 +0000 (GMT) +Received: from pns.mm.eutelsat.org (pns.mm.eutelsat.org [194.214.173.227]) + by svr1.postgresql.org (Postfix) with ESMTP id E1F5832A007 + for ; + Mon, 27 Sep 2004 21:41:49 +0100 (BST) +Received: from nts-03.mm.eutelsat.org (localhost [127.0.0.1]) + by pns.mm.eutelsat.org (8.11.6/linuxconf) with ESMTP id i8RKeC404285; + Mon, 27 Sep 2004 22:40:13 +0200 +Received: from [127.0.0.1] (accesspoint.mm.eutelsat.org [194.214.173.4]) + by nts-03.mm.eutelsat.org (8.11.6/linuxconf) with ESMTP id i8RKfgV07053; + Mon, 27 Sep 2004 22:41:42 +0200 +Message-ID: <41587AF5.3060904@bigfoot.com> +Date: Mon, 27 Sep 2004 22:41:25 +0200 +From: Gaetano Mendola +User-Agent: Mozilla Thunderbird 0.8 (Windows/20040913) +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: josh@agliodbs.com +Cc: pgsql-performance@postgresql.org +Subject: Re: best statistic target for boolean columns +References: + <200409271131.09932.josh@agliodbs.com> +In-Reply-To: <200409271131.09932.josh@agliodbs.com> +X-Enigmail-Version: 0.86.1.0 +X-Enigmail-Supports: pgp-inline, pgp-mime +Content-Type: text/plain; charset=ISO-8859-1; format=flowed +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/297 +X-Sequence-Number: 8425 + +-----BEGIN PGP SIGNED MESSAGE----- +Hash: SHA1 + +Josh Berkus wrote: +| Gaetano, +| +| +|>don't you think the best statistic target for a boolean +|>column is something like 2? Or in general the is useless +|>have a statistics target > data type cardinality ? +| +| +| It depends, really, on the proportionality of the boolean values; if they're +| about equal, I certainly wouldn't raise Stats from the default of 10. If, +| however, it's very dispraportionate -- like 2% true and 98% false -- then it +| may pay to have better statistics so that the planner doesn't assume 50% +| hits, which it otherwise might. + +So, I didn't understand how the statistics hystogram works. +I'm going to take a look at analyze.c + + +Regards +Gaetano Mendola + + +-----BEGIN PGP SIGNATURE----- +Version: GnuPG v1.2.5 (MingW32) +Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org + +iD8DBQFBWHr07UpzwH2SGd4RAi8nAJoDOa7j+5IjDEcqBvB4ATXRzRPB+wCfWZ0p +OCmUew9zlyqVkxB9iWKoGAw= +=7lkZ +-----END PGP SIGNATURE----- + + +From pgsql-performance-owner@postgresql.org Mon Sep 27 21:46:52 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id DCE00329F43 + for ; + Mon, 27 Sep 2004 21:46:50 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 35506-05 + for ; + Mon, 27 Sep 2004 20:46:43 +0000 (GMT) +Received: from gp.word-to-the-wise.com (gp.word-to-the-wise.com + [64.71.176.18]) + by svr1.postgresql.org (Postfix) with ESMTP id 4C2E7329DBF + for ; + Mon, 27 Sep 2004 21:46:44 +0100 (BST) +Received: by gp.word-to-the-wise.com (Postfix, from userid 500) + id CBA9290005F; Mon, 27 Sep 2004 13:53:45 -0700 (PDT) +Date: Mon, 27 Sep 2004 13:53:45 -0700 +From: Steve Atkins +To: pgsql-performance@postgresql.org +Subject: Re: Caching of Queries +Message-ID: <20040927205345.GA29554@gp.word-to-the-wise.com> +References: + <00e801c4a4b6$5526dd30$8300a8c0@solent> + <330532b604092711591491303a@mail.gmail.com> + <415875C0.3010805@ymogen.net> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <415875C0.3010805@ymogen.net> +User-Agent: Mutt/1.4.1i +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/298 +X-Sequence-Number: 8426 + +On Mon, Sep 27, 2004 at 09:19:12PM +0100, Matt Clark wrote: + +> >Basically you set a default in seconds for the HTML results to be +> >cached, and then have triggers set that force the cache to regenerate +> >(whenever CRUD happens to the content, for example). +> > +> >Can't speak for Perl/Python/Ruby/.Net/Java, but Cache_Lite sure made a +> >believer out of me! +> > +> > +> > +> Nice to have it in a library, but if you want to be that simplistic then +> it's easy in any language. What if a process on server B modifies a n +> important value that server A has cached though? Coherency (albeit that +> the client may choose to not use it) is a must for a general solution. + +memcached is one solution designed for that situation. Easy to use +from most languages. Works. Lets you use memory on systems where you +have it, rather than using up valuable database server RAM that's +better spent caching disk sectors. + +Any competently written application where caching results would be a +suitable performance boost can already implement application or +middleware caching fairly easily, and increase performance much more +than putting result caching into the database would. + +I don't see caching results in the database as much of a win for most +well written applications. Toy benchmarks, sure, but for real apps it +seems it would add a lot of complexity, and violate the whole point of +using an ACID database. + +(Caching parse trees or query plans, though? It'd be interesting to + model what effect that'd have.) + +Cheers, + Steve + + +From pgsql-performance-owner@postgresql.org Mon Sep 27 22:38:39 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 65EEC329EAD + for ; + Mon, 27 Sep 2004 22:38:36 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 54487-04 + for ; + Mon, 27 Sep 2004 21:38:16 +0000 (GMT) +Received: from bayswater1.ymogen.net (host-154-240-27-217.pobox.net.uk + [217.27.240.154]) + by svr1.postgresql.org (Postfix) with ESMTP id 4216D329E93 + for ; + Mon, 27 Sep 2004 22:38:17 +0100 (BST) +Received: from [82.68.132.233] (82-68-132-233.dsl.in-addr.zen.co.uk + [82.68.132.233]) by bayswater1.ymogen.net (Postfix) with ESMTP + id 7DCCC9EAA1; Mon, 27 Sep 2004 22:38:16 +0100 (BST) +Message-ID: <415887AE.6070909@ymogen.net> +Date: Mon, 27 Sep 2004 22:35:42 +0100 +From: Matt Clark +User-Agent: Mozilla Thunderbird 0.7.3 (Windows/20040803) +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: Rod Taylor +Cc: 'Aaron Werman' , + 'Scott Kirkwood' , + Postgresql Performance +Subject: Re: Caching of Queries +References: <00e801c4a4b6$5526dd30$8300a8c0@solent> + <1096306670.40463.173.camel@jester> <41587867.4090505@ymogen.net> + <1096317453.40463.226.camel@jester> +In-Reply-To: <1096317453.40463.226.camel@jester> +Content-Type: multipart/alternative; + boundary="------------000803080104020300080009" +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.5 tagged_above=0.0 required=5.0 tests=HTML_MESSAGE, + HTML_TITLE_EMPTY +X-Spam-Level: +X-Archive-Number: 200409/299 +X-Sequence-Number: 8427 + +This is a multi-part message in MIME format. +--------------000803080104020300080009 +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit + + +>>More to the point though, I think this is a feature that really really +>>should be in the DB, because then it's trivial for people to use. +>> +>> +> +>How does putting it into PGPool make it any less trivial for people to +>use? +> +The answers are at http://www2b.biglobe.ne.jp/~caco/pgpool/index-e.html +. Specifically, it's a separate application that needs configuration, +the homepage has no real discussion of the potential pitfalls of pooling +and what this implementation does to get around them, you get the idea. +I'm sure it's great software, but it doesn't come as part of the DB +server, so 95% of people who would benefit from query caching being +implemented in it never will. If it shipped with and was turned on by +default in SUSE or RedHat that would be a different matter. Which I +realise makes me look like one of those people who doesn't appreciate +code unless it's 'popular', but I hope I'm not *that* bad... + +Oh OK, I'll say it, this is a perfect example of why My*** has so much +more mindshare. It's not better, but it sure makes the average Joe +_feel_ better. Sorry, I've got my corporate hat on today, I'm sure I'll +feel a little less cynical tomorrow. + +M + +--------------000803080104020300080009 +Content-Type: text/html; charset=us-ascii +Content-Transfer-Encoding: 7bit + + + + + + + + +
+
+
+
More to the point though, I think this is a feature that really really 
+should be in the DB, because then it's trivial for people to use.  
+    
+
+

+How does putting it into PGPool make it any less trivial for people to
+use?
+
+The answers are at  +http://www2b.biglobe.ne.jp/~caco/pgpool/index-e.html .  Specifically, +it's a separate application that needs configuration, the homepage has +no real discussion of the potential pitfalls of pooling and what this +implementation does to get around them, you get the idea.  I'm sure +it's great software, but it doesn't come as part of the DB server, so +95% of people who would benefit from query caching being implemented in +it never will.  If it shipped with and was turned on by default in SUSE +or RedHat that would be a different matter.  Which I realise makes me +look like one of those people who doesn't appreciate code unless it's +'popular', but I hope I'm not *that* bad...
+
+Oh OK, I'll say it, this is a perfect example of why My*** has so much +more mindshare.  It's not better, but it sure makes the average Joe +_feel_ better.  Sorry, I've got my corporate hat on today, I'm sure +I'll feel a little less cynical tomorrow.
+
+M
+ + + +--------------000803080104020300080009-- + +From pgsql-performance-owner@postgresql.org Mon Sep 27 22:44:42 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id A6052329EFE + for ; + Mon, 27 Sep 2004 22:44:28 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 55948-01 + for ; + Mon, 27 Sep 2004 21:44:25 +0000 (GMT) +Received: from bayswater1.ymogen.net (host-154-240-27-217.pobox.net.uk + [217.27.240.154]) + by svr1.postgresql.org (Postfix) with ESMTP id 33636329EC3 + for ; + Mon, 27 Sep 2004 22:44:27 +0100 (BST) +Received: from [82.68.132.233] (82-68-132-233.dsl.in-addr.zen.co.uk + [82.68.132.233]) by bayswater1.ymogen.net (Postfix) with ESMTP + id A2D679EA95; Mon, 27 Sep 2004 22:44:26 +0100 (BST) +Message-ID: <41588920.6020304@ymogen.net> +Date: Mon, 27 Sep 2004 22:41:52 +0100 +From: Matt Clark +User-Agent: Mozilla Thunderbird 0.7.3 (Windows/20040803) +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: Steve Atkins +Cc: pgsql-performance@postgresql.org +Subject: Re: Caching of Queries +References: + <00e801c4a4b6$5526dd30$8300a8c0@solent> + <330532b604092711591491303a@mail.gmail.com> + <415875C0.3010805@ymogen.net> + <20040927205345.GA29554@gp.word-to-the-wise.com> +In-Reply-To: <20040927205345.GA29554@gp.word-to-the-wise.com> +Content-Type: text/plain; charset=ISO-8859-1; format=flowed +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/300 +X-Sequence-Number: 8428 + + +>Any competently written application where caching results would be a +>suitable performance boost can already implement application or +>middleware caching fairly easily, and increase performance much more +>than putting result caching into the database would. +> +> +> +I guess the performance increase is that you can spend $10,000 on a +developer, or $10,000 on hardware, and for the most part get a more +reliable result the second way. MemcacheD is fine(ish), but it's not a +panacea, and it's more than easy to shoot yourself in the foot with it. +Caching is hard enough that lots of people do it badly - I'd rather use +an implementation from the PG team than almost anywhere else. + +>I don't see caching results in the database as much of a win for most +>well written applications. Toy benchmarks, sure, but for real apps it +>seems it would add a lot of complexity, and violate the whole point of +>using an ACID database. +> +> +> +Well the point surely is to _remove_ complexity from the application, +which is written by God Knows Who, and put it in the DB, which is +written by God And You. And you can still have ACID (cached data is not +the same as stale data, although once you have the former, the latter +can begin to look tempting sometimes). + +M + +From pgsql-performance-owner@postgresql.org Mon Sep 27 23:46:05 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 53B8E32A002 + for ; + Mon, 27 Sep 2004 23:45:59 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 68156-10 + for ; + Mon, 27 Sep 2004 22:45:39 +0000 (GMT) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by svr1.postgresql.org (Postfix) with ESMTP id CA682329F45 + for ; + Mon, 27 Sep 2004 23:45:40 +0100 (BST) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by news.hub.org (8.12.9/8.12.9) with ESMTP id i8RMjbfg073826 + for ; Mon, 27 Sep 2004 22:45:37 GMT + (envelope-from news@news.hub.org) +Received: (from news@localhost) + by news.hub.org (8.12.9/8.12.9/Submit) id i8RMgLG8072876 + for pgsql-performance@postgresql.org; Mon, 27 Sep 2004 22:42:21 GMT +From: Gaetano Mendola +X-Newsgroups: comp.databases.postgresql.performance +Subject: Re: best statistic target for boolean columns +Date: Tue, 28 Sep 2004 00:42:06 +0200 +Organization: PYRENET Midi-pyrenees Provider +Lines: 49 +Message-ID: <4158973E.7010408@bigfoot.com> +References: <87k6uf7ceu.fsf@stark.xeocode.com> <3481.1096313192@sss.pgh.pa.us> +Mime-Version: 1.0 +Content-Type: text/plain; charset=ISO-8859-1; format=flowed +Content-Transfer-Encoding: 7bit +X-Complaints-To: abuse@pyrenet.fr +To: Tom Lane +User-Agent: Mozilla Thunderbird 0.8 (Windows/20040913) +X-Accept-Language: en-us, en +In-Reply-To: <3481.1096313192@sss.pgh.pa.us> +X-Enigmail-Version: 0.86.1.0 +X-Enigmail-Supports: pgp-inline, pgp-mime +To: pgsql-performance@postgresql.org +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/301 +X-Sequence-Number: 8429 + +Tom Lane wrote: +> Gregory Stark writes: +> +>>No, actually the stats table keeps the n most common values and their +>>frequency (usually in percentage). So really a target of 2 ought to be enough +>>for boolean values. In fact that's all I see in pg_statistic; I'm assuming +>>there's a full histogram somewhere but I don't see it. Where would it be? +> +> +> It's not going to be there. The histogram only covers values that are +> not in the most-frequent-values list, and therefore it won't exist for a +> column that is completely describable by most-frequent-values. +> +> +>>However the target also dictates how large a sample of the table to take. A +>>target of two represents a very small sample. So the estimations could be +>>quite far off. +> +> +> Right. The real point of stats target for such columns is that it +> determines how many rows to sample, and thereby indirectly implies +> the accuracy of the statistics. For a heavily skewed boolean column +> you'd want a high target so that the number of occurrences of the +> infrequent value would be estimated accurately. +> +> It's also worth noting that the number of rows sampled is driven by the +> largest per-column stats target in the table, and so reducing stats +> target to 2 for a boolean column will save *zero* effort unless all the +> columns in the table are booleans. + +Thank you all, now I have more clear how it works. +Btw last time I was thinking: why during an explain analyze we can not use +the information on about the really extracted rows vs the extimated rows ? + +Now I'm reading an article, written by the same author that ispired the magic "300" +on analyze.c, about "Self-tuning Histograms". If this is implemented, I understood +we can take rid of "vacuum analyze" for mantain up to date the statistics. +Have someone in his plans to implement it ? +After all the idea is simple: compare during normal selects the extimated rows and +the actual extracted rows then use this "free" information to refine the histograms. + + + + +Regards +Gaetano Mendola + + + + +From pgsql-performance-owner@postgresql.org Tue Sep 28 00:46:46 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id CCB53329E7B + for ; + Tue, 28 Sep 2004 00:44:18 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 90120-01 + for ; + Mon, 27 Sep 2004 23:44:11 +0000 (GMT) +Received: from sue.samurai.com (sue.samurai.com [205.207.28.74]) + by svr1.postgresql.org (Postfix) with ESMTP id 016CE32A025 + for ; + Tue, 28 Sep 2004 00:44:11 +0100 (BST) +Received: from localhost (localhost [127.0.0.1]) + by sue.samurai.com (Postfix) with ESMTP id 28AF63ED7; + Mon, 27 Sep 2004 19:44:11 -0400 (EDT) +Received: from sue.samurai.com ([127.0.0.1]) + by localhost (sue.samurai.com [127.0.0.1]) (amavisd-new, port 10024) + with LMTP id 19635-01-6; Mon, 27 Sep 2004 19:44:10 -0400 (EDT) +Received: from localhost (unknown [61.88.101.19]) + by sue.samurai.com (Postfix) with ESMTP id 47BBB3ECD; + Mon, 27 Sep 2004 19:44:09 -0400 (EDT) +Subject: Re: best statistic target for boolean columns +From: Neil Conway +To: Gaetano Mendola +Cc: Tom Lane , pgsql-performance@postgresql.org +In-Reply-To: <4158973E.7010408@bigfoot.com> +References: <87k6uf7ceu.fsf@stark.xeocode.com> + <3481.1096313192@sss.pgh.pa.us> <4158973E.7010408@bigfoot.com> +Content-Type: text/plain +Message-Id: <1096328625.25688.755.camel@localhost.localdomain> +Mime-Version: 1.0 +X-Mailer: Ximian Evolution 1.4.6 +Date: Tue, 28 Sep 2004 09:43:45 +1000 +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at mailbox.samurai.com +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/302 +X-Sequence-Number: 8430 + +On Tue, 2004-09-28 at 08:42, Gaetano Mendola wrote: +> Now I'm reading an article, written by the same author that ispired the magic "300" +> on analyze.c, about "Self-tuning Histograms". If this is implemented, I understood +> we can take rid of "vacuum analyze" for mantain up to date the statistics. +> Have someone in his plans to implement it ? + +http://www.mail-archive.com/pgsql-hackers@postgresql.org/msg17477.html + +Tom's reply is salient. I still think self-tuning histograms would be +worth looking at for the multi-dimensional case. + +-Neil + + + +From pgsql-performance-owner@postgresql.org Tue Sep 28 01:45:56 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id C6BC832A018 + for ; + Tue, 28 Sep 2004 01:45:48 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 04029-07 + for ; + Tue, 28 Sep 2004 00:45:38 +0000 (GMT) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by svr1.postgresql.org (Postfix) with ESMTP id 2C80432A015 + for ; + Tue, 28 Sep 2004 01:45:41 +0100 (BST) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by news.hub.org (8.12.9/8.12.9) with ESMTP id i8S0jcfg007860 + for ; Tue, 28 Sep 2004 00:45:38 GMT + (envelope-from news@news.hub.org) +Received: (from news@localhost) + by news.hub.org (8.12.9/8.12.9/Submit) id i8S0GcZR001743 + for pgsql-performance@postgresql.org; Tue, 28 Sep 2004 00:16:38 GMT +From: Gaetano Mendola +X-Newsgroups: comp.databases.postgresql.performance +Subject: Re: best statistic target for boolean columns +Date: Tue, 28 Sep 2004 02:16:28 +0200 +Organization: PYRENET Midi-pyrenees Provider +Lines: 21 +Message-ID: <4158AD5C.9090908@bigfoot.com> +References: <87k6uf7ceu.fsf@stark.xeocode.com> + <3481.1096313192@sss.pgh.pa.us> <4158973E.7010408@bigfoot.com> + <1096328625.25688.755.camel@localhost.localdomain> +Mime-Version: 1.0 +Content-Type: text/plain; charset=ISO-8859-1; format=flowed +Content-Transfer-Encoding: 7bit +X-Complaints-To: abuse@pyrenet.fr +To: Neil Conway +User-Agent: Mozilla Thunderbird 0.8 (Windows/20040913) +X-Accept-Language: en-us, en +In-Reply-To: <1096328625.25688.755.camel@localhost.localdomain> +X-Enigmail-Version: 0.86.1.0 +X-Enigmail-Supports: pgp-inline, pgp-mime +To: pgsql-performance@postgresql.org +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/303 +X-Sequence-Number: 8431 + +Neil Conway wrote: +> On Tue, 2004-09-28 at 08:42, Gaetano Mendola wrote: +> +>>Now I'm reading an article, written by the same author that ispired the magic "300" +>>on analyze.c, about "Self-tuning Histograms". If this is implemented, I understood +>>we can take rid of "vacuum analyze" for mantain up to date the statistics. +>>Have someone in his plans to implement it ? +> +> +> http://www.mail-archive.com/pgsql-hackers@postgresql.org/msg17477.html +> +> Tom's reply is salient. I still think self-tuning histograms would be +> worth looking at for the multi-dimensional case. + +I see. + + + +Regards +Gaetano Mendola + + +From pgsql-performance-owner@postgresql.org Tue Sep 28 03:06:55 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 52C2B32A096 + for ; + Tue, 28 Sep 2004 03:06:27 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 25485-05 + for ; + Tue, 28 Sep 2004 02:06:14 +0000 (GMT) +Received: from millenium.mst.co.jp (unknown [210.230.185.241]) + by svr1.postgresql.org (Postfix) with ESMTP id 9686A32A08F + for ; + Tue, 28 Sep 2004 03:06:16 +0100 (BST) +Received: from mst1x5r347kymb (lc12114 [192.168.1.114]) + by millenium.mst.co.jp (8.11.6p2/3.7W) with SMTP id i8S26Bq23771; + Tue, 28 Sep 2004 11:06:11 +0900 +Message-ID: <00b201c4a4ff$bd73b8b0$7201a8c0@mst1x5r347kymb> +From: "Iain" +To: "Jim C. Nasby" +Cc: +References: + <20040923152925.18234.qmail@web41114.mail.yahoo.com> + <20040927191836.GS1297@decibel.org> +Subject: Re: Caching of Queries +Date: Tue, 28 Sep 2004 11:06:17 +0900 +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 6.00.2800.1437 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/304 +X-Sequence-Number: 8432 + +Jim, + +I can only tell you (roughly) how it works wth Oracle, and it's a very well +documented and laboured point over there - it's the cornerstone of Oracle's +scalability architecture, so if you don't believe me, or my explanation is +just plain lacking, then it wouldn't be a bad idea to check it out. The +"other Tom" aka Tomas Kyte runs the Ask Tom site which is a great source of +info on this. It's also very well explained in his book "Expert one on one +Oracle" I think it was called. I havn't seen any reason yet as to why the +same issues shouldn't, don't or wouldn't apply to pg. + +Your comment is both right and wrong. Yes, metadata lookups are essentially +the same as as access methods for normal queries. Any time you read data in +the DB you have to place a shared lock, often called a latch - it's a +lightweight type of lock. The trouble is that while a data page can have +multiple latches set at any time, only 1 process can be placing a a latch +on a page at a time. This doesn't sound so serious so far, latches are +"lightweight" afterall, however... even in a database of a billion rows and +100+ tables, the database metadata is a very _small_ area. You must put +latches on the metadata tables to do optimization, so for example, if you +are optimizing a 10 table join, you must queue up 10 times to place your +latchs. You then do your optimization and queue up 10 more times to remove +your latches. In fact it is worse than this, because you won't queue up 10 +times it's more likely to be a hundred times since it is far more complex +than 1 latch per table being optimized (you will be looking up statistics +and other things). + +As I already said, even in a huge DB of a billion rows, these latches are +happening on a realatively small and concentrated data set - the metadata. +Even if there is no contention for the application data, the contention for +the metadata may be furious. Consider this scenario, you have a 1000 users +constantly submitting queries that must not only be soft parsed (SQL +statement syntax) but hard parsed (optimized) because you have no query +cache. Even if they are looking at completely different data, they'll all be +queuing up for latches on the same little patch of metadata. Doubling your +CPU speed or throwing in a fibre channel disk array will not help here, the +system smply won't scale. + +Tom Lane noted that since the query cache would be in shared memory the +contention issue does not go away. This is true, but I don't think that it's +hard to see that the amount of contention is consderably less in any system +that is taking advantage of the caching facility - ie applications using +bind variables to reduce hard parsing. However, badly written applications +(from the point of view of query cache utilization) could very well +experience a degradation in performance. This could be handled with an +option to disable caching - or even better to disable caching of any sql not +using binds. I don't think even the mighty Oracle has that option. + +As you may have guessed, my vote is for implementing a query cache that +includes plans. + +I have no specific preference as to data caching. It doesn't seem to be so +important to me. + +Regards +Iain + + + +> On Thu, Sep 23, 2004 at 08:29:25AM -0700, Mr Pink wrote: +> > Not knowing anything about the internals of pg, I don't know how this +relates, but in theory, +> > query plan caching is not just about saving time re-planning queries, +it's about scalability. +> > Optimizing queries requires shared locks on the database metadata, +which, as I understand it +> > causes contention and serialization, which kills scalability. +> +> One of the guru's can correct me if I'm wrong here, but AFAIK metadata +> lookups use essentially the same access methods as normal queries. This +> means MVCC is used and no locking is required. Even if locks were +> required, they would be shared read locks which wouldn't block each +> other. +> -- +> Jim C. Nasby, Database Consultant decibel@decibel.org +> Give your computer some brain candy! www.distributed.net Team #1828 +> +> Windows: "Where do you want to go today?" +> Linux: "Where do you want to go tomorrow?" +> FreeBSD: "Are you guys coming, or what?" +> +> ---------------------------(end of broadcast)--------------------------- +> TIP 8: explain analyze is your friend + + +From pgsql-performance-owner@postgresql.org Tue Sep 28 04:18:04 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 44D6F32A0E6 + for ; + Tue, 28 Sep 2004 04:17:48 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 40062-08 + for ; + Tue, 28 Sep 2004 03:17:46 +0000 (GMT) +Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) + by svr1.postgresql.org (Postfix) with ESMTP id 747CB32A07F + for ; + Tue, 28 Sep 2004 04:17:45 +0100 (BST) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id i8S3HetZ009618; + Mon, 27 Sep 2004 23:17:40 -0400 (EDT) +To: "Iain" +Cc: "Jim C. Nasby" , + pgsql-performance@postgresql.org +Subject: Re: Caching of Queries +In-reply-to: <00b201c4a4ff$bd73b8b0$7201a8c0@mst1x5r347kymb> +References: + <20040923152925.18234.qmail@web41114.mail.yahoo.com> + <20040927191836.GS1297@decibel.org> + <00b201c4a4ff$bd73b8b0$7201a8c0@mst1x5r347kymb> +Comments: In-reply-to "Iain" + message dated "Tue, 28 Sep 2004 11:06:17 +0900" +Date: Mon, 27 Sep 2004 23:17:40 -0400 +Message-ID: <9617.1096341460@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/305 +X-Sequence-Number: 8433 + +"Iain" writes: +> I can only tell you (roughly) how it works wth Oracle, + +Which unfortunately has little to do with how it works with Postgres. +This "latches" stuff is irrelevant to us. + +In practice, any repetitive planning in PG is going to be consulting +catalog rows that it draws from the backend's local catalog caches. +After the first read of a given catalog row, the backend won't need +to re-read it unless the associated table has a schema update. (There +are some other cases, like a VACUUM FULL of the catalog the rows came +from, but in practice catalog cache entries don't change often in most +scenarios.) We need place only one lock per table referenced in order +to interlock against schema updates; not one per catalog row used. + +The upshot of all this is that any sort of shared plan cache is going to +create substantially more contention than exists now --- and that's not +even counting the costs of managing the cache, ie deciding when to throw +away entries. + +A backend-local plan cache would avoid the contention issues, but would +of course not allow amortizing planning costs across multiple backends. + +I'm personally dubious that sharing planning costs is a big deal. +Simple queries generally don't take that long to plan. Complicated +queries do, but I think the reusability odds go down with increasing +query complexity. + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Tue Sep 28 05:47:35 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 7FFC632A088 + for ; + Tue, 28 Sep 2004 05:47:33 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 61675-06 + for ; + Tue, 28 Sep 2004 04:47:31 +0000 (GMT) +Received: from millenium.mst.co.jp (unknown [210.230.185.241]) + by svr1.postgresql.org (Postfix) with ESMTP id 6F2B732A0D1 + for ; + Tue, 28 Sep 2004 05:47:30 +0100 (BST) +Received: from mst1x5r347kymb (lc12114 [192.168.1.114]) + by millenium.mst.co.jp (8.11.6p2/3.7W) with SMTP id i8S4lOq24519; + Tue, 28 Sep 2004 13:47:24 +0900 +Message-ID: <00bd01c4a516$42fff230$7201a8c0@mst1x5r347kymb> +From: "Iain" +To: "Tom Lane" +Cc: "Jim C. Nasby" , + +References: + <20040923152925.18234.qmail@web41114.mail.yahoo.com> + <20040927191836.GS1297@decibel.org> + <00b201c4a4ff$bd73b8b0$7201a8c0@mst1x5r347kymb> + <9617.1096341460@sss.pgh.pa.us> +Subject: Re: Caching of Queries +Date: Tue, 28 Sep 2004 13:47:30 +0900 +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-2022-jp" +Content-Transfer-Encoding: 7bit +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 6.00.2800.1437 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/306 +X-Sequence-Number: 8434 + +Hi Tom, + +> This "latches" stuff is irrelevant to us. + +Well, that's good to know anyway, thanks for setting me straight. Maybe +Oracle could take a leaf out of PGs book instead of the other way around. I +recall that you mentioned the caching of the schema before, so even though I +assumed PG was latching the metadata, I had begun to wonder if it was +actually neccessary. + +While it7s obviously not as critical as I thought, I think there may still +be some potential for query caching by pg. It would be nice to have the +option anyway, as different applications have different needs. + +I think that re-use of SQL in applications (ie controlling the proliferation +of SQL statements that are minor variants of each other) is a good goal for +maintainability, even if it doesn't have a major impact on performance as it +seems you are suggesting in the case of pg. Even complex queries that must +be constructed dynamically typically only have a finite number of options +and can still use bind variables, so in a well tuned system, they should +still be viable candidates for caching (ie, if they aren't being bumped out +of the cache by thousands of little queries not using binds). + +I'll just finish by saying that, developing applications in a way that would +take advantage of any query caching still seems like good practice to me, +even if the target DBMS has no query caching. For now, that's what I plan to +do with future PG/Oracle/Hypersonic (my 3 favourite DBMSs) application +development anyway. + +Regards +Iain + + +----- Original Message ----- +From: "Tom Lane" +To: "Iain" +Cc: "Jim C. Nasby" ; +Sent: Tuesday, September 28, 2004 12:17 PM +Subject: Re: [PERFORM] Caching of Queries + + +> "Iain" writes: +> > I can only tell you (roughly) how it works wth Oracle, +> +> Which unfortunately has little to do with how it works with Postgres. +> This "latches" stuff is irrelevant to us. +> +> In practice, any repetitive planning in PG is going to be consulting +> catalog rows that it draws from the backend's local catalog caches. +> After the first read of a given catalog row, the backend won't need +> to re-read it unless the associated table has a schema update. (There +> are some other cases, like a VACUUM FULL of the catalog the rows came +> from, but in practice catalog cache entries don't change often in most +> scenarios.) We need place only one lock per table referenced in order +> to interlock against schema updates; not one per catalog row used. +> +> The upshot of all this is that any sort of shared plan cache is going to +> create substantially more contention than exists now --- and that's not +> even counting the costs of managing the cache, ie deciding when to throw +> away entries. +> +> A backend-local plan cache would avoid the contention issues, but would +> of course not allow amortizing planning costs across multiple backends. +> +> I'm personally dubious that sharing planning costs is a big deal. +> Simple queries generally don't take that long to plan. Complicated +> queries do, but I think the reusability odds go down with increasing +> query complexity. +> +> regards, tom lane +> +> ---------------------------(end of broadcast)--------------------------- +> TIP 6: Have you searched our list archives? +> +> http://archives.postgresql.org + + +From pgsql-performance-owner@postgresql.org Tue Sep 28 14:14:02 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 3FF6032A083 + for ; + Tue, 28 Sep 2004 14:13:59 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 24625-01 + for ; + Tue, 28 Sep 2004 13:13:46 +0000 (GMT) +Received: from hotmail.com (bay18-dav12.bay18.hotmail.com [65.54.187.192]) + by svr1.postgresql.org (Postfix) with ESMTP id 61AB5329FE2 + for ; + Tue, 28 Sep 2004 14:13:48 +0100 (BST) +Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; + Tue, 28 Sep 2004 06:05:01 -0700 +Received: from 67.81.98.198 by bay18-dav12.bay18.hotmail.com with DAV; + Tue, 28 Sep 2004 13:04:34 +0000 +X-Originating-IP: [67.81.98.198] +X-Originating-Email: [awerman2@hotmail.com] +X-Sender: awerman2@hotmail.com +From: "Aaron Werman" +To: "Iain" , "Tom Lane" +Cc: "Jim C. Nasby" , + +References: + <20040923152925.18234.qmail@web41114.mail.yahoo.com> + <20040927191836.GS1297@decibel.org> + <00b201c4a4ff$bd73b8b0$7201a8c0@mst1x5r347kymb> + <9617.1096341460@sss.pgh.pa.us> +Subject: Re: Caching of Queries +Date: Tue, 28 Sep 2004 09:04:34 -0400 +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 6.00.2800.1437 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 +Message-ID: +X-OriginalArrivalTime: 28 Sep 2004 13:05:01.0093 (UTC) + FILETIME=[C354AD50:01C4A55B] +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/307 +X-Sequence-Number: 8435 + + +----- Original Message ----- +From: "Tom Lane" +To: "Iain" +Cc: "Jim C. Nasby" ; +Sent: Monday, September 27, 2004 11:17 PM +Subject: Re: [PERFORM] Caching of Queries + + +> "Iain" writes: +> > I can only tell you (roughly) how it works wth Oracle, +> +> Which unfortunately has little to do with how it works with Postgres. +> This "latches" stuff is irrelevant to us. + +Latches are the Oracle term for semaphores. Both Oracle and pg use +semaphores and spin locks to serialize activity in critical sections. I +believe that the point that blocking/queuing reduces scalability is valid. + +> +> In practice, any repetitive planning in PG is going to be consulting +> catalog rows that it draws from the backend's local catalog caches. +> After the first read of a given catalog row, the backend won't need +> to re-read it unless the associated table has a schema update. (There +> are some other cases, like a VACUUM FULL of the catalog the rows came +> from, but in practice catalog cache entries don't change often in most +> scenarios.) We need place only one lock per table referenced in order +> to interlock against schema updates; not one per catalog row used. +> +> The upshot of all this is that any sort of shared plan cache is going to +> create substantially more contention than exists now --- and that's not +> even counting the costs of managing the cache, ie deciding when to throw +> away entries. + +I imagine a design where a shared plan cache would consist of the plans, +indexed by a statement hash and again by dependant objects. A statement to +be planned would be hashed and matched to the cache. DDL would need to +synchronously destroy all dependant plans. If each plan maintains a validity +flag, changing the cache wouldn't have to block so I don't see where there +would be contention. + +> +> A backend-local plan cache would avoid the contention issues, but would +> of course not allow amortizing planning costs across multiple backends. +> +> I'm personally dubious that sharing planning costs is a big deal. +> Simple queries generally don't take that long to plan. Complicated +> queries do, but I think the reusability odds go down with increasing +> query complexity. +> + +I think both the parse and planning are major tasks if the transaction rate +is high. Simple queries can easily take much longer to plan than execute, so +this is a scalability concern. Caching complicated queries is valuable - +apps seem to have lots of similar queries because they are intimately +related to the data model. + +> regards, tom lane +> +> ---------------------------(end of broadcast)--------------------------- +> TIP 6: Have you searched our list archives? +> +> http://archives.postgresql.org +> + +From pgsql-performance-owner@postgresql.org Tue Sep 28 14:59:32 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id AA33332A191 + for ; + Tue, 28 Sep 2004 14:59:30 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 42776-02 + for ; + Tue, 28 Sep 2004 13:59:17 +0000 (GMT) +Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) + by svr1.postgresql.org (Postfix) with ESMTP id 42A5032A082 + for ; + Tue, 28 Sep 2004 14:59:20 +0100 (BST) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id i8SDw1fl014084; + Tue, 28 Sep 2004 09:58:02 -0400 (EDT) +To: "Aaron Werman" +Cc: "Iain" , "Jim C. Nasby" , + pgsql-performance@postgresql.org +Subject: Re: Caching of Queries +In-reply-to: +References: + <20040923152925.18234.qmail@web41114.mail.yahoo.com> + <20040927191836.GS1297@decibel.org> + <00b201c4a4ff$bd73b8b0$7201a8c0@mst1x5r347kymb> + <9617.1096341460@sss.pgh.pa.us> + +Comments: In-reply-to "Aaron Werman" + message dated "Tue, 28 Sep 2004 09:04:34 -0400" +Date: Tue, 28 Sep 2004 09:58:01 -0400 +Message-ID: <14083.1096379881@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/308 +X-Sequence-Number: 8436 + +"Aaron Werman" writes: +> I imagine a design where a shared plan cache would consist of the plans, +> indexed by a statement hash and again by dependant objects. A statement to +> be planned would be hashed and matched to the cache. DDL would need to +> synchronously destroy all dependant plans. If each plan maintains a validity + ^^^^^^^^^^^^^ +> flag, changing the cache wouldn't have to block so I don't see where there + ^^^^^^^^^^^^^^^^^^^^^^ +> would be contention. + +You have contention to access a shared data structure *at all* -- for +instance readers must lock out writers. Or didn't you notice the self- +contradictions in what you just said? + +Our current scalability problems dictate reducing such contention, not +adding whole new sources of it. + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Tue Sep 28 15:20:24 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 5F406329FFA + for ; + Tue, 28 Sep 2004 15:20:22 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 53079-03 + for ; + Tue, 28 Sep 2004 14:20:15 +0000 (GMT) +Received: from rambo.iniquinet.com (rambo.iniquinet.com [69.39.89.10]) + by svr1.postgresql.org (Postfix) with ESMTP id CD77F329F18 + for ; + Tue, 28 Sep 2004 15:20:17 +0100 (BST) +Received: (qmail 20844 invoked by uid 1010); 28 Sep 2004 10:20:17 -0400 +Received: from Robert_Creager@LogicalChaos.org by rambo.iniquinet.com by uid + 1002 with qmail-scanner-1.20 (clamscan: 0.70. spamassassin: 2.64. + Clear:RC:0(216.150.208.13):SA:0(-4.6/6.0):. + Processed in 1.914515 secs); 28 Sep 2004 14:20:17 -0000 +Received: from static-13.mm.den.viawest.net (HELO thunder.mshome.net) + (perl?test@logicalchaos.org@216.150.208.13) + by rambo.iniquinet.com with AES256-SHA encrypted SMTP; + 28 Sep 2004 10:20:15 -0400 +Received: from localhost.localdomain (thunder.mshome.net [192.168.0.250]) + by thunder.mshome.net (Postfix) with ESMTP id F26F6A8237 + for ; + Tue, 28 Sep 2004 08:20:13 -0600 (MDT) +Received: from logicalchaos.org (thunder.mshome.net [192.168.0.250]) + by thunder.mshome.net (Postfix) with SMTP id F1984A8237 + for ; + Tue, 28 Sep 2004 08:20:08 -0600 (MDT) +Date: Tue, 28 Sep 2004 08:19:57 -0600 +From: Robert Creager +To: PGPerformance +Subject: This query is still running after 10 hours... +Message-Id: <20040928081957.7a317a95@thunder.mshome.net> +Organization: Starlight Vision, LLC. +X-Mailer: Sylpheed version 0.9.10claws (GTK+ 1.2.10; i586-mandrake-linux-gnu) +Mime-Version: 1.0 +Content-Type: multipart/signed; protocol="application/pgp-signature"; + micalg="pgp-sha1"; + boundary="Signature=_Tue__28_Sep_2004_08_19_57_-0600_SoHUPpVH+j8MtfL0" +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/309 +X-Sequence-Number: 8437 + +--Signature=_Tue__28_Sep_2004_08_19_57_-0600_SoHUPpVH+j8MtfL0 +Content-Type: text/plain; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit + + +Help? + +Normally, this query takes from 5 minutes to 2 hours to run. On this update, it's been running for more than 10 hours. + +Can it be helped? + +UPDATE obs_v +SET mag = obs_v.imag + zp.zero_v + cg.color_v * (obs_v.imag - i.imag), + use = true +FROM color_groups AS cg, zero_pair AS zp, obs_i AS i, files AS f, groups AS g +WHERE obs_v.star_id = i.star_id + AND obs_v.file_id = f.file_id + AND cg.group_id = g.group_id + AND g.night_id = f.night_id + AND g.group_id = $group_id + AND zp.pair_id = f.pair_id + +Hash Join (cost=130079.22..639663.94 rows=1590204 width=63) + Hash Cond: ("outer".star_id = "inner".star_id) + -> Seq Scan on obs_i i (cost=0.00..213658.19 rows=10391319 width=8) + -> Hash (cost=129094.19..129094.19 rows=77211 width=59) + -> Nested Loop (cost=250.69..129094.19 rows=77211 width=59) + -> Hash Join (cost=250.69..307.34 rows=67 width=12) + Hash Cond: ("outer".pair_id = "inner".pair_id) + -> Seq Scan on zero_pair zp (cost=0.00..43.32 rows=2532 width=8) + -> Hash (cost=250.40..250.40 rows=118 width=12) + -> Hash Join (cost=4.80..250.40 rows=118 width=12) + Hash Cond: ("outer".night_id = "inner".night_id) + -> Seq Scan on files f (cost=0.00..199.28 rows=9028 width=12) + -> Hash (cost=4.80..4.80 rows=1 width=8) + -> Nested Loop (cost=0.00..4.80 rows=1 width=8) + -> Seq Scan on color_groups cg (cost=0.00..2.84 rows=1 width=8) + Filter: (171 = group_id) + -> Seq Scan on groups g (cost=0.00..1.95 rows=1 width=8) + Filter: (group_id = 171) + -> Index Scan using obs_v_file_id_index on obs_v (cost=0.00..1893.23 rows=2317 width=51) + Index Cond: (obs_v.file_id = "outer".file_id) + +Table definitions: + +tassiv=# \d color_groups + Table "public.color_groups" + Column | Type | Modifiers +--------------+---------+--------------------------------------------------------------- + group_id | integer | not null default nextval('"color_groups_group_id_seq"'::text) + color_u | real | + color_b | real | + color_v | real | + color_r | real | + color_i | real | + max_residual | real | +Indexes: + "color_groups_pkey" primary key, btree (group_id) + "color_group_group_id_index" btree (group_id) + +tassiv=# \d zero_pair + Table "public.zero_pair" + Column | Type | Modifiers +---------+---------+----------- + pair_id | integer | not null + zero_u | real | default 0 + zero_b | real | default 0 + zero_v | real | default 0 + zero_r | real | default 0 + zero_i | real | default 0 +Indexes: + "zero_pair_pkey" primary key, btree (pair_id) +Foreign-key constraints: + "$1" FOREIGN KEY (pair_id) REFERENCES pairs(pair_id) ON DELETE CASCADE + +tassiv=# \d obs_v + Table "public.obs_v" + Column | Type | Modifiers +---------+---------+------------------------------------------------ + x | real | not null + y | real | not null + imag | real | not null + smag | real | not null + loc | spoint | not null + obs_id | integer | not null default nextval('"obs_id_seq"'::text) + file_id | integer | not null + use | boolean | default false + solve | boolean | default false + star_id | integer | + mag | real | +Indexes: + "obs_v_file_id_index" btree (file_id) + "obs_v_loc_index" gist (loc) + "obs_v_obs_id_index" btree (obs_id) + "obs_v_star_id_index" btree (star_id) + "obs_v_use_index" btree (use) +Foreign-key constraints: + "obs_v_files_constraint" FOREIGN KEY (file_id) REFERENCES files(file_id) ON DELETE CASCADE + "obs_v_star_id_constraint" FOREIGN KEY (star_id) REFERENCES catalog(star_id) ON DELETE SET NULL +Triggers: + obs_v_trig BEFORE INSERT OR DELETE OR UPDATE ON obs_v FOR EACH ROW EXECUTE PROCEDURE observations_trigger +() + +tassiv=# \d files + Table "public.files" + Column | Type | Modifiers +----------+-----------------------------+------------------------------------------------------- + file_id | integer | not null default nextval('"files_file_id_seq"'::text) + night_id | integer | + pair_id | integer | + name | character varying | not null + date | timestamp without time zone | +Indexes: + "files_pkey" primary key, btree (file_id) + "files_name_key" unique, btree (name) + "files_id_index" btree (file_id, night_id, pair_id) +Foreign-key constraints: + "$1" FOREIGN KEY (night_id) REFERENCES nights(night_id) ON UPDATE CASCADE ON DELETE CASCADE + "$2" FOREIGN KEY (pair_id) REFERENCES pairs(pair_id) ON DELETE CASCADE + +tassiv=# \d groups + Table "public.groups" + Column | Type | Modifiers +----------+---------+----------- + group_id | integer | not null + night_id | integer | not null +Indexes: + "groups_pkey" primary key, btree (group_id, night_id) +Foreign-key constraints: + "$1" FOREIGN KEY (group_id) REFERENCES color_groups(group_id) ON DELETE CASCADE + "$2" FOREIGN KEY (night_id) REFERENCES nights(night_id) ON DELETE CASCADE + +Server is a dual AMD2600+ with 2Gb mem: + +shared_buffers = 20000 # min 16, at least max_connections*2, 8KB each +sort_mem = 16000 # min 64, size in KB +max_fsm_pages = 100000 # min max_fsm_relations*16, 6 bytes each +max_fsm_relations = 5000 # min 100, ~50 bytes each +effective_cache_size = 100000 # typically 8KB each +random_page_cost = 2 # units are one sequential page +default_statistics_target = 500 # range 1-1000 + +Thanks, +Rob + +-- + 08:06:34 up 5 days, 10:33, 2 users, load average: 3.13, 3.29, 3.61 +Linux 2.6.5-02 #8 SMP Mon Jul 12 21:34:44 MDT 2004 + +--Signature=_Tue__28_Sep_2004_08_19_57_-0600_SoHUPpVH+j8MtfL0 +Content-Type: application/pgp-signature + +-----BEGIN PGP SIGNATURE----- +Version: GnuPG v1.2.4 (GNU/Linux) + +iEYEARECAAYFAkFZcxgACgkQLQ/DKuwDYznHAQCeMYm4FYYFH6GmNEus2CLMynKC +6E0AoIFJ4cMQbAnCTuP1thJjcS9HkVne +=ftuq +-----END PGP SIGNATURE----- + +--Signature=_Tue__28_Sep_2004_08_19_57_-0600_SoHUPpVH+j8MtfL0-- + + +From pgsql-performance-owner@postgresql.org Tue Sep 28 15:28:55 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id A9761329ED6 + for ; + Tue, 28 Sep 2004 15:28:53 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 55393-09 + for ; + Tue, 28 Sep 2004 14:28:48 +0000 (GMT) +Received: from mproxy.gmail.com (rproxy.gmail.com [64.233.170.194]) + by svr1.postgresql.org (Postfix) with ESMTP id D1B40329EAE + for ; + Tue, 28 Sep 2004 15:28:50 +0100 (BST) +Received: by mproxy.gmail.com with SMTP id 73so2765515rnk + for ; + Tue, 28 Sep 2004 07:28:47 -0700 (PDT) +Received: by 10.38.162.50 with SMTP id k50mr573003rne; + Tue, 28 Sep 2004 07:28:47 -0700 (PDT) +Received: by 10.38.165.21 with HTTP; Tue, 28 Sep 2004 07:28:47 -0700 (PDT) +Message-ID: +Date: Tue, 28 Sep 2004 09:28:47 -0500 +From: Kevin Barnard +Reply-To: Kevin Barnard +To: pgsql-performance@postgresql.org +Subject: Re: This query is still running after 10 hours... +In-Reply-To: +Mime-Version: 1.0 +Content-Type: text/plain; charset=US-ASCII +Content-Transfer-Encoding: 7bit +References: <20040928081957.7a317a95@thunder.mshome.net> + +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/310 +X-Sequence-Number: 8438 + +What does observations_trigger do? + + + +On Tue, 28 Sep 2004 08:19:57 -0600, Robert Creager + wrote: +> +> Help? +> +> Normally, this query takes from 5 minutes to 2 hours to run. On this update, it's been running for more than 10 hours. +> +> Can it be helped? +> +> UPDATE obs_v +> SET mag = obs_v.imag + zp.zero_v + cg.color_v * (obs_v.imag - i.imag), +> use = true +> FROM color_groups AS cg, zero_pair AS zp, obs_i AS i, files AS f, groups AS g +> WHERE obs_v.star_id = i.star_id +> AND obs_v.file_id = f.file_id +> AND cg.group_id = g.group_id +> AND g.night_id = f.night_id +> AND g.group_id = $group_id +> AND zp.pair_id = f.pair_id +> +> Hash Join (cost=130079.22..639663.94 rows=1590204 width=63) +> Hash Cond: ("outer".star_id = "inner".star_id) +> -> Seq Scan on obs_i i (cost=0.00..213658.19 rows=10391319 width=8) +> -> Hash (cost=129094.19..129094.19 rows=77211 width=59) +> -> Nested Loop (cost=250.69..129094.19 rows=77211 width=59) +> -> Hash Join (cost=250.69..307.34 rows=67 width=12) +> Hash Cond: ("outer".pair_id = "inner".pair_id) +> -> Seq Scan on zero_pair zp (cost=0.00..43.32 rows=2532 width=8) +> -> Hash (cost=250.40..250.40 rows=118 width=12) +> -> Hash Join (cost=4.80..250.40 rows=118 width=12) +> Hash Cond: ("outer".night_id = "inner".night_id) +> -> Seq Scan on files f (cost=0.00..199.28 rows=9028 width=12) +> -> Hash (cost=4.80..4.80 rows=1 width=8) +> -> Nested Loop (cost=0.00..4.80 rows=1 width=8) +> -> Seq Scan on color_groups cg (cost=0.00..2.84 rows=1 width=8) +> Filter: (171 = group_id) +> -> Seq Scan on groups g (cost=0.00..1.95 rows=1 width=8) +> Filter: (group_id = 171) +> -> Index Scan using obs_v_file_id_index on obs_v (cost=0.00..1893.23 rows=2317 width=51) +> Index Cond: (obs_v.file_id = "outer".file_id) +> +> Table definitions: +> +> tassiv=# \d color_groups +> Table "public.color_groups" +> Column | Type | Modifiers +> --------------+---------+--------------------------------------------------------------- +> group_id | integer | not null default nextval('"color_groups_group_id_seq"'::text) +> color_u | real | +> color_b | real | +> color_v | real | +> color_r | real | +> color_i | real | +> max_residual | real | +> Indexes: +> "color_groups_pkey" primary key, btree (group_id) +> "color_group_group_id_index" btree (group_id) +> +> tassiv=# \d zero_pair +> Table "public.zero_pair" +> Column | Type | Modifiers +> ---------+---------+----------- +> pair_id | integer | not null +> zero_u | real | default 0 +> zero_b | real | default 0 +> zero_v | real | default 0 +> zero_r | real | default 0 +> zero_i | real | default 0 +> Indexes: +> "zero_pair_pkey" primary key, btree (pair_id) +> Foreign-key constraints: +> "$1" FOREIGN KEY (pair_id) REFERENCES pairs(pair_id) ON DELETE CASCADE +> +> tassiv=# \d obs_v +> Table "public.obs_v" +> Column | Type | Modifiers +> ---------+---------+------------------------------------------------ +> x | real | not null +> y | real | not null +> imag | real | not null +> smag | real | not null +> loc | spoint | not null +> obs_id | integer | not null default nextval('"obs_id_seq"'::text) +> file_id | integer | not null +> use | boolean | default false +> solve | boolean | default false +> star_id | integer | +> mag | real | +> Indexes: +> "obs_v_file_id_index" btree (file_id) +> "obs_v_loc_index" gist (loc) +> "obs_v_obs_id_index" btree (obs_id) +> "obs_v_star_id_index" btree (star_id) +> "obs_v_use_index" btree (use) +> Foreign-key constraints: +> "obs_v_files_constraint" FOREIGN KEY (file_id) REFERENCES files(file_id) ON DELETE CASCADE +> "obs_v_star_id_constraint" FOREIGN KEY (star_id) REFERENCES catalog(star_id) ON DELETE SET NULL +> Triggers: +> obs_v_trig BEFORE INSERT OR DELETE OR UPDATE ON obs_v FOR EACH ROW EXECUTE PROCEDURE observations_trigger +> () +> +> tassiv=# \d files +> Table "public.files" +> Column | Type | Modifiers +> ----------+-----------------------------+------------------------------------------------------- +> file_id | integer | not null default nextval('"files_file_id_seq"'::text) +> night_id | integer | +> pair_id | integer | +> name | character varying | not null +> date | timestamp without time zone | +> Indexes: +> "files_pkey" primary key, btree (file_id) +> "files_name_key" unique, btree (name) +> "files_id_index" btree (file_id, night_id, pair_id) +> Foreign-key constraints: +> "$1" FOREIGN KEY (night_id) REFERENCES nights(night_id) ON UPDATE CASCADE ON DELETE CASCADE +> "$2" FOREIGN KEY (pair_id) REFERENCES pairs(pair_id) ON DELETE CASCADE +> +> tassiv=# \d groups +> Table "public.groups" +> Column | Type | Modifiers +> ----------+---------+----------- +> group_id | integer | not null +> night_id | integer | not null +> Indexes: +> "groups_pkey" primary key, btree (group_id, night_id) +> Foreign-key constraints: +> "$1" FOREIGN KEY (group_id) REFERENCES color_groups(group_id) ON DELETE CASCADE +> "$2" FOREIGN KEY (night_id) REFERENCES nights(night_id) ON DELETE CASCADE +> +> Server is a dual AMD2600+ with 2Gb mem: +> +> shared_buffers = 20000 # min 16, at least max_connections*2, 8KB each +> sort_mem = 16000 # min 64, size in KB +> max_fsm_pages = 100000 # min max_fsm_relations*16, 6 bytes each +> max_fsm_relations = 5000 # min 100, ~50 bytes each +> effective_cache_size = 100000 # typically 8KB each +> random_page_cost = 2 # units are one sequential page +> default_statistics_target = 500 # range 1-1000 +> +> Thanks, +> Rob +> +> -- +> 08:06:34 up 5 days, 10:33, 2 users, load average: 3.13, 3.29, 3.61 +> Linux 2.6.5-02 #8 SMP Mon Jul 12 21:34:44 MDT 2004 +> +> +> +> + +From pgsql-performance-owner@postgresql.org Tue Sep 28 15:37:21 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 4BA6732A08F + for ; + Tue, 28 Sep 2004 15:37:04 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 58603-06 + for ; + Tue, 28 Sep 2004 14:36:58 +0000 (GMT) +Received: from hotmail.com (bay18-dav2.bay18.hotmail.com [65.54.187.182]) + by svr1.postgresql.org (Postfix) with ESMTP id 4173F329FFE + for ; + Tue, 28 Sep 2004 15:37:01 +0100 (BST) +Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; + Tue, 28 Sep 2004 07:37:01 -0700 +Received: from 67.81.98.198 by bay18-dav2.bay18.hotmail.com with DAV; + Tue, 28 Sep 2004 14:36:02 +0000 +X-Originating-IP: [67.81.98.198] +X-Originating-Email: [awerman2@hotmail.com] +X-Sender: awerman2@hotmail.com +From: "Aaron Werman" +To: "Tom Lane" +Cc: +References: + <20040923152925.18234.qmail@web41114.mail.yahoo.com> + <20040927191836.GS1297@decibel.org> + <00b201c4a4ff$bd73b8b0$7201a8c0@mst1x5r347kymb> + <9617.1096341460@sss.pgh.pa.us> + + <14083.1096379881@sss.pgh.pa.us> +Subject: Re: Caching of Queries +Date: Tue, 28 Sep 2004 10:36:03 -0400 +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 6.00.2800.1437 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 +Message-ID: +X-OriginalArrivalTime: 28 Sep 2004 14:37:01.0307 (UTC) + FILETIME=[9DA27CB0:01C4A568] +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/311 +X-Sequence-Number: 8439 + + +----- Original Message ----- +From: "Tom Lane" +To: "Aaron Werman" +Cc: "Iain" ; "Jim C. Nasby" ; + +Sent: Tuesday, September 28, 2004 9:58 AM +Subject: Re: [PERFORM] Caching of Queries + + +> "Aaron Werman" writes: +> > I imagine a design where a shared plan cache would consist of the plans, +> > indexed by a statement hash and again by dependant objects. A statement +to +> > be planned would be hashed and matched to the cache. DDL would need to +> > synchronously destroy all dependant plans. If each plan maintains a +validity +> ^^^^^^^^^^^^^ +> > flag, changing the cache wouldn't have to block so I don't see where +there +> ^^^^^^^^^^^^^^^^^^^^^^ +> > would be contention. +> +> You have contention to access a shared data structure *at all* -- for +> instance readers must lock out writers. Or didn't you notice the self- +> contradictions in what you just said? +> +> Our current scalability problems dictate reducing such contention, not +> adding whole new sources of it. + +You're right - that seems unclear. What I meant is that there can be a +global hash table that is never locked, and the hashes point to chains of +plans that are only locally locked for maintenance, such as gc and chaining +hash collisions. If maintenance was relatively rare and only local, my +assumption is that it wouldn't have global impact. + +The nice thing about plan caching is that it can be sloppy, unlike block +cache, because it is only an optimization tweak. So, for example, if the +plan has atomic refererence times or counts there is no need to block, since +overwriting is not so bad. If the multiprocessing planner chains the same +plan twice, the second one would ultimately age out.... + +/Aaron + +> +> regards, tom lane +> + +From pgsql-performance-owner@postgresql.org Tue Sep 28 16:16:03 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id E5AA7329EFB + for ; + Tue, 28 Sep 2004 16:15:59 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 77744-04 + for ; + Tue, 28 Sep 2004 15:15:51 +0000 (GMT) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by svr1.postgresql.org (Postfix) with ESMTP id 2D507329C63 + for ; + Tue, 28 Sep 2004 16:15:50 +0100 (BST) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by news.hub.org (8.12.9/8.12.9) with ESMTP id i8SFFofg079419 + for ; Tue, 28 Sep 2004 15:15:50 GMT + (envelope-from news@news.hub.org) +Received: (from news@localhost) + by news.hub.org (8.12.9/8.12.9/Submit) id i8SEtK48070588 + for pgsql-performance@postgresql.org; Tue, 28 Sep 2004 14:55:20 GMT +From: Gaetano Mendola +X-Newsgroups: comp.databases.postgresql.performance +Subject: Re: This query is still running after 10 hours... +Date: Tue, 28 Sep 2004 16:55:13 +0200 +Organization: PYRENET Midi-pyrenees Provider +Lines: 15 +Message-ID: <41597B51.7040100@bigfoot.com> +References: <20040928081957.7a317a95@thunder.mshome.net> +Mime-Version: 1.0 +Content-Type: text/plain; charset=ISO-8859-1; format=flowed +Content-Transfer-Encoding: 7bit +X-Complaints-To: abuse@pyrenet.fr +To: Robert Creager +User-Agent: Mozilla Thunderbird 0.8 (Windows/20040913) +X-Accept-Language: en-us, en +In-Reply-To: <20040928081957.7a317a95@thunder.mshome.net> +X-Enigmail-Version: 0.86.1.0 +X-Enigmail-Supports: pgp-inline, pgp-mime +To: pgsql-performance@postgresql.org +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/313 +X-Sequence-Number: 8441 + +Robert Creager wrote: +> Help? +> +> Normally, this query takes from 5 minutes to 2 hours to run. On this update, it's been running for more than 10 hours. +> +> Can it be helped? + + +When I see this usually means that tables are full of +dead rows. Did you vacuum you DB. Which version are you +using ? + +Regards +Gaetano Mendola + + +From pgsql-performance-owner@postgresql.org Tue Sep 28 16:04:44 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 9746232A085 + for ; + Tue, 28 Sep 2004 16:04:34 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 73538-03 + for ; + Tue, 28 Sep 2004 15:04:28 +0000 (GMT) +Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) + by svr1.postgresql.org (Postfix) with ESMTP id D55C332A057 + for ; + Tue, 28 Sep 2004 16:04:26 +0100 (BST) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id i8SF4N5o014843; + Tue, 28 Sep 2004 11:04:23 -0400 (EDT) +To: Robert Creager +Cc: PGPerformance +Subject: Re: This query is still running after 10 hours... +In-reply-to: <20040928081957.7a317a95@thunder.mshome.net> +References: <20040928081957.7a317a95@thunder.mshome.net> +Comments: In-reply-to Robert Creager + message dated "Tue, 28 Sep 2004 08:19:57 -0600" +Date: Tue, 28 Sep 2004 11:04:23 -0400 +Message-ID: <14842.1096383863@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/312 +X-Sequence-Number: 8440 + +Robert Creager writes: +> Normally, this query takes from 5 minutes to 2 hours to run. On this update, it's been running for more than 10 hours. + +> ... +> -> Nested Loop (cost=250.69..129094.19 rows=77211 width=59) +> -> Hash Join (cost=250.69..307.34 rows=67 width=12) +> Hash Cond: ("outer".pair_id = "inner".pair_id) +> ... + +It chose a nested loop here because it was only expecting 67 rows out of +the next-lower join, and so it thought it would only need 67 repetitions +of the index probe into obs_v_file_id_index. I'm suspicious that that +estimate was way low and so the nestloop is taking forever. You might +try "SET enable_nestloop = off" as a crude way of avoiding that trap. + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Tue Sep 28 18:52:36 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 9575232A205 + for ; + Tue, 28 Sep 2004 18:52:34 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 24198-02 + for ; + Tue, 28 Sep 2004 17:52:24 +0000 (GMT) +Received: from davinci.ethosmedia.com (server226.ethosmedia.com + [209.128.84.226]) + by svr1.postgresql.org (Postfix) with ESMTP id 9DE6132A20D + for ; + Tue, 28 Sep 2004 18:52:16 +0100 (BST) +Received: from [64.81.245.111] (account josh@agliodbs.com HELO + temoku.sf.agliodbs.com) + by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.1.8) + with ESMTP id 6425795 for pgsql-performance@postgresql.org; + Tue, 28 Sep 2004 10:53:36 -0700 +From: Josh Berkus +Reply-To: josh@agliodbs.com +Organization: Aglio Database Solutions +To: pgsql-performance@postgresql.org +Subject: Interest in perf testing? +Date: Tue, 28 Sep 2004 10:53:53 -0700 +User-Agent: KMail/1.6.2 +MIME-Version: 1.0 +Content-Disposition: inline +Content-Type: text/plain; + charset="us-ascii" +Content-Transfer-Encoding: 7bit +Message-Id: <200409281053.53355.josh@agliodbs.com> +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/314 +X-Sequence-Number: 8442 + +Folks, + +I'm beginning a series of tests on OSDL's Scalable Test Platform in order to +determine some recommended settings for many of the new PostgreSQL.conf +parameters as well as pg_autovacuum. + +Is anyone else interested in helping me with this? + +-- +--Josh + +Josh Berkus +Aglio Database Solutions +San Francisco + +From pgsql-performance-owner@postgresql.org Wed Sep 29 02:37:58 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 5ECF332A08F + for ; + Wed, 29 Sep 2004 02:37:43 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 43978-01 + for ; + Wed, 29 Sep 2004 01:37:27 +0000 (GMT) +Received: from ms-smtp-01.tampabay.rr.com (ms-smtp-01-smtplb.tampabay.rr.com + [65.32.5.131]) + by svr1.postgresql.org (Postfix) with ESMTP id 3840632A054 + for ; + Wed, 29 Sep 2004 02:37:03 +0100 (BST) +Received: from MATTSPC (222-60.26-24.tampabay.rr.com [24.26.60.222]) + by ms-smtp-01.tampabay.rr.com (8.12.10/8.12.7) with ESMTP id + i8T1ajlM025548 for ; + Tue, 28 Sep 2004 21:36:46 -0400 (EDT) +Message-Id: <200409290136.i8T1ajlM025548@ms-smtp-01.tampabay.rr.com> +From: "Matthew Nuzum" +To: +Subject: Re: Caching of Queries +Date: Tue, 28 Sep 2004 21:36:43 -0400 +MIME-Version: 1.0 +Content-Type: text/plain; + charset="us-ascii" +Content-Transfer-Encoding: 7bit +X-Mailer: Microsoft Office Outlook, Build 11.0.5510 +In-reply-to: <18766.1096262336@sss.pgh.pa.us> +X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 +Thread-Index: AcSkUapRPlDQlE22TI6+ginXeb462QBaQT7A +X-Virus-Scanned: Symantec AntiVirus Scan Engine +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/315 +X-Sequence-Number: 8443 + +I could spend a week or two tweaking the performance of my database servers +and probably make some sizeable improvements, but I'm not going to. + +Why? Because PostgreSQL screams as it is. + +I would make sure that if the consensus is to add some sort of caching that +it be done only if there is no hit to current performance and stability. +That being said, I think that server side caching has major buzz and there's +nothing wrong with adding features that sell. + +I will disagree with 3 points made on the argument against caching. +Specifically, the benefit of doing caching on the db server is that the +benefits may be reaped by multiple clients where as caching on the client +side must be done by each client and may not be as effective. + +So what if the caching has a slight chance of returning stale results? Just +make sure people know about it in advance. There are some things where +stale results are no big deal and if I can easily benefit from an aggressive +caching system, I will (and I do now with the adodb caching library, but +like I said, caching has to be done for each client). In fact, I'm all for +using a low-tech cache expiration algorithm to keep complexity down. + +Finally, if the caching is not likely to help (or may even hurt) simple +queries but is likely to help complex queries then fine, make sure people +know about it and let them decide if they can benefit. + +Sorry if I'm beating a dead horse or playing the devil's advocate. Just +felt compelled to chime in. + +-- +Matthew Nuzum + "Man was born free, and everywhere +www.bearfruit.org : he is in chains," Rousseau ++~~~~~~~~~~~~~~~~~~+ "Then you will know the truth, and +the TRUTH will set you free," Jesus Christ (John 8:32 NIV) + +-----Original Message----- +From: pgsql-performance-owner@postgresql.org +[mailto:pgsql-performance-owner@postgresql.org] On Behalf Of Tom Lane +Sent: Monday, September 27, 2004 1:19 AM +To: Neil Conway +Cc: Aaron Werman; Scott Kirkwood; pgsql-performance@postgresql.org +Subject: Re: [PERFORM] Caching of Queries + +Neil Conway writes: +> I think the conclusion of past discussions about this feature is that +> it's a bad idea. Last I checked, MySQL has to clear the *entire* query +> cache when a single DML statement modifying the table in question is +> issued. + +Do they actually make a rigorous guarantee that the cached result is +still accurate when/if it is returned to the client? (That's an honest +question --- I don't know how MySQL implements this.) + +IIRC, in our past threads on this topic, it was suggested that if you +can tolerate not-necessarily-up-to-date results, you should be doing +this sort of caching on the client side and not in the DB server at all. +I wouldn't try that in a true "client" scenario, but when the DB client +is application-server middleware, it would make some sense to cache in +the application server. + + regards, tom lane + +---------------------------(end of broadcast)--------------------------- +TIP 2: you can get off all lists at once with the unregister command + (send "unregister YourEmailAddressHere" to majordomo@postgresql.org) + + +From pgsql-performance-owner@postgresql.org Wed Sep 29 03:22:49 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 87A2C32A18C + for ; + Wed, 29 Sep 2004 03:22:39 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 50039-08 + for ; + Wed, 29 Sep 2004 02:22:12 +0000 (GMT) +Received: from rambo.iniquinet.com (rambo.iniquinet.com [69.39.89.10]) + by svr1.postgresql.org (Postfix) with ESMTP id DD79C32A10A + for ; + Wed, 29 Sep 2004 03:22:01 +0100 (BST) +Received: (qmail 26466 invoked by uid 1010); 28 Sep 2004 22:21:58 -0400 +Received: from Robert_Creager@LogicalChaos.org by rambo.iniquinet.com by uid + 1002 with qmail-scanner-1.20 (clamscan: 0.70. spamassassin: 2.64. + Clear:RC:0(216.150.208.13):SA:0(-4.6/6.0):. + Processed in 1.060603 secs); 29 Sep 2004 02:21:58 -0000 +Received: from static-13.mm.den.viawest.net (HELO thunder.mshome.net) + (perl?test@logicalchaos.org@216.150.208.13) + by rambo.iniquinet.com with AES256-SHA encrypted SMTP; + 28 Sep 2004 22:21:57 -0400 +Received: from localhost.localdomain (thunder.mshome.net [192.168.0.250]) + by thunder.mshome.net (Postfix) with ESMTP id B3371A8237; + Tue, 28 Sep 2004 20:21:55 -0600 (MDT) +Received: from logicalchaos.org (thunder.mshome.net [192.168.0.250]) + by thunder.mshome.net (Postfix) with SMTP id 5C4EDA8237; + Tue, 28 Sep 2004 20:21:54 -0600 (MDT) +Date: Tue, 28 Sep 2004 20:21:40 -0600 +From: Robert Creager +To: Kevin Barnard +Cc: pgsql-performance@postgresql.org +Subject: Re: This query is still running after 10 hours... +Message-Id: <20040928202140.4ea9d090@thunder.mshome.net> +In-Reply-To: +References: <20040928081957.7a317a95@thunder.mshome.net> + + +Organization: Starlight Vision, LLC. +X-Mailer: Sylpheed version 0.9.10claws (GTK+ 1.2.10; i586-mandrake-linux-gnu) +Mime-Version: 1.0 +Content-Type: multipart/signed; protocol="application/pgp-signature"; + micalg="pgp-sha1"; + boundary="Signature=_Tue__28_Sep_2004_20_21_40_-0600_FIHAlQlsQoWvkbUY" +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/316 +X-Sequence-Number: 8444 + +--Signature=_Tue__28_Sep_2004_20_21_40_-0600_FIHAlQlsQoWvkbUY +Content-Type: text/plain; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit + +When grilled further on (Tue, 28 Sep 2004 09:28:47 -0500), +Kevin Barnard confessed: + +> What does observations_trigger do? +> + +The trigger keeps another table (catalog) up to date with the information from the obs_v and obs_i tables. There are no direct insert/update/delete's on the catalog table, only though the trigger. + +-- + 19:56:54 up 5 days, 22:23, 2 users, load average: 2.46, 2.27, 2.15 +Linux 2.6.5-02 #8 SMP Mon Jul 12 21:34:44 MDT 2004 + +--Signature=_Tue__28_Sep_2004_20_21_40_-0600_FIHAlQlsQoWvkbUY +Content-Type: application/pgp-signature + +-----BEGIN PGP SIGNATURE----- +Version: GnuPG v1.2.4 (GNU/Linux) + +iEYEARECAAYFAkFaHEIACgkQLQ/DKuwDYzkJcgCfUoVrTe2qEFOdGbAfBpZBbUGn +awkAn0pThr+hBRN97lTbBPj4meGgO63R +=e5Nt +-----END PGP SIGNATURE----- + +--Signature=_Tue__28_Sep_2004_20_21_40_-0600_FIHAlQlsQoWvkbUY-- + + +From pgsql-performance-owner@postgresql.org Wed Sep 29 03:26:02 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 1D18332A0DA + for ; + Wed, 29 Sep 2004 03:25:56 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 50949-06 + for ; + Wed, 29 Sep 2004 02:25:43 +0000 (GMT) +Received: from rambo.iniquinet.com (rambo.iniquinet.com [69.39.89.10]) + by svr1.postgresql.org (Postfix) with ESMTP id 901DC32A10C + for ; + Wed, 29 Sep 2004 03:25:30 +0100 (BST) +Received: (qmail 27183 invoked by uid 1010); 28 Sep 2004 22:25:20 -0400 +Received: from Robert_Creager@LogicalChaos.org by rambo.iniquinet.com by uid + 1002 with qmail-scanner-1.20 (clamscan: 0.70. spamassassin: 2.64. + Clear:RC:0(216.150.208.13):SA:0(-4.6/6.0):. + Processed in 1.051685 secs); 29 Sep 2004 02:25:20 -0000 +Received: from static-13.mm.den.viawest.net (HELO thunder.mshome.net) + (perl?test@logicalchaos.org@216.150.208.13) + by rambo.iniquinet.com with AES256-SHA encrypted SMTP; + 28 Sep 2004 22:25:19 -0400 +Received: from localhost.localdomain (thunder.mshome.net [192.168.0.250]) + by thunder.mshome.net (Postfix) with ESMTP id 92DC0A8237; + Tue, 28 Sep 2004 20:25:18 -0600 (MDT) +Received: from logicalchaos.org (thunder.mshome.net [192.168.0.250]) + by thunder.mshome.net (Postfix) with SMTP id 371B5A8237; + Tue, 28 Sep 2004 20:25:08 -0600 (MDT) +Date: Tue, 28 Sep 2004 20:25:07 -0600 +From: Robert Creager +To: Gaetano Mendola +Cc: pgsql-performance@postgresql.org +Subject: Re: This query is still running after 10 hours... +Message-Id: <20040928202507.7fbbdb7c@thunder.mshome.net> +In-Reply-To: <41597B51.7040100@bigfoot.com> +References: <20040928081957.7a317a95@thunder.mshome.net> + <41597B51.7040100@bigfoot.com> +Organization: Starlight Vision, LLC. +X-Mailer: Sylpheed version 0.9.10claws (GTK+ 1.2.10; i586-mandrake-linux-gnu) +Mime-Version: 1.0 +Content-Type: multipart/signed; protocol="application/pgp-signature"; + micalg="pgp-sha1"; + boundary="Signature=_Tue__28_Sep_2004_20_25_07_-0600_j=i95elLENMshOJ/" +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/317 +X-Sequence-Number: 8445 + +--Signature=_Tue__28_Sep_2004_20_25_07_-0600_j=i95elLENMshOJ/ +Content-Type: text/plain; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit + +When grilled further on (Tue, 28 Sep 2004 16:55:13 +0200), +Gaetano Mendola confessed: + +> Robert Creager wrote: +> > Help? +> > +> > Normally, this query takes from 5 minutes to 2 hours to run. On this +> > update, it's been running for more than 10 hours. +> > +> > Can it be helped? +> +> +> When I see this usually means that tables are full of +> dead rows. Did you vacuum you DB. Which version are you +> using ? +> + +Gee, the two questions I realized I forgot to answer going into work ;-) I run +pg_autovacuum, and it's working. Even ran a FULL ANALYZE, no help. The version +is 7.4.1. + +Cheers, +Rob + +-- + 20:22:11 up 5 days, 22:48, 2 users, load average: 2.16, 2.18, 2.15 +Linux 2.6.5-02 #8 SMP Mon Jul 12 21:34:44 MDT 2004 + +--Signature=_Tue__28_Sep_2004_20_25_07_-0600_j=i95elLENMshOJ/ +Content-Type: application/pgp-signature + +-----BEGIN PGP SIGNATURE----- +Version: GnuPG v1.2.4 (GNU/Linux) + +iEYEARECAAYFAkFaHQMACgkQLQ/DKuwDYzm/TQCdHD4To5In8v00yp6/Av/e3r0z +sWkAnAhNzkCrQj7n6+dmZy9EzPApdzad +=wrEM +-----END PGP SIGNATURE----- + +--Signature=_Tue__28_Sep_2004_20_25_07_-0600_j=i95elLENMshOJ/-- + + +From pgsql-performance-owner@postgresql.org Wed Sep 29 03:42:42 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 6CDAC329FA7 + for ; + Wed, 29 Sep 2004 03:42:36 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 55831-01 + for ; + Wed, 29 Sep 2004 02:42:09 +0000 (GMT) +Received: from mproxy.gmail.com (rproxy.gmail.com [64.233.170.201]) + by svr1.postgresql.org (Postfix) with ESMTP id 1A64432A10A + for ; + Wed, 29 Sep 2004 03:41:55 +0100 (BST) +Received: by mproxy.gmail.com with SMTP id 73so2851314rnk + for ; + Tue, 28 Sep 2004 19:41:50 -0700 (PDT) +Received: by 10.38.208.53 with SMTP id f53mr1501805rng; + Tue, 28 Sep 2004 19:41:50 -0700 (PDT) +Received: by 10.38.165.21 with HTTP; Tue, 28 Sep 2004 19:41:50 -0700 (PDT) +Message-ID: +Date: Tue, 28 Sep 2004 21:41:50 -0500 +From: Kevin Barnard +Reply-To: Kevin Barnard +To: Robert Creager +Subject: Re: This query is still running after 10 hours... +Cc: pgsql-performance@postgresql.org +In-Reply-To: <20040928202140.4ea9d090@thunder.mshome.net> +Mime-Version: 1.0 +Content-Type: text/plain; charset=US-ASCII +Content-Transfer-Encoding: 7bit +References: <20040928081957.7a317a95@thunder.mshome.net> + + + <20040928202140.4ea9d090@thunder.mshome.net> +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/318 +X-Sequence-Number: 8446 + +On Tue, 28 Sep 2004 20:21:40 -0600, Robert Creager + wrote: +> +> The trigger keeps another table (catalog) up to date with the information from the obs_v and obs_i tables. There are no direct insert/update/delete's on the catalog table, only though the trigger. +> + +It's possible that the update to catalog is what is really taking a +long time. You might wish to try and explain that query just to make +sure. You might also wish to disable to trigger just to rule it out. +Does catalog have any triggers on it? Does it have any foreign keys? + +I've shot myself in the foot on this before which is the only reason I +ask about it. + +From pgsql-hackers-win32-owner@postgresql.org Wed Sep 29 04:14:40 2004 +X-Original-To: pgsql-hackers-win32-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id ECD8C32A10C + for ; + Wed, 29 Sep 2004 04:14:35 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 62509-05 + for ; + Wed, 29 Sep 2004 03:14:31 +0000 (GMT) +Received: from server07.icaen.uiowa.edu (server07.icaen.uiowa.edu + [128.255.17.47]) + by svr1.postgresql.org (Postfix) with ESMTP id 7BC68329DCD + for ; + Wed, 29 Sep 2004 04:14:24 +0100 (BST) +Received: from server11.icaen.uiowa.edu (server11.icaen.uiowa.edu + [128.255.17.51]) + by server07.icaen.uiowa.edu (8.12.9/8.12.9) with ESMTP id + i8T3EKtq015778 + for ; sent by ; + Tue, 28 Sep 2004 22:14:20 -0500 (CDT) +Received: from [192.168.1.11] (12-217-241-0.client.mchsi.com [12.217.241.0]) + by server11.icaen.uiowa.edu (8.12.9/smtp-service-1.6) with ESMTP id + i8T3EJMZ019915 for ; + (envelope-from ) Tue, 28 Sep 2004 22:14:19 -0500 + (CDT) +Message-ID: <415A288F.2030002@johnmeinel.com> +Date: Tue, 28 Sep 2004 22:14:23 -0500 +From: John Meinel +User-Agent: Mozilla Thunderbird 0.8 (Windows/20040913) +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: pgsql-hackers-win32 +Subject: Poor Performance for large queries in functions +References: <4155C955.40808@dunslane.net> +In-Reply-To: <4155C955.40808@dunslane.net> +X-Enigmail-Version: 0.86.0.0 +X-Enigmail-Supports: pgp-inline, pgp-mime +Content-Type: multipart/signed; micalg=pgp-sha1; + protocol="application/pgp-signature"; + boundary="------------enig024506932F80510134C3D0ED" +X-Virus-Scanned: clamd / ClamAV version 0.75, clamav-milter version 0.66n +X-Virus-Scanned: clamd / ClamAV version 0.75, clamav-milter version 0.75 + on clamav.icaen.uiowa.edu +X-Virus-Status: Clean +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, + hits=0.3 tagged_above=0.0 required=5.0 tests=UPPERCASE_25_50 +X-Spam-Level: +X-Archive-Number: 200409/155 +X-Sequence-Number: 2285 + +This is an OpenPGP/MIME signed message (RFC 2440 and 3156) +--------------enig024506932F80510134C3D0ED +Content-Type: text/plain; charset=ISO-8859-1; format=flowed +Content-Transfer-Encoding: 7bit + +I've been using postgres 8.0 beta for win32 for quite a while now, and I +am very happy with it. However, I am having an odd problem. Basically, I +have a large query which is a bunch of UNION SELECTs from a bunch of +different tables. I have all the necessary columns indexed, and when I +run the query by hand, it runs very fast (20ms). However, if I try to +bundle this query up into a server side function, it runs very slow (10 +seconds). I'm trying to figure out why, but since I can't run EXPLAIN +ANALYZE inside a function, I don't really know what else to do. + +The layout of my database is a bunch of tables that all have an object +id associated with them. There is a main object table that defines per +object permissions, and then all of the tables refer to eachother by the +unique id. What I'm trying to do is get a list of objects that might +refer to a given id. + +Here is the query. 48542 is just one of the object ids. Some of these +tables have 500,000 rows, but most are quite small, and the result is +only 3 rows. + +SELECT * FROM object WHERE id in ( + SELECT id FROM data_t WHERE project_id = 48542 + UNION SELECT id FROM analyzeset_t + WHERE subject_id = 48542 + OR img_id = 48542 + OR hdr_id = 48542 + UNION SELECT id FROM bdi_t WHERE dcmstudy_id = 48542 + UNION SELECT id FROM crq_t WHERE dcmstudy_id = 48542 + UNION SELECT id FROM dcmfile_t WHERE dcmseries_id = 48542 + UNION SELECT id FROM dcmseries_t WHERE dcmstudy_id = 48542 + UNION SELECT id FROM dcmstudy_t + WHERE dcmsub_id = 48542 + OR consent_id = 48542 + UNION SELECT id FROM hsq_t WHERE dcmstudy_id = 48542 + UNION SELECT id FROM job_t WHERE claimed_id = 48542 + UNION SELECT id FROM loc_t WHERE contact_id = 48542 + UNION SELECT id FROM pathslide_t WHERE plane_id = 48542 + UNION SELECT id FROM pft_t WHERE dcmstudy_id = 48542 + UNION SELECT id FROM pftblood_t WHERE pft_id = 48542 + UNION SELECT id FROM pftdata_t WHERE pft_id = 48542 + UNION SELECT id FROM pftpred_t WHERE pft_id = 48542 + UNION SELECT id FROM run_t WHERE job_id = 48542 + UNION SELECT id FROM scanread_t + WHERE readby_id = 48542 + OR dcmstudy_id = 48542 + UNION SELECT id FROM service_t WHERE comp_id = 48542 + UNION SELECT id FROM sliceplane_t WHERE tissue_id = 48542 + UNION SELECT id FROM store_t WHERE loc_id = 48542 + UNION SELECT id FROM subject_t WHERE supersub_id = 48542 + UNION SELECT id FROM vc_t WHERE dcmstudy_id = 48542 + UNION SELECT id FROM vcdata_t WHERE vc_id = 48542 + UNION SELECT id FROM vcdyn_t WHERE vc_id = 48542 + UNION SELECT id FROM vcstatic_t WHERE vc_id = 48542 + UNION SELECT child_id as id FROM datapar_t WHERE par_id = 48542 + UNION SELECT par_id as id FROM datapar_t WHERE child_id = 48542 + UNION SELECT store_id as id FROM finst_t WHERE file_id = 48542 + UNION SELECT file_id as id FROM finst_t WHERE store_id = 48542 + UNION SELECT from_id as id FROM link_t WHERE to_id = 48542 + UNION SELECT to_id as id FROM link_t WHERE from_id = 48542 + UNION SELECT data_id as id FROM proc_t WHERE filter_id = 48542 + UNION SELECT filter_id as id FROM proc_t WHERE data_id = 48542 + UNION SELECT subject_id as id FROM subdata_t WHERE data_id = 48542 + UNION SELECT data_id as id FROM subdata_t WHERE subject_id = 48542 +) +; + +If I run this exact query, it takes 21 ms. + +I tried to wrap it into a function with: + +create function getrefs(int) returns setof object as ' +... +' language sql; + +Where the ... is just the same query with 48542 replaced with $1. +select getrefs(48542); +takes 10356.000ms + +I have also tried some other things such as: + +CREATE OR REPLACE FUNCTION mf_getrefobjs(int) RETURNS boolean AS ' +DECLARE + oldid alias for $1; +BEGIN + DROP TABLE refobjs; + CREATE TEMPORARY TABLE refobjs AS + SELECT * FROM object WHERE id in ( + SELECT id FROM data_t WHERE project_id = oldid +... + ); + RETURN 1; +end; +' LANGUAGE plpgSQL; + +I have tried returning cursors (they return fast, but the first FETCH +NEXT, is very slow.) + +Does anyone know why this would be? Is it a problem that in a function +it doesn't notice that all of the '=' are the same number, and it cannot +optimize the query? Is there some way I could force an EXPLAIN ANALYZE? +(if i run it on SELECT getrefs() I just get that it made 1 function call.) + +I've tried adding oldid::int in case it was a casting problem. + +Actually, I've also tried stripping it all the way down to one query: +create or replace function getrefs(int4) returns setof object as ' + SELECT * FROM object WHERE id in ( + SELECT id FROM data_t WHERE project_id = $1::int + ); +' language sql; + +And that takes 3ms to return 0 rows. It actually seems like it is +ignoring the index on project_id in this case. + +It is true that project_id can be Null. It seems that if I make this +query on other tables that have "not null" the don't have the same +performance hit. + +Any help would be much appreciated, even if it is just giving me a +better place to ask. + +John +=:-> + +--------------enig024506932F80510134C3D0ED +Content-Type: application/pgp-signature; name="signature.asc" +Content-Description: OpenPGP digital signature +Content-Disposition: attachment; filename="signature.asc" + +-----BEGIN PGP SIGNATURE----- +Version: GnuPG v1.2.4 (Cygwin) +Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org + +iD8DBQFBWiiPJdeBCYSNAAMRAiJIAKDCFY0FZHKxDX5ZvSEkZzi4jdwWpgCdFk/9 +pW37qEf0bjZgJZawlGVvsgw= +=wALV +-----END PGP SIGNATURE----- + +--------------enig024506932F80510134C3D0ED-- + +From pgsql-performance-owner@postgresql.org Wed Sep 29 04:45:53 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 2F40932A24E + for ; + Wed, 29 Sep 2004 04:45:25 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 68560-04 + for ; + Wed, 29 Sep 2004 03:45:14 +0000 (GMT) +Received: from rambo.iniquinet.com (rambo.iniquinet.com [69.39.89.10]) + by svr1.postgresql.org (Postfix) with ESMTP id 81B0A32A161 + for ; + Wed, 29 Sep 2004 04:44:42 +0100 (BST) +Received: (qmail 17553 invoked by uid 1010); 28 Sep 2004 23:44:29 -0400 +Received: from Robert_Creager@LogicalChaos.org by rambo.iniquinet.com by uid + 1002 with qmail-scanner-1.20 (clamscan: 0.70. spamassassin: 2.64. + Clear:RC:0(216.150.208.13):SA:0(-4.6/6.0):. + Processed in 1.750459 secs); 29 Sep 2004 03:44:29 -0000 +Received: from static-13.mm.den.viawest.net (HELO thunder.mshome.net) + (perl?test@logicalchaos.org@216.150.208.13) + by rambo.iniquinet.com with AES256-SHA encrypted SMTP; + 28 Sep 2004 23:44:28 -0400 +Received: from localhost.localdomain (thunder.mshome.net [192.168.0.250]) + by thunder.mshome.net (Postfix) with ESMTP id 36F0BA8237; + Tue, 28 Sep 2004 21:44:26 -0600 (MDT) +Received: from logicalchaos.org (thunder.mshome.net [192.168.0.250]) + by thunder.mshome.net (Postfix) with SMTP id E869DA8237; + Tue, 28 Sep 2004 21:44:24 -0600 (MDT) +Date: Tue, 28 Sep 2004 21:44:24 -0600 +From: Robert Creager +To: Tom Lane +Cc: PGPerformance +Subject: Re: This query is still running after 10 hours... +Message-Id: <20040928214424.2583b925@thunder.mshome.net> +In-Reply-To: <14842.1096383863@sss.pgh.pa.us> +References: <20040928081957.7a317a95@thunder.mshome.net> + <14842.1096383863@sss.pgh.pa.us> +Organization: Starlight Vision, LLC. +X-Mailer: Sylpheed version 0.9.10claws (GTK+ 1.2.10; i586-mandrake-linux-gnu) +Mime-Version: 1.0 +Content-Type: multipart/signed; protocol="application/pgp-signature"; + micalg="pgp-sha1"; + boundary="Signature=_Tue__28_Sep_2004_21_44_24_-0600_z6MwwaicMC+jj6K2" +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/319 +X-Sequence-Number: 8447 + +--Signature=_Tue__28_Sep_2004_21_44_24_-0600_z6MwwaicMC+jj6K2 +Content-Type: multipart/mixed; + boundary="Multipart=_Tue__28_Sep_2004_21_44_24_-0600_T=3Spy18auU7fXX_" + +--Multipart=_Tue__28_Sep_2004_21_44_24_-0600_T=3Spy18auU7fXX_ +Content-Type: text/plain; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit + +When grilled further on (Tue, 28 Sep 2004 11:04:23 -0400), +Tom Lane confessed: + +> Robert Creager writes: +> > Normally, this query takes from 5 minutes to 2 hours to run. On this +> > update, it's been running for more than 10 hours. +> +> > ... +> > -> Nested Loop (cost=250.69..129094.19 rows=77211 width=59) +> > -> Hash Join (cost=250.69..307.34 rows=67 width=12) +> > Hash Cond: ("outer".pair_id = "inner".pair_id) +> > ... +> +> It chose a nested loop here because it was only expecting 67 rows out of +> the next-lower join, and so it thought it would only need 67 repetitions +> of the index probe into obs_v_file_id_index. I'm suspicious that that +> estimate was way low and so the nestloop is taking forever. You might +> try "SET enable_nestloop = off" as a crude way of avoiding that trap. + +I tried your suggestion. Did generate a different plan (below), but the +estimation is blown as it still used a nested loop. The query is currently +running(42 minutes so far). For the query in question, there are 151 different +pair_id's in the pairs table, which equates to 302 entries in the files table +(part of the query), which moves on to 533592 entries in the obs_v table and +533699 entries in the obs_i table. + +The groups table has 76 total entries, files 9028, zero_pair 2532, color_groups +147. Only the obs_v and obs_i tables have data of any significant quantities +with 10M rows apiece. The trigger hitting the catalog table (875499 entries) is +searching for single entries to match (one fire per obs_v/obs_i update) on an +index (took 54ms on the first query of a random id just now). + +There is no significant disk activity (read 0), one CPU is pegged, and that +process is consuming 218M Resident memory, 168M Shared (10% available memory +total). All reasonable, except for the fact it doesn't come back... + +Hash Join (cost=100267870.17..100751247.13 rows=1578889 width=63) + Hash Cond: ("outer".star_id = "inner".star_id) + -> Seq Scan on obs_i i (cost=0.00..213658.19 rows=10391319 width=8) + -> Hash (cost=100266886.39..100266886.39 rows=77113 width=59) + -> Hash Join (cost=100000307.51..100266886.39 rows=77113 width=59) + Hash Cond: ("outer".file_id = "inner".file_id) + -> Seq Scan on obs_v (cost=0.00..213854.50 rows=10390650 width=5 +1) -> Hash (cost=100000307.34..100000307.34 rows=67 width=12) + -> Hash Join (cost=100000250.69..100000307.34 rows=67 +width=12) Hash Cond: ("outer".pair_id = +"inner".pair_id) -> Seq Scan on zero_pair zp +(cost=0.00..43.32 rows=2532 width=8) -> Hash +(cost=100000250.40..100000250.40 rows=118 width=12) + -> Hash Join (cost=100000004.80..100000250.40 rows=118 width=12) + Hash Cond: ("outer".night_id = "inner".night_id) + -> Seq Scan on files f (cost=0.00..199.28 +rows=9028 width=12) -> Hash +(cost=100000004.80..100000004.80rows=1 width=8) + -> Nested Loop (cost=100000000.00..100000004.80 rows=1 width=8) + -> Seq Scan on color_groups cg +(cost=0.00..2.84 rows=1 width=8) + Filter: (175 = group_id) +-> Seq Scan on groups g (cost=0.00..1.95 rows=1 width=8) + Filter: (group_id = 175) + + + +-- + 20:48:23 up 5 days, 23:14, 2 users, load average: 2.56, 2.91, 2.78 +Linux 2.6.5-02 #8 SMP Mon Jul 12 21:34:44 MDT 2004 + +--Multipart=_Tue__28_Sep_2004_21_44_24_-0600_T=3Spy18auU7fXX_ +Content-Type: application/octet-stream; + name="color.explain" +Content-Disposition: attachment; + filename="color.explain" +Content-Transfer-Encoding: base64 + +VVBEQVRFIG9ic192ClNFVCBtYWcgPSBvYnNfdi5pbWFnICsgenAuemVyb192 +ICsgY2cuY29sb3JfdiAqIChvYnNfdi5pbWFnIC0gaS5pbWFnKSwKICAgIHVz +ZSA9IHRydWUKRlJPTSBjb2xvcl9ncm91cHMgQVMgY2csIHplcm9fcGFpciBB +UyB6cCwgb2JzX2kgQVMgaSwgZmlsZXMgQVMgZiwgZ3JvdXBzIEFTIGcKV0hF +UkUgIG9ic192LnN0YXJfaWQgPSBpLnN0YXJfaWQKICAgQU5EIG9ic192LmZp +bGVfaWQgPSBmLmZpbGVfaWQKICAgQU5EIGNnLmdyb3VwX2lkID0gZy5ncm91 +cF9pZAogICBBTkQgZy5uaWdodF9pZCA9IGYubmlnaHRfaWQKICAgQU5EIGcu +Z3JvdXBfaWQgPSAkZ3JvdXBfaWQKICAgQU5EIHpwLnBhaXJfaWQgPSBmLnBh +aXJfaWQKCkhhc2ggSm9pbiAgKGNvc3Q9MTMwMDc5LjIyLi42Mzk2NjMuOTQg +cm93cz0xNTkwMjA0IHdpZHRoPTYzKQogIEhhc2ggQ29uZDogKCJvdXRlciIu +c3Rhcl9pZCA9ICJpbm5lciIuc3Rhcl9pZCkKICAtPiAgU2VxIFNjYW4gb24g +b2JzX2kgaSAgKGNvc3Q9MC4wMC4uMjEzNjU4LjE5IHJvd3M9MTAzOTEzMTkg +d2lkdGg9OCkKICAtPiAgSGFzaCAgKGNvc3Q9MTI5MDk0LjE5Li4xMjkwOTQu +MTkgcm93cz03NzIxMSB3aWR0aD01OSkKICAgICAgICAtPiAgTmVzdGVkIExv +b3AgIChjb3N0PTI1MC42OS4uMTI5MDk0LjE5IHJvd3M9NzcyMTEgd2lkdGg9 +NTkpCiAgICAgICAgICAgICAgLT4gIEhhc2ggSm9pbiAgKGNvc3Q9MjUwLjY5 +Li4zMDcuMzQgcm93cz02NyB3aWR0aD0xMikKICAgICAgICAgICAgICAgICAg +ICBIYXNoIENvbmQ6ICgib3V0ZXIiLnBhaXJfaWQgPSAiaW5uZXIiLnBhaXJf +aWQpCiAgICAgICAgICAgICAgICAgICAgLT4gIFNlcSBTY2FuIG9uIHplcm9f +cGFpciB6cCAgKGNvc3Q9MC4wMC4uNDMuMzIgcm93cz0yNTMyIHdpZHRoPTgp +CiAgICAgICAgICAgICAgICAgICAgLT4gIEhhc2ggIChjb3N0PTI1MC40MC4u +MjUwLjQwIHJvd3M9MTE4IHdpZHRoPTEyKQogICAgICAgICAgICAgICAgICAg +ICAgICAgIC0+ICBIYXNoIEpvaW4gIChjb3N0PTQuODAuLjI1MC40MCByb3dz +PTExOCB3aWR0aD0xMikKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg +ICBIYXNoIENvbmQ6ICgib3V0ZXIiLm5pZ2h0X2lkID0gImlubmVyIi5uaWdo +dF9pZCkKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAtPiAgU2Vx +IFNjYW4gb24gZmlsZXMgZiAgKGNvc3Q9MC4wMC4uMTk5LjI4IHJvd3M9OTAy +OCB3aWR0aD0xMikKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAt +PiAgSGFzaCAgKGNvc3Q9NC44MC4uNC44MCByb3dzPTEgd2lkdGg9OCkKICAg +ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAtPiAgTmVzdGVk +IExvb3AgIChjb3N0PTAuMDAuLjQuODAgcm93cz0xIHdpZHRoPTgpCiAgICAg +ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgLT4gIFNl +cSBTY2FuIG9uIGNvbG9yX2dyb3VwcyBjZyAgKGNvc3Q9MC4wMC4uMi44NCBy +b3dzPTEgd2lkdGg9OCkKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg +ICAgICAgICAgICAgICAgICAgICBGaWx0ZXI6ICgxNzEgPSBncm91cF9pZCkK +ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAt +PiAgU2VxIFNjYW4gb24gZ3JvdXBzIGcgIChjb3N0PTAuMDAuLjEuOTUgcm93 +cz0xIHdpZHRoPTgpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg +ICAgICAgICAgICAgICAgICAgRmlsdGVyOiAoZ3JvdXBfaWQgPSAxNzEpCiAg +ICAgICAgICAgICAgLT4gIEluZGV4IFNjYW4gdXNpbmcgb2JzX3ZfZmlsZV9p +ZF9pbmRleCBvbiBvYnNfdiAgKGNvc3Q9MC4wMC4uMTg5My4yMyByb3dzPTIz +MTcgd2lkdGg9NTEpCiAgICAgICAgICAgICAgICAgICAgSW5kZXggQ29uZDog +KG9ic192LmZpbGVfaWQgPSAib3V0ZXIiLmZpbGVfaWQpCgpIYXNoIEpvaW4g +IChjb3N0PTEwMDI2Nzg3MC4xNy4uMTAwNzUxMjQ3LjEzIHJvd3M9MTU3ODg4 +OSB3aWR0aD02MykKICBIYXNoIENvbmQ6ICgib3V0ZXIiLnN0YXJfaWQgPSAi +aW5uZXIiLnN0YXJfaWQpCiAgLT4gIFNlcSBTY2FuIG9uIG9ic19pIGkgIChj +b3N0PTAuMDAuLjIxMzY1OC4xOSByb3dzPTEwMzkxMzE5IHdpZHRoPTgpCiAg +LT4gIEhhc2ggIChjb3N0PTEwMDI2Njg4Ni4zOS4uMTAwMjY2ODg2LjM5IHJv +d3M9NzcxMTMgd2lkdGg9NTkpCiAgICAgICAgLT4gIEhhc2ggSm9pbiAgKGNv +c3Q9MTAwMDAwMzA3LjUxLi4xMDAyNjY4ODYuMzkgcm93cz03NzExMyB3aWR0 +aD01OSkKICAgICAgICAgICAgICBIYXNoIENvbmQ6ICgib3V0ZXIiLmZpbGVf +aWQgPSAiaW5uZXIiLmZpbGVfaWQpCiAgICAgICAgICAgICAgLT4gIFNlcSBT +Y2FuIG9uIG9ic192ICAoY29zdD0wLjAwLi4yMTM4NTQuNTAgcm93cz0xMDM5 +MDY1MCB3aWR0aD01IDEpCiAgICAgICAgICAgICAgLT4gIEhhc2ggIChjb3N0 +PTEwMDAwMDMwNy4zNC4uMTAwMDAwMzA3LjM0IHJvd3M9Njcgd2lkdGg9MTIp +CiAgICAgICAgICAgICAgICAgICAgLT4gIEhhc2ggSm9pbiAgKGNvc3Q9MTAw +MDAwMjUwLjY5Li4xMDAwMDAzMDcuMzQgcm93cz02NyB3aWR0aD0xMikKICAg +ICAgICAgICAgICAgICAgICAgICAgICBIYXNoIENvbmQ6ICgib3V0ZXIiLnBh +aXJfaWQgPSAiaW5uZXIiLnBhaXJfaWQpCiAgICAgICAgICAgICAgICAgICAg +ICAgICAgLT4gIFNlcSBTY2FuIG9uIHplcm9fcGFpciB6cCAgKGNvc3Q9MC4w +MC4uNDMuMzIgcm93cz0yNTMyIHdpZHRoPTgpCiAgICAgICAgICAgICAgICAg +ICAgICAgICAgLT4gIEhhc2ggIChjb3N0PTEwMDAwMDI1MC40MC4uMTAwMDAw +MjUwLjQwIHJvd3M9MTE4IHdpZHRoPTEyKQogICAgICAgICAgICAgICAgICAg +ICAgICAgICAgICAgIC0+ICBIYXNoIEpvaW4gIChjb3N0PTEwMDAwMDAwNC44 +MC4uMTAwMDAwMjUwLjQwIHJvd3M9MTE4IHdpZHRoPTEyKQogICAgICAgICAg +ICAgICAgICAgICAgICAgICAgICAgICAgICAgIEhhc2ggQ29uZDogKCJvdXRl +ciIubmlnaHRfaWQgPSAiaW5uZXIiLm5pZ2h0X2lkKQogICAgICAgICAgICAg +ICAgICAgICAgICAgICAgICAgICAgICAgIC0+ICBTZXEgU2NhbiBvbiBmaWxl +cyBmICAoY29zdD0wLjAwLi4xOTkuMjggcm93cz05MDI4IHdpZHRoPTEyKQog +ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC0+ICBIYXNo +ICAoY29zdD0xMDAwMDAwMDQuODAuLjEwMDAwMDAwNC44MHJvd3M9MSB3aWR0 +aD04KQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg +ICAgIC0+ICBOZXN0ZWQgTG9vcCAgKGNvc3Q9MTAwMDAwMDAwLjAwLi4xMDAw +MDAwMDQuODAgcm93cz0xIHdpZHRoPTgpCiAgICAgICAgICAgICAgICAgICAg +ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgLT4gIFNlcSBTY2FuIG9u +IGNvbG9yX2dyb3VwcyBjZyAgKGNvc3Q9MC4wMC4uMi44NCByb3dzPTEgd2lk +dGg9OCkKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg +ICAgICAgICAgICAgICAgICBGaWx0ZXI6ICgxNzUgPSBncm91cF9pZCkKICAg +ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg +ICAtPiAgU2VxIFNjYW4gb24gZ3JvdXBzIGcgIChjb3N0PTAuMDAuLjEuOTUg +cm93cz0xIHdpZHRoPTgpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAg +ICAgICAgICAgICAgICAgICAgICAgICAgICAgRmlsdGVyOiAoZ3JvdXBfaWQg +PSAxNzUpCgo= + +--Multipart=_Tue__28_Sep_2004_21_44_24_-0600_T=3Spy18auU7fXX_-- + +--Signature=_Tue__28_Sep_2004_21_44_24_-0600_z6MwwaicMC+jj6K2 +Content-Type: application/pgp-signature + +-----BEGIN PGP SIGNATURE----- +Version: GnuPG v1.2.4 (GNU/Linux) + +iEYEARECAAYFAkFaL5gACgkQLQ/DKuwDYzkWcwCdHKHLxmMydV8CvQAT2DJBBCDY +MiQAoJh2KtRrDNvSdxmJgzCQ/8v35Vhn +=YUs9 +-----END PGP SIGNATURE----- + +--Signature=_Tue__28_Sep_2004_21_44_24_-0600_z6MwwaicMC+jj6K2-- + + +From pgsql-performance-owner@postgresql.org Wed Sep 29 04:52:59 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 9B1A032A169 + for ; + Wed, 29 Sep 2004 04:52:54 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 66544-10 + for ; + Wed, 29 Sep 2004 03:52:18 +0000 (GMT) +Received: from rambo.iniquinet.com (rambo.iniquinet.com [69.39.89.10]) + by svr1.postgresql.org (Postfix) with ESMTP id 6B2D432A032 + for ; + Wed, 29 Sep 2004 04:52:14 +0100 (BST) +Received: (qmail 19832 invoked by uid 1010); 28 Sep 2004 23:52:08 -0400 +Received: from Robert_Creager@LogicalChaos.org by rambo.iniquinet.com by uid + 1002 with qmail-scanner-1.20 (clamscan: 0.70. spamassassin: 2.64. + Clear:RC:0(216.150.208.13):SA:0(-4.6/6.0):. + Processed in 1.397411 secs); 29 Sep 2004 03:52:08 -0000 +Received: from static-13.mm.den.viawest.net (HELO thunder.mshome.net) + (perl?test@logicalchaos.org@216.150.208.13) + by rambo.iniquinet.com with AES256-SHA encrypted SMTP; + 28 Sep 2004 23:52:07 -0400 +Received: from localhost.localdomain (thunder.mshome.net [192.168.0.250]) + by thunder.mshome.net (Postfix) with ESMTP id 3AF1AA8237; + Tue, 28 Sep 2004 21:52:06 -0600 (MDT) +Received: from logicalchaos.org (thunder.mshome.net [192.168.0.250]) + by thunder.mshome.net (Postfix) with SMTP id 72C83A8237; + Tue, 28 Sep 2004 21:51:57 -0600 (MDT) +Date: Tue, 28 Sep 2004 21:51:56 -0600 +From: Robert Creager +To: Kevin Barnard +Cc: pgsql-performance@postgresql.org +Subject: Re: This query is still running after 10 hours... +Message-Id: <20040928215156.65c36a5a@thunder.mshome.net> +In-Reply-To: +References: <20040928081957.7a317a95@thunder.mshome.net> + + + <20040928202140.4ea9d090@thunder.mshome.net> + +Organization: Starlight Vision, LLC. +X-Mailer: Sylpheed version 0.9.10claws (GTK+ 1.2.10; i586-mandrake-linux-gnu) +Mime-Version: 1.0 +Content-Type: multipart/signed; protocol="application/pgp-signature"; + micalg="pgp-sha1"; + boundary="Signature=_Tue__28_Sep_2004_21_51_56_-0600_AR02941twMntN+Sx" +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/320 +X-Sequence-Number: 8448 + +--Signature=_Tue__28_Sep_2004_21_51_56_-0600_AR02941twMntN+Sx +Content-Type: text/plain; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit + +When grilled further on (Tue, 28 Sep 2004 21:41:50 -0500), +Kevin Barnard confessed: + +> On Tue, 28 Sep 2004 20:21:40 -0600, Robert Creager +> wrote: +> > +> > The trigger keeps another table (catalog) up to date with the information +> > from the obs_v and obs_i tables. There are no direct insert/update/delete's +> > on the catalog table, only though the trigger. +> > +> +> It's possible that the update to catalog is what is really taking a +> long time. You might wish to try and explain that query just to make +> sure. You might also wish to disable to trigger just to rule it out. +> Does catalog have any triggers on it? Does it have any foreign keys? + +A select on the catalog is really quick (54ms on a random query - ~1M entries). The updates use the index. The catalog table has no triggers or foreign keys. The trigger on the obs_? tables manages the catalog table. + +tassiv=# \d catalog + Table "public.catalog" + Column | Type | Modifiers +------------------+------------------+------------------------------------------------- + star_id | integer | not null default nextval('"star_id_seq"'::text) + loc_count | integer | default 0 + loc | spoint | not null + ra_sum | double precision | default 0 + ra_sigma | real | default 0 + ra_sum_square | double precision | default 0 + dec_sum | double precision | default 0 + dec_sigma | real | default 0 + dec_sum_square | double precision | default 0 + mag_u_count | integer | default 0 + mag_u | real | default 99 + mag_u_sum | double precision | default 0 + mag_u_sigma | real | default 0 + mag_u_sum_square | double precision | default 0 + mag_b_count | integer | default 0 + mag_b | real | default 99 + mag_b_sum | double precision | default 0 + mag_b_sigma | real | default 0 + mag_b_sum_square | double precision | default 0 + mag_v_count | integer | default 0 + mag_v | real | default 99 + mag_v_sum | double precision | default 0 + mag_v_sigma | real | default 0 + mag_v_sum_square | double precision | default 0 + mag_r_count | integer | default 0 + mag_r | real | default 99 + mag_r_sum | double precision | default 0 + mag_r_sigma | real | default 0 + mag_r_sum_square | double precision | default 0 + mag_i_count | integer | default 0 + mag_i | real | default 99 + mag_i_sum | double precision | default 0 + mag_i_sigma | real | default 0 + mag_i_sum_square | double precision | default 0 +Indexes: + "catalog_pkey" primary key, btree (star_id) + "catalog_ra_decl_index" gist (loc) + + +-- + 21:44:49 up 6 days, 11 min, 2 users, load average: 2.03, 2.17, 2.39 +Linux 2.6.5-02 #8 SMP Mon Jul 12 21:34:44 MDT 2004 + +--Signature=_Tue__28_Sep_2004_21_51_56_-0600_AR02941twMntN+Sx +Content-Type: application/pgp-signature + +-----BEGIN PGP SIGNATURE----- +Version: GnuPG v1.2.4 (GNU/Linux) + +iEYEARECAAYFAkFaMVwACgkQLQ/DKuwDYzmYtwCfZjY2Thj7TIEYkXZLipFEC5NX +oYYAniVsBAlm342Y4lagvurpgLAybs6G +=Jg6r +-----END PGP SIGNATURE----- + +--Signature=_Tue__28_Sep_2004_21_51_56_-0600_AR02941twMntN+Sx-- + + +From pgsql-hackers-win32-owner@postgresql.org Wed Sep 29 06:11:25 2004 +X-Original-To: pgsql-hackers-win32-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 967F832A23E + for ; + Wed, 29 Sep 2004 06:11:24 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 83989-07 + for ; + Wed, 29 Sep 2004 05:11:13 +0000 (GMT) +Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) + by svr1.postgresql.org (Postfix) with ESMTP id 46ECF32A232 + for ; + Wed, 29 Sep 2004 06:11:04 +0100 (BST) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id i8T5AliS022683; + Wed, 29 Sep 2004 01:10:48 -0400 (EDT) +To: John Meinel +Cc: pgsql-hackers-win32 +Subject: Re: Poor Performance for large queries in functions +In-reply-to: <415A288F.2030002@johnmeinel.com> +References: <4155C955.40808@dunslane.net> <415A288F.2030002@johnmeinel.com> +Comments: In-reply-to John Meinel + message dated "Tue, 28 Sep 2004 22:14:23 -0500" +Date: Wed, 29 Sep 2004 01:10:47 -0400 +Message-ID: <22682.1096434647@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/156 +X-Sequence-Number: 2286 + +John Meinel writes: +> ... However, if I try to +> bundle this query up into a server side function, it runs very slow (10 +> seconds). I'm trying to figure out why, but since I can't run EXPLAIN +> ANALYZE inside a function, I don't really know what else to do. + +A parameterized query inside a function is basically the same as a +PREPARE'd query with parameters at the SQL level. So you can +investigate what's happening here with + + PREPARE foo(int) AS + SELECT * FROM object WHERE id in ( + SELECT id FROM data_t WHERE project_id = $1 + UNION SELECT ... ; + + EXPLAIN ANALYZE EXECUTE foo(48542); + +I'm not sure where the problem is either, so please do send along the +results. + + regards, tom lane + +PS: pgsql-performance would be a more appropriate venue for this +discussion. + +From pgsql-hackers-win32-owner@postgresql.org Wed Sep 29 08:13:34 2004 +X-Original-To: pgsql-hackers-win32-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id A01E632A161; + Wed, 29 Sep 2004 08:13:31 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 13865-04; Wed, 29 Sep 2004 07:13:19 +0000 (GMT) +Received: from www.postgresql.com (www.postgresql.com [200.46.204.209]) + by svr1.postgresql.org (Postfix) with ESMTP id 360CC32A11D; + Wed, 29 Sep 2004 08:13:21 +0100 (BST) +Received: from server07.icaen.uiowa.edu (server07.icaen.uiowa.edu + [128.255.17.47]) + by www.postgresql.com (Postfix) with ESMTP id ECAF65A1094; + Wed, 29 Sep 2004 08:13:11 +0100 (BST) +Received: from server11.icaen.uiowa.edu (server11.icaen.uiowa.edu + [128.255.17.51]) + by server07.icaen.uiowa.edu (8.12.9/8.12.9) with ESMTP id + i8T77puk018683; + sent by ; Wed, 29 Sep 2004 02:08:03 -0500 (CDT) +Received: from [192.168.1.11] (12-217-241-0.client.mchsi.com [12.217.241.0]) + by server11.icaen.uiowa.edu (8.12.9/smtp-service-1.6) with ESMTP id + i8T6Y6MZ011499; (envelope-from ) Wed, + 29 Sep 2004 01:34:07 -0500 (CDT) +Message-ID: <415A575F.2060802@johnmeinel.com> +Date: Wed, 29 Sep 2004 01:34:07 -0500 +From: John Meinel +User-Agent: Mozilla Thunderbird 0.8 (Windows/20040913) +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: pgsql-hackers-win32 , + pgsql-performance@postgresql.org +Subject: Re: Poor Performance for large queries in functions +References: <4155C955.40808@dunslane.net> <415A288F.2030002@johnmeinel.com> + <22682.1096434647@sss.pgh.pa.us> +In-Reply-To: <22682.1096434647@sss.pgh.pa.us> +X-Enigmail-Version: 0.86.0.0 +X-Enigmail-Supports: pgp-inline, pgp-mime +Content-Type: multipart/signed; micalg=pgp-sha1; + protocol="application/pgp-signature"; + boundary="------------enigF2DFFA754DD831AA68A3C06E" +X-Virus-Scanned: clamd / ClamAV version 0.75, clamav-milter version 0.66n +X-Virus-Scanned: clamd / ClamAV version 0.75, clamav-milter version 0.75 + on clamav.icaen.uiowa.edu +X-Virus-Status: Clean +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/157 +X-Sequence-Number: 2287 + +This is an OpenPGP/MIME signed message (RFC 2440 and 3156) +--------------enigF2DFFA754DD831AA68A3C06E +Content-Type: text/plain; charset=ISO-8859-1; format=flowed +Content-Transfer-Encoding: 7bit + +Tom Lane wrote: +> John Meinel writes: +> +>>... However, if I try to +>>bundle this query up into a server side function, it runs very slow (10 +>>seconds). I'm trying to figure out why, but since I can't run EXPLAIN +>>ANALYZE inside a function, I don't really know what else to do. +> +> +> A parameterized query inside a function is basically the same as a +> PREPARE'd query with parameters at the SQL level. So you can +> investigate what's happening here with +> +> PREPARE foo(int) AS +> SELECT * FROM object WHERE id in ( +> SELECT id FROM data_t WHERE project_id = $1 +> UNION SELECT ... ; +> +> EXPLAIN ANALYZE EXECUTE foo(48542); +> +> I'm not sure where the problem is either, so please do send along the +> results. +> +> regards, tom lane +> +> PS: pgsql-performance would be a more appropriate venue for this +> discussion. + +Well, I think I tracked the problem down to the fact that the column +does not have a "not null" constraint on it. Here is a demonstration. +Basically, I have 3 tables, tobjects, tdata, and tproject. tdata +basically just links between tobjects and tproject, but isn't required +to link to tproject. Yes, the real data has more columns, but this shows +the problem. + +jfmeinel=> \d tobjects + Table "public.tobjects" + Column | Type | Modifiers +--------+---------+----------- + id | integer | not null +Indexes: + "tobjects_pkey" primary key, btree (id) + +jfmeinel=> \d tproject + Table "public.tproject" + Column | Type | Modifiers +--------+---------+----------- + id | integer | not null +Indexes: + "tproject_pkey" primary key, btree (id) + +jfmeinel=> \d tdata + Table "public.tdata" + Column | Type | Modifiers +------------+---------+----------- + id | integer | not null + project_id | integer | +Indexes: + "tdata_pkey" primary key, btree (id) + "tdata_project_id_idx" btree (project_id) +Foreign-key constraints: + "tdata_id_fkey" FOREIGN KEY (id) REFERENCES tobjects(id) ON UPDATE +CASCADE ON DELETE CASCADE + "tdata_project_id_fkey" FOREIGN KEY (project_id) REFERENCES + tproject(id) ON UPDATE CASCADE ON DELETE SET DEFAULT + +jfmeinel=> select count(*) from tdata; + count +-------- + 545768 + +jfmeinel=> select count(*) - count(project_id) from tdata; + ?column? +---------- + 240 + +So tdata(project_id) is almost completely full, of the 540000+ entries, +only 240 are null. + + +jfmeinel=> prepare myget(int) as select id from tdata +jfmeinel-> where project_id = $1; +PREPARE + +jfmeinel=> explain analyze execute myget(30000); + QUERY PLAN +-------------------------------------------------------------------- + Seq Scan on tdata (cost=0.00..9773.10 rows=181923 width=4) + (actual time=1047.000..1047.000 rows=0 loops=1) + Filter: (project_id = $1) + Total runtime: 1047.000 ms + +jfmeinel=> explain analyze select id from tdata where project_id = 30000; + QUERY PLAN + +------------------------------------------------------------------------- + Index Scan using tdata_project_id_idx on tdata (cost=0.00..4.20 +rows=1 width=4) (actual time=0.000..0.000 rows=0 loops =1) + Index Cond: (project_id = 30000) + Total runtime: 0.000 ms + +So notice that when doing the actual select it is able to do the index +query. But for some reason with a prepared statement, it is not able to +do it. + +Any ideas? + +Since I only have the integers now, I can send the data to someone if +they care to investigate it. It comes to 2.2M as a .tar.bz2, so +obviously I'm not going to spam the list. + +If I rewrite myget as: +prepare myget(int) as select id from tdata where project_id = 30000; it +does the right thing again. So it's something about how a variable +interacts with an indexed column with null values. + +Note: I've tried creating a script that generates dummy data to show +this problem and I have failed (it always performed the query correctly.) + +But this test data definitely shows the problem. And yes, I've vacuum +analyzed all over the place. + +John +=:-> + +PS> I tested this on PostgreSQL 7.4.3, and it did not demonstrate this +problem. I am using PostgreSQL 8.0.0beta2 (probably -dev1) + +--------------enigF2DFFA754DD831AA68A3C06E +Content-Type: application/pgp-signature; name="signature.asc" +Content-Description: OpenPGP digital signature +Content-Disposition: attachment; filename="signature.asc" + +-----BEGIN PGP SIGNATURE----- +Version: GnuPG v1.2.4 (Cygwin) +Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org + +iD8DBQFBWldjJdeBCYSNAAMRAkE2AJ4ilrPW6KfvE7hCPaSgQnVziIW32QCgxAgC +WMiDT4P3CqY0usnlvrYiDhI= +=65BZ +-----END PGP SIGNATURE----- + +--------------enigF2DFFA754DD831AA68A3C06E-- + +From pgsql-hackers-win32-owner@postgresql.org Wed Sep 29 12:35:14 2004 +X-Original-To: pgsql-hackers-win32-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id E85A532A14F; + Wed, 29 Sep 2004 09:40:42 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 37453-09; Wed, 29 Sep 2004 08:40:33 +0000 (GMT) +Received: from anchor-post-36.mail.demon.net (anchor-post-36.mail.demon.net + [194.217.242.86]) + by svr1.postgresql.org (Postfix) with ESMTP id A94E932A15F; + Wed, 29 Sep 2004 09:40:25 +0100 (BST) +Received: from mwynhau.demon.co.uk ([193.237.186.96] + helo=mainbox.archonet.com) + by anchor-post-36.mail.demon.net with esmtp (Exim 4.42) + id 1CCa0S-000JEe-KA; Wed, 29 Sep 2004 08:40:12 +0000 +Received: from [192.168.1.17] (client17.archonet.com [192.168.1.17]) + by mainbox.archonet.com (Postfix) with ESMTP + id BDE34167EE; Wed, 29 Sep 2004 09:40:10 +0100 (BST) +Message-ID: <415A74EB.9040308@archonet.com> +Date: Wed, 29 Sep 2004 09:40:11 +0100 +From: Richard Huxton +User-Agent: Mozilla Thunderbird 0.7 (X11/20040615) +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: John Meinel +Cc: pgsql-hackers-win32 , + pgsql-performance@postgresql.org +Subject: Re: [PERFORM] Poor Performance for large queries +References: <4155C955.40808@dunslane.net> <415A288F.2030002@johnmeinel.com> + <22682.1096434647@sss.pgh.pa.us> <415A575F.2060802@johnmeinel.com> +In-Reply-To: <415A575F.2060802@johnmeinel.com> +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/158 +X-Sequence-Number: 2288 + +John Meinel wrote: +> +> So notice that when doing the actual select it is able to do the index +> query. But for some reason with a prepared statement, it is not able to +> do it. +> +> Any ideas? + +In the index-using example, PG knows the value you are comparing to. So, +it can make a better estimate of how many rows will be returned. With +the prepared/compiled version it has to come up with a plan that makes +sense for any value. + +If you look back at the explain output you'll see PG is guessing 181,923 +rows will match with the prepared query but only 1 for the second query. +If in fact you returned that many rows, you wouldn't want to use the +index - it would mean fetching values twice. + +The only work-around if you are using plpgsql functions is to use +EXECUTE to make sure your queries are planned for each value provided. + +-- + Richard Huxton + Archonet Ltd + +From pgsql-performance-owner@postgresql.org Wed Sep 29 14:33:02 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id D994C32A19D + for ; + Wed, 29 Sep 2004 14:33:00 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 38062-07 + for ; + Wed, 29 Sep 2004 13:32:48 +0000 (GMT) +Received: from e4.ny.us.ibm.com (e4.ny.us.ibm.com [32.97.182.104]) + by svr1.postgresql.org (Postfix) with ESMTP id 7203E32A275 + for ; + Wed, 29 Sep 2004 14:30:55 +0100 (BST) +Received: from northrelay02.pok.ibm.com (northrelay02.pok.ibm.com + [9.56.224.150]) + by e4.ny.us.ibm.com (8.12.10/8.12.9) with ESMTP id i8TDSpvx561526; + Wed, 29 Sep 2004 09:28:51 -0400 +Received: from d01ml255.pok.ibm.com (d01av02.pok.ibm.com [9.56.224.216]) + by northrelay02.pok.ibm.com (8.12.10/NCO/VER6.6) with ESMTP id + i8TDU49B136596; Wed, 29 Sep 2004 09:30:05 -0400 +In-Reply-To: <20040928214424.2583b925@thunder.mshome.net> +Subject: Re: This query is still running after 10 hours... +To: Robert Creager +Cc: PGPerformance , + pgsql-performance-owner@postgresql.org, Tom Lane +X-Mailer: Lotus Notes Release 6.0.2CF1 June 9, 2003 +Message-ID: + +From: Steven Rosenstein +Date: Wed, 29 Sep 2004 09:28:48 -0400 +X-MIMETrack: Serialize by Router on D01ML255/01/M/IBM(Release 6.51HF562 | + September 17, 2004) at 09/29/2004 09:28:50 +MIME-Version: 1.0 +Content-type: multipart/mixed; + Boundary="0__=0ABBE58DDFDA9B8E8f9e8a93df938690918c0ABBE58DDFDA9B8E" +Content-Disposition: inline +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/323 +X-Sequence-Number: 8451 + +--0__=0ABBE58DDFDA9B8E8f9e8a93df938690918c0ABBE58DDFDA9B8E +Content-type: text/plain; charset=US-ASCII + + + + + +Hi Robert, + +"There is no significant disk activity (read 0), one CPU is pegged, and +that process is consuming 218M Resident memory, 168M Shared (10% available +memory total). All reasonable, except for the fact it doesn't come back..." + +Just to let you know, I've observed the identical phenomenon on my RHEL3-WS +server running PostgreSQL V7.3.4: One of the CPU's pegged at 100% (2-way +SMP with hyperthreading, so 4 apparent CPU's), virtually zero disk I/O +activity, high memory usage, etc. I thought it might be due to a casting +problem in a JOIN's ON clause, but that did not turn out to be the case. I +*have* recently observed that if I run a vacuum analyze on the entire +database, the amount of time spent in this looping state decreases greatly, +but it has *not* disappeared in all cases. + +Next week I hope to be able to run some directed test with stats collection +turned on, to try to see if I can find out what's causing this to occur. +I'll post the results if I find anything significant. + +--- Steve +___________________________________________________________________________________ + +Steven Rosenstein +Senior IT Architect/Specialist | IBM Virtual Server Administration +Voice/FAX: 845-689-2064 | Cell: 646-345-6978 | Tieline: 930-6001 +Text Messaging: 6463456978 @ mobile.mycingular.com +Email: srosenst @ us.ibm.com + +"Learn from the mistakes of others because you can't live long enough to +make them all yourself." -- Eleanor Roosevelt + + + + Robert Creager + To + Sent by: Tom Lane + pgsql-performance cc + -owner@postgresql PGPerformance + .org + Subject + Re: [PERFORM] This query is still + 09/28/2004 11:44 running after 10 hours... + PM + + + + + + + + + +When grilled further on (Tue, 28 Sep 2004 11:04:23 -0400), +Tom Lane confessed: + +> Robert Creager writes: +> > Normally, this query takes from 5 minutes to 2 hours to run. On this +> > update, it's been running for more than 10 hours. +> +> > ... +> > -> Nested Loop (cost=250.69..129094.19 rows=77211 width=59) +> > -> Hash Join (cost=250.69..307.34 rows=67 width=12) +> > Hash Cond: ("outer".pair_id = "inner".pair_id) +> > ... +> +> It chose a nested loop here because it was only expecting 67 rows out of +> the next-lower join, and so it thought it would only need 67 repetitions +> of the index probe into obs_v_file_id_index. I'm suspicious that that +> estimate was way low and so the nestloop is taking forever. You might +> try "SET enable_nestloop = off" as a crude way of avoiding that trap. + +I tried your suggestion. Did generate a different plan (below), but the +estimation is blown as it still used a nested loop. The query is currently +running(42 minutes so far). For the query in question, there are 151 +different +pair_id's in the pairs table, which equates to 302 entries in the files +table +(part of the query), which moves on to 533592 entries in the obs_v table +and +533699 entries in the obs_i table. + +The groups table has 76 total entries, files 9028, zero_pair 2532, +color_groups +147. Only the obs_v and obs_i tables have data of any significant +quantities +with 10M rows apiece. The trigger hitting the catalog table (875499 +entries) is +searching for single entries to match (one fire per obs_v/obs_i update) on +an +index (took 54ms on the first query of a random id just now). + +There is no significant disk activity (read 0), one CPU is pegged, and that +process is consuming 218M Resident memory, 168M Shared (10% available +memory +total). All reasonable, except for the fact it doesn't come back... + +Hash Join (cost=100267870.17..100751247.13 rows=1578889 width=63) + Hash Cond: ("outer".star_id = "inner".star_id) + -> Seq Scan on obs_i i (cost=0.00..213658.19 rows=10391319 width=8) + -> Hash (cost=100266886.39..100266886.39 rows=77113 width=59) + -> Hash Join (cost=100000307.51..100266886.39 rows=77113 +width=59) + Hash Cond: ("outer".file_id = "inner".file_id) + -> Seq Scan on obs_v (cost=0.00..213854.50 rows=10390650 +width=5 +1) -> Hash (cost=100000307.34..100000307.34 rows=67 +width=12) + -> Hash Join (cost=100000250.69..100000307.34 rows=67 +width=12) Hash Cond: ("outer".pair_id = +"inner".pair_id) -> Seq Scan on zero_pair zp +(cost=0.00..43.32 rows=2532 width=8) -> Hash +(cost=100000250.40..100000250.40 rows=118 width=12) + + -> Hash Join (cost=100000004.80..100000250.40 rows=118 width=12) + + Hash Cond: ("outer".night_id = "inner".night_id) + + -> Seq Scan on files f (cost=0.00..199.28 +rows=9028 width=12) -> Hash +(cost=100000004.80..100000004.80rows=1 width=8) + + -> Nested Loop (cost=100000000.00..100000004.80 rows=1 width=8) + + -> Seq Scan on color_groups cg + +(cost=0.00..2.84 rows=1 width=8) + + Filter: (175 = group_id) + +-> Seq Scan on groups g (cost=0.00..1.95 rows=1 width=8) + + Filter: (group_id = 175) + + + +-- + 20:48:23 up 5 days, 23:14, 2 users, load average: 2.56, 2.91, 2.78 +Linux 2.6.5-02 #8 SMP Mon Jul 12 21:34:44 MDT 2004 +(See attached file: color.explain)(See attached file: attlakjy.dat) +--0__=0ABBE58DDFDA9B8E8f9e8a93df938690918c0ABBE58DDFDA9B8E +Content-type: application/octet-stream; + name="color.explain" +Content-Disposition: attachment; filename="color.explain" +Content-transfer-encoding: base64 + +VVBEQVRFIG9ic192ClNFVCBtYWcgPSBvYnNfdi5pbWFnICsgenAuemVyb192 +ICsgY2cuY29sb3JfdiAqIChvYnNfdi5pbWFnIC0gaS5pbWFnKSwKICAgIHVz +ZSA9IHRydWUKRlJPTSBjb2xvcl9ncm91cHMgQVMgY2csIHplcm9fcGFpciBB +UyB6cCwgb2JzX2kgQVMgaSwgZmlsZXMgQVMgZiwgZ3JvdXBzIEFTIGcKV0hF +UkUgIG9ic192LnN0YXJfaWQgPSBpLnN0YXJfaWQKICAgQU5EIG9ic192LmZp +bGVfaWQgPSBmLmZpbGVfaWQKICAgQU5EIGNnLmdyb3VwX2lkID0gZy5ncm91 +cF9pZAogICBBTkQgZy5uaWdodF9pZCA9IGYubmlnaHRfaWQKICAgQU5EIGcu +Z3JvdXBfaWQgPSAkZ3JvdXBfaWQKICAgQU5EIHpwLnBhaXJfaWQgPSBmLnBh +aXJfaWQKCkhhc2ggSm9pbiAgKGNvc3Q9MTMwMDc5LjIyLi42Mzk2NjMuOTQg +cm93cz0xNTkwMjA0IHdpZHRoPTYzKQogIEhhc2ggQ29uZDogKCJvdXRlciIu +c3Rhcl9pZCA9ICJpbm5lciIuc3Rhcl9pZCkKICAtPiAgU2VxIFNjYW4gb24g +b2JzX2kgaSAgKGNvc3Q9MC4wMC4uMjEzNjU4LjE5IHJvd3M9MTAzOTEzMTkg +d2lkdGg9OCkKICAtPiAgSGFzaCAgKGNvc3Q9MTI5MDk0LjE5Li4xMjkwOTQu +MTkgcm93cz03NzIxMSB3aWR0aD01OSkKICAgICAgICAtPiAgTmVzdGVkIExv +b3AgIChjb3N0PTI1MC42OS4uMTI5MDk0LjE5IHJvd3M9NzcyMTEgd2lkdGg9 +NTkpCiAgICAgICAgICAgICAgLT4gIEhhc2ggSm9pbiAgKGNvc3Q9MjUwLjY5 +Li4zMDcuMzQgcm93cz02NyB3aWR0aD0xMikKICAgICAgICAgICAgICAgICAg +ICBIYXNoIENvbmQ6ICgib3V0ZXIiLnBhaXJfaWQgPSAiaW5uZXIiLnBhaXJf +aWQpCiAgICAgICAgICAgICAgICAgICAgLT4gIFNlcSBTY2FuIG9uIHplcm9f +cGFpciB6cCAgKGNvc3Q9MC4wMC4uNDMuMzIgcm93cz0yNTMyIHdpZHRoPTgp +CiAgICAgICAgICAgICAgICAgICAgLT4gIEhhc2ggIChjb3N0PTI1MC40MC4u +MjUwLjQwIHJvd3M9MTE4IHdpZHRoPTEyKQogICAgICAgICAgICAgICAgICAg +ICAgICAgIC0+ICBIYXNoIEpvaW4gIChjb3N0PTQuODAuLjI1MC40MCByb3dz +PTExOCB3aWR0aD0xMikKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg +ICBIYXNoIENvbmQ6ICgib3V0ZXIiLm5pZ2h0X2lkID0gImlubmVyIi5uaWdo +dF9pZCkKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAtPiAgU2Vx +IFNjYW4gb24gZmlsZXMgZiAgKGNvc3Q9MC4wMC4uMTk5LjI4IHJvd3M9OTAy +OCB3aWR0aD0xMikKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAt +PiAgSGFzaCAgKGNvc3Q9NC44MC4uNC44MCByb3dzPTEgd2lkdGg9OCkKICAg +ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAtPiAgTmVzdGVk +IExvb3AgIChjb3N0PTAuMDAuLjQuODAgcm93cz0xIHdpZHRoPTgpCiAgICAg +ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgLT4gIFNl +cSBTY2FuIG9uIGNvbG9yX2dyb3VwcyBjZyAgKGNvc3Q9MC4wMC4uMi44NCBy +b3dzPTEgd2lkdGg9OCkKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg +ICAgICAgICAgICAgICAgICAgICBGaWx0ZXI6ICgxNzEgPSBncm91cF9pZCkK +ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAt +PiAgU2VxIFNjYW4gb24gZ3JvdXBzIGcgIChjb3N0PTAuMDAuLjEuOTUgcm93 +cz0xIHdpZHRoPTgpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg +ICAgICAgICAgICAgICAgICAgRmlsdGVyOiAoZ3JvdXBfaWQgPSAxNzEpCiAg +ICAgICAgICAgICAgLT4gIEluZGV4IFNjYW4gdXNpbmcgb2JzX3ZfZmlsZV9p +ZF9pbmRleCBvbiBvYnNfdiAgKGNvc3Q9MC4wMC4uMTg5My4yMyByb3dzPTIz +MTcgd2lkdGg9NTEpCiAgICAgICAgICAgICAgICAgICAgSW5kZXggQ29uZDog +KG9ic192LmZpbGVfaWQgPSAib3V0ZXIiLmZpbGVfaWQpCgpIYXNoIEpvaW4g +IChjb3N0PTEwMDI2Nzg3MC4xNy4uMTAwNzUxMjQ3LjEzIHJvd3M9MTU3ODg4 +OSB3aWR0aD02MykKICBIYXNoIENvbmQ6ICgib3V0ZXIiLnN0YXJfaWQgPSAi +aW5uZXIiLnN0YXJfaWQpCiAgLT4gIFNlcSBTY2FuIG9uIG9ic19pIGkgIChj +b3N0PTAuMDAuLjIxMzY1OC4xOSByb3dzPTEwMzkxMzE5IHdpZHRoPTgpCiAg +LT4gIEhhc2ggIChjb3N0PTEwMDI2Njg4Ni4zOS4uMTAwMjY2ODg2LjM5IHJv +d3M9NzcxMTMgd2lkdGg9NTkpCiAgICAgICAgLT4gIEhhc2ggSm9pbiAgKGNv +c3Q9MTAwMDAwMzA3LjUxLi4xMDAyNjY4ODYuMzkgcm93cz03NzExMyB3aWR0 +aD01OSkKICAgICAgICAgICAgICBIYXNoIENvbmQ6ICgib3V0ZXIiLmZpbGVf +aWQgPSAiaW5uZXIiLmZpbGVfaWQpCiAgICAgICAgICAgICAgLT4gIFNlcSBT +Y2FuIG9uIG9ic192ICAoY29zdD0wLjAwLi4yMTM4NTQuNTAgcm93cz0xMDM5 +MDY1MCB3aWR0aD01IDEpCiAgICAgICAgICAgICAgLT4gIEhhc2ggIChjb3N0 +PTEwMDAwMDMwNy4zNC4uMTAwMDAwMzA3LjM0IHJvd3M9Njcgd2lkdGg9MTIp +CiAgICAgICAgICAgICAgICAgICAgLT4gIEhhc2ggSm9pbiAgKGNvc3Q9MTAw +MDAwMjUwLjY5Li4xMDAwMDAzMDcuMzQgcm93cz02NyB3aWR0aD0xMikKICAg +ICAgICAgICAgICAgICAgICAgICAgICBIYXNoIENvbmQ6ICgib3V0ZXIiLnBh +aXJfaWQgPSAiaW5uZXIiLnBhaXJfaWQpCiAgICAgICAgICAgICAgICAgICAg +ICAgICAgLT4gIFNlcSBTY2FuIG9uIHplcm9fcGFpciB6cCAgKGNvc3Q9MC4w +MC4uNDMuMzIgcm93cz0yNTMyIHdpZHRoPTgpCiAgICAgICAgICAgICAgICAg +ICAgICAgICAgLT4gIEhhc2ggIChjb3N0PTEwMDAwMDI1MC40MC4uMTAwMDAw +MjUwLjQwIHJvd3M9MTE4IHdpZHRoPTEyKQogICAgICAgICAgICAgICAgICAg +ICAgICAgICAgICAgIC0+ICBIYXNoIEpvaW4gIChjb3N0PTEwMDAwMDAwNC44 +MC4uMTAwMDAwMjUwLjQwIHJvd3M9MTE4IHdpZHRoPTEyKQogICAgICAgICAg +ICAgICAgICAgICAgICAgICAgICAgICAgICAgIEhhc2ggQ29uZDogKCJvdXRl +ciIubmlnaHRfaWQgPSAiaW5uZXIiLm5pZ2h0X2lkKQogICAgICAgICAgICAg +ICAgICAgICAgICAgICAgICAgICAgICAgIC0+ICBTZXEgU2NhbiBvbiBmaWxl +cyBmICAoY29zdD0wLjAwLi4xOTkuMjggcm93cz05MDI4IHdpZHRoPTEyKQog +ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC0+ICBIYXNo +ICAoY29zdD0xMDAwMDAwMDQuODAuLjEwMDAwMDAwNC44MHJvd3M9MSB3aWR0 +aD04KQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg +ICAgIC0+ICBOZXN0ZWQgTG9vcCAgKGNvc3Q9MTAwMDAwMDAwLjAwLi4xMDAw +MDAwMDQuODAgcm93cz0xIHdpZHRoPTgpCiAgICAgICAgICAgICAgICAgICAg +ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgLT4gIFNlcSBTY2FuIG9u +IGNvbG9yX2dyb3VwcyBjZyAgKGNvc3Q9MC4wMC4uMi44NCByb3dzPTEgd2lk +dGg9OCkKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg +ICAgICAgICAgICAgICAgICBGaWx0ZXI6ICgxNzUgPSBncm91cF9pZCkKICAg +ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg +ICAtPiAgU2VxIFNjYW4gb24gZ3JvdXBzIGcgIChjb3N0PTAuMDAuLjEuOTUg +cm93cz0xIHdpZHRoPTgpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAg +ICAgICAgICAgICAgICAgICAgICAgICAgICAgRmlsdGVyOiAoZ3JvdXBfaWQg +PSAxNzUpCgo= + +--0__=0ABBE58DDFDA9B8E8f9e8a93df938690918c0ABBE58DDFDA9B8E +Content-type: application/octet-stream; + name="attlakjy.dat" +Content-Disposition: attachment; filename="attlakjy.dat" +Content-transfer-encoding: base64 + +LS0tLS1CRUdJTiBQR1AgU0lHTkFUVVJFLS0tLS0NClZlcnNpb246IEdudVBH +IHYxLjIuNCAoR05VL0xpbnV4KQ0KDQppRVlFQVJFQ0FBWUZBa0ZhTDVnQUNn +a1FMUS9ES3V3RFl6a1djd0NkSEtITHhtTXlkVjhDdlFBVDJESkJCQ0RZDQpN +aVFBb0poMkt0UnJETnZTZHhtSmd6Q1EvOHYzNVZobg0KPVlVczkNCi0tLS0t +RU5EIFBHUCBTSUdOQVRVUkUtLS0tLQ0K + +--0__=0ABBE58DDFDA9B8E8f9e8a93df938690918c0ABBE58DDFDA9B8E-- + + +From pgsql-performance-owner@postgresql.org Wed Sep 29 15:46:35 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 215CE32A0FA + for ; + Wed, 29 Sep 2004 15:46:27 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 68447-03 + for ; + Wed, 29 Sep 2004 14:45:57 +0000 (GMT) +Received: from ECCMCBH.cmc.int.ec.gc.ca (ecdor130.cmc.ec.gc.ca + [199.212.17.130]) + by svr1.postgresql.org (Postfix) with ESMTP id 7BD5332A0AF + for ; + Wed, 29 Sep 2004 15:45:31 +0100 (BST) +content-class: urn:content-classes:message +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: quoted-printable +X-MimeOLE: Produced By Microsoft Exchange V6.0.6487.1 +Subject: Re: Interest in perf testing? +Date: Wed, 29 Sep 2004 10:44:12 -0400 +Message-ID: <644D07D3D59D8F408CD01AC2F833D8C62B9301@cisxa.cmc.int.ec.gc.ca> +X-MS-Has-Attach: +X-MS-TNEF-Correlator: +Thread-Topic: [PERFORM] Interest in perf testing? +Thread-Index: AcSlhvI7b95tSxEvRwaxv7Wrpli/rgAq4T7g +From: "Shea,Dan [CIS]" +To: , +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/324 +X-Sequence-Number: 8452 + +What is involved, rather what kind of help do you require?=20=20 + +Dan. + +-----Original Message----- +From: pgsql-performance-owner@postgresql.org +[mailto:pgsql-performance-owner@postgresql.org]On Behalf Of Josh Berkus +Sent: Tuesday, September 28, 2004 1:54 PM +To: pgsql-performance@postgresql.org +Subject: [PERFORM] Interest in perf testing? + + +Folks, + +I'm beginning a series of tests on OSDL's Scalable Test Platform in order t= +o=20 +determine some recommended settings for many of the new PostgreSQL.conf=20 +parameters as well as pg_autovacuum.=20=20=20=20 + +Is anyone else interested in helping me with this?=20=20=20=20=20 + +--=20 +--Josh + +Josh Berkus +Aglio Database Solutions +San Francisco + +---------------------------(end of broadcast)--------------------------- +TIP 7: don't forget to increase your free space map settings + +From pgsql-hackers-win32-owner@postgresql.org Wed Sep 29 15:58:11 2004 +X-Original-To: pgsql-hackers-win32-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 55F0232A0A0; + Wed, 29 Sep 2004 15:58:09 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 70454-07; Wed, 29 Sep 2004 14:57:37 +0000 (GMT) +Received: from server07.icaen.uiowa.edu (server07.icaen.uiowa.edu + [128.255.17.47]) + by svr1.postgresql.org (Postfix) with ESMTP id 60EE7329E4A; + Wed, 29 Sep 2004 15:57:22 +0100 (BST) +Received: from server11.icaen.uiowa.edu (server11.icaen.uiowa.edu + [128.255.17.51]) + by server07.icaen.uiowa.edu (8.12.9/8.12.9) with ESMTP id + i8TEv6tq027140; + sent by ; Wed, 29 Sep 2004 09:57:06 -0500 (CDT) +Received: from [192.168.1.11] (12-217-241-0.client.mchsi.com [12.217.241.0]) + by server11.icaen.uiowa.edu (8.12.9/smtp-service-1.6) with ESMTP id + i8TEuZ4J025624; (envelope-from ) Wed, + 29 Sep 2004 09:57:06 -0500 (CDT) +Message-ID: <415ACD1B.1020003@johnmeinel.com> +Date: Wed, 29 Sep 2004 09:56:27 -0500 +From: John Meinel +User-Agent: Mozilla Thunderbird 0.8 (Windows/20040913) +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: Richard Huxton +Cc: pgsql-hackers-win32 , + pgsql-performance@postgresql.org +Subject: Re: [PERFORM] Poor Performance for large queries +References: <4155C955.40808@dunslane.net> <415A288F.2030002@johnmeinel.com> + <22682.1096434647@sss.pgh.pa.us> <415A575F.2060802@johnmeinel.com> + <415A74EB.9040308@archonet.com> +In-Reply-To: <415A74EB.9040308@archonet.com> +X-Enigmail-Version: 0.86.0.0 +X-Enigmail-Supports: pgp-inline, pgp-mime +Content-Type: multipart/signed; micalg=pgp-sha1; + protocol="application/pgp-signature"; + boundary="------------enigF7951A9C532AA07E99D5651C" +X-Virus-Scanned: clamd / ClamAV version 0.75, clamav-milter version 0.66n +X-Virus-Scanned: clamd / ClamAV version 0.75, clamav-milter version 0.75 + on clamav.icaen.uiowa.edu +X-Virus-Status: Clean +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/159 +X-Sequence-Number: 2289 + +This is an OpenPGP/MIME signed message (RFC 2440 and 3156) +--------------enigF7951A9C532AA07E99D5651C +Content-Type: text/plain; charset=ISO-8859-1; format=flowed +Content-Transfer-Encoding: 7bit + +Richard Huxton wrote: +> John Meinel wrote: +> +>> +>> So notice that when doing the actual select it is able to do the index +>> query. But for some reason with a prepared statement, it is not able +>> to do it. +>> +>> Any ideas? +> +> +> In the index-using example, PG knows the value you are comparing to. So, +> it can make a better estimate of how many rows will be returned. With +> the prepared/compiled version it has to come up with a plan that makes +> sense for any value. +> +> If you look back at the explain output you'll see PG is guessing 181,923 +> rows will match with the prepared query but only 1 for the second query. +> If in fact you returned that many rows, you wouldn't want to use the +> index - it would mean fetching values twice. +> +> The only work-around if you are using plpgsql functions is to use +> EXECUTE to make sure your queries are planned for each value provided. +> +I suppose that make sense. If the number was small (< 100) then there +probably would be a lot of responses. Because the tproject table is all +small integers. + +But for a large number, it probably doesn't exist on that table at all. + +Thanks for the heads up. + +John +=:-> + +--------------enigF7951A9C532AA07E99D5651C +Content-Type: application/pgp-signature; name="signature.asc" +Content-Description: OpenPGP digital signature +Content-Disposition: attachment; filename="signature.asc" + +-----BEGIN PGP SIGNATURE----- +Version: GnuPG v1.2.4 (Cygwin) +Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org + +iD8DBQFBWs0iJdeBCYSNAAMRAu/PAJ9j450dzwsMWNUSlR4AvbirOzTlTQCgw4dM +069qTf5ZqQ2fRKsIt/ZkYcA= +=n+Tk +-----END PGP SIGNATURE----- + +--------------enigF7951A9C532AA07E99D5651C-- + +From pgsql-performance-owner@postgresql.org Wed Sep 29 16:56:03 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id A301632A132 + for ; + Wed, 29 Sep 2004 16:56:01 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 95889-10 + for ; + Wed, 29 Sep 2004 15:55:55 +0000 (GMT) +Received: from mail2.aeccom.com (port-212-202-101-158.static.qsc.de + [212.202.101.158]) + by svr1.postgresql.org (Postfix) with ESMTP id 22002329CDD + for ; + Wed, 29 Sep 2004 16:55:48 +0100 (BST) +Received: from [192.168.2.12] (cayambe.core.aeccom.com [192.168.2.12]) + by mail2.aeccom.com (Postfix) with ESMTP id 7AB643F + for ; + Wed, 29 Sep 2004 17:55:45 +0200 (CEST) +Message-ID: <415ADB01.9090001@aeccom.com> +Date: Wed, 29 Sep 2004 17:55:45 +0200 +From: =?ISO-8859-1?Q?Dirk_Lutzeb=E4ck?= +User-Agent: Mozilla Thunderbird 0.8 (X11/20040913) +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: pgsql-performance@postgresql.org +Subject: why does explain analyze differ so much from estimated explain? +Content-Type: multipart/mixed; boundary="------------060000050407090400010500" +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/326 +X-Sequence-Number: 8454 + +This is a multi-part message in MIME format. +--------------060000050407090400010500 +Content-Type: text/plain; charset=ISO-8859-1; format=flowed +Content-Transfer-Encoding: 7bit + +Hi, + +I have a query where I do not understand that the rows number that +explain analyze finds differs so much from what explain estimates (3rd +nested loop estimates 1 row but in real it is 4222 rows). I did analyze +the tables (pgsql 7.4.1). + +Here is the query: + +explain analyze +SELECT fts.val_1, max(fts.val_2) AS val_2 + +FROM docobjflat AS fts, + boxinfo, + docobjflat AS ftw0, + docobjflat AS ftw, envspec_map + +WHERE boxinfo.member=158096693 +AND boxinfo.envelope=ftw.envelope +AND boxinfo.community=169964332 +AND boxinfo.hide=FALSE +AND ftw0.flatid=ftw.flatid +AND fts.flatid=ftw.flatid +AND fts.docstart=1 +AND envspec_map.spec=169964482 +AND envspec_map.community=boxinfo.community +AND envspec_map.envelope=boxinfo.envelope + +AND ftw0.val_14='IN-A01' + +GROUP BY fts.val_1; + +Query plan is attached. + +Regards Dirk + +--------------060000050407090400010500 +Content-Type: text/plain; + name="qp" +Content-Transfer-Encoding: 7bit +Content-Disposition: inline; + filename="qp" + + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + HashAggregate (cost=134.58..134.58 rows=1 width=12) (actual time=1218.479..1218.480 rows=1 loops=1) + -> Nested Loop (cost=0.00..134.57 rows=1 width=12) (actual time=723.208..1218.167 rows=173 loops=1) + -> Nested Loop (cost=0.00..110.49 rows=1 width=42) (actual time=0.687..636.649 rows=4222 loops=1) + -> Nested Loop (cost=0.00..86.39 rows=1 width=15) (actual time=0.567..28.520 rows=4222 loops=1) + -> Nested Loop (cost=0.00..38.04 rows=1 width=8) (actual time=0.394..6.078 rows=43 loops=1) + -> Index Scan using boxinfo_audi_index on boxinfo (cost=0.00..16.89 rows=4 width=8) (actual time=0.190..2.791 rows=165 loops=1) + Index Cond: (member = 158096693::oid) + Filter: ((community = 169964332::oid) AND (hide = false)) + -> Index Scan using envspec_169964482_index on envspec_map (cost=0.00..5.28 rows=1 width=8) (actual time=0.016..0.016 rows=0 loops=165) + Index Cond: ((envspec_map.envelope = "outer".envelope) AND (envspec_map.community = 169964332::oid)) + Filter: (spec = 169964482) + -> Index Scan using docobjflat_169964482_envelope on docobjflat_169964482 ftw (cost=0.00..47.31 rows=83 width=19) (actual time=0.049..0.291 rows=98 loops=43) + Index Cond: ("outer".envelope = ftw.envelope) + -> Index Scan using docobjflat_169964482_flatid on docobjflat_169964482 fts (cost=0.00..24.07 rows=2 width=27) (actual time=0.010..0.138 rows=1 loops=4222) + Index Cond: (fts.flatid = "outer".flatid) + Filter: (docstart = 1) + -> Index Scan using docobjflat_169964482_flatid on docobjflat_169964482 ftw0 (cost=0.00..24.07 rows=1 width=15) (actual time=0.135..0.135 rows=0 loops=4222) + Index Cond: ("outer".flatid = ftw0.flatid) + Filter: (val_14 = 'IN-A01'::text) + Total runtime: 1219.200 ms +(20 rows) + + +--------------060000050407090400010500-- + +From pgsql-hackers-win32-owner@postgresql.org Wed Sep 29 17:18:54 2004 +X-Original-To: pgsql-hackers-win32-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id EB5F132A141; + Wed, 29 Sep 2004 17:18:42 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 04766-10; Wed, 29 Sep 2004 16:18:37 +0000 (GMT) +Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) + by svr1.postgresql.org (Postfix) with ESMTP id 886E132A135; + Wed, 29 Sep 2004 17:18:37 +0100 (BST) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id i8TGID9W029955; + Wed, 29 Sep 2004 12:18:13 -0400 (EDT) +To: John Meinel +Cc: pgsql-hackers-win32 , + pgsql-performance@postgresql.org +Subject: Re: Poor Performance for large queries in functions +In-reply-to: <415A575F.2060802@johnmeinel.com> +References: <4155C955.40808@dunslane.net> <415A288F.2030002@johnmeinel.com> + <22682.1096434647@sss.pgh.pa.us> <415A575F.2060802@johnmeinel.com> +Comments: In-reply-to John Meinel + message dated "Wed, 29 Sep 2004 01:34:07 -0500" +Date: Wed, 29 Sep 2004 12:18:13 -0400 +Message-ID: <29954.1096474693@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/160 +X-Sequence-Number: 2290 + +[ enlarging on Richard's response a bit ] + +John Meinel writes: +> jfmeinel=> explain analyze execute myget(30000); +> QUERY PLAN +> -------------------------------------------------------------------- +> Seq Scan on tdata (cost=0.00..9773.10 rows=181923 width=4) +> (actual time=1047.000..1047.000 rows=0 loops=1) +> Filter: (project_id = $1) +> Total runtime: 1047.000 ms + +> jfmeinel=> explain analyze select id from tdata where project_id = 30000; +> QUERY PLAN + +> ------------------------------------------------------------------------- +> Index Scan using tdata_project_id_idx on tdata (cost=0.00..4.20 +> rows=1 width=4) (actual time=0.000..0.000 rows=0 loops =1) +> Index Cond: (project_id = 30000) +> Total runtime: 0.000 ms + +> So notice that when doing the actual select it is able to do the index +> query. But for some reason with a prepared statement, it is not able to +> do it. + +This isn't a "can't do it" situation, it's a "doesn't want to do it" +situation, and it's got nothing whatever to do with null or not null. +The issue is the estimated row count, which in the first case is so high +as to make the seqscan approach look cheaper. So the real question here +is what are the statistics on the column that are making the planner +guess such a large number when it has no specific information about the +compared-to value. Do you have one extremely common value in the column? +Have you done an ANALYZE recently on the table, and if so can you show +us the pg_stats row for the column? + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Wed Sep 29 18:09:59 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id F1C7B32A126 + for ; + Wed, 29 Sep 2004 18:09:57 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 23726-07 + for ; + Wed, 29 Sep 2004 17:09:45 +0000 (GMT) +Received: from server07.icaen.uiowa.edu (server07.icaen.uiowa.edu + [128.255.17.47]) + by svr1.postgresql.org (Postfix) with ESMTP id 54BE332A20A + for ; + Wed, 29 Sep 2004 18:09:37 +0100 (BST) +Received: from server11.icaen.uiowa.edu (server11.icaen.uiowa.edu + [128.255.17.51]) + by server07.icaen.uiowa.edu (8.12.9/8.12.9) with ESMTP id + i8TH94vK001902; + sent by ; Wed, 29 Sep 2004 12:09:33 -0500 (CDT) +Received: from [192.168.1.11] (12-217-241-0.client.mchsi.com [12.217.241.0]) + by server11.icaen.uiowa.edu (8.12.9/smtp-service-1.6) with ESMTP id + i8TGiE4J023878; (envelope-from ) Wed, + 29 Sep 2004 11:44:45 -0500 (CDT) +Message-ID: <415AE65E.3030200@johnmeinel.com> +Date: Wed, 29 Sep 2004 11:44:14 -0500 +From: John Meinel +User-Agent: Mozilla Thunderbird 0.8 (Windows/20040913) +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: Tom Lane +Cc: pgsql-performance@postgresql.org +Subject: Re: [pgsql-hackers-win32] Poor Performance for large queries +References: <4155C955.40808@dunslane.net> <415A288F.2030002@johnmeinel.com> + <22682.1096434647@sss.pgh.pa.us> <415A575F.2060802@johnmeinel.com> + <29954.1096474693@sss.pgh.pa.us> +In-Reply-To: <29954.1096474693@sss.pgh.pa.us> +X-Enigmail-Version: 0.86.0.0 +X-Enigmail-Supports: pgp-inline, pgp-mime +Content-Type: multipart/signed; micalg=pgp-sha1; + protocol="application/pgp-signature"; + boundary="------------enigCDEA57F1EE45456906C2BF68" +X-Virus-Scanned: clamd / ClamAV version 0.75, clamav-milter version 0.66n +X-Virus-Scanned: clamd / ClamAV version 0.75, clamav-milter version 0.75 + on clamav.icaen.uiowa.edu +X-Virus-Status: Clean +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/328 +X-Sequence-Number: 8456 + +This is an OpenPGP/MIME signed message (RFC 2440 and 3156) +--------------enigCDEA57F1EE45456906C2BF68 +Content-Type: text/plain; charset=ISO-8859-1; format=flowed +Content-Transfer-Encoding: 7bit + +Tom Lane wrote: +> [ enlarging on Richard's response a bit ] +> +> John Meinel writes: +> +>>jfmeinel=> explain analyze execute myget(30000); +>> QUERY PLAN +>>-------------------------------------------------------------------- +>> Seq Scan on tdata (cost=0.00..9773.10 rows=181923 width=4) +>> (actual time=1047.000..1047.000 rows=0 loops=1) +>> Filter: (project_id = $1) +>> Total runtime: 1047.000 ms +> +> +>>jfmeinel=> explain analyze select id from tdata where project_id = 30000; +>> QUERY PLAN +> +> +>>------------------------------------------------------------------------- +>> Index Scan using tdata_project_id_idx on tdata (cost=0.00..4.20 +>>rows=1 width=4) (actual time=0.000..0.000 rows=0 loops =1) +>> Index Cond: (project_id = 30000) +>> Total runtime: 0.000 ms +> +> +>>So notice that when doing the actual select it is able to do the index +>>query. But for some reason with a prepared statement, it is not able to +>>do it. +> +> +> This isn't a "can't do it" situation, it's a "doesn't want to do it" +> situation, and it's got nothing whatever to do with null or not null. +> The issue is the estimated row count, which in the first case is so high +> as to make the seqscan approach look cheaper. So the real question here +> is what are the statistics on the column that are making the planner +> guess such a large number when it has no specific information about the +> compared-to value. Do you have one extremely common value in the column? +> Have you done an ANALYZE recently on the table, and if so can you show +> us the pg_stats row for the column? +> +> regards, tom lane +> + +The answer is "yes" that particular column has very common numbers in +it. Project id is a number from 1->21. I ended up modifying my query +such that I do the bulk of the work in a regular UNION SELECT so that +all that can be optimized, and then I later do another query for this +row in an 'EXECUTE ...' so that unless I'm actually requesting a small +number, the query planner can notice that it can do an indexed query. + +I'm pretty sure this is just avoiding worst case scenario. Because it is +true that if I use the number 18, it will return 500,000 rows. Getting +those with an indexed lookup would be very bad. But typically, I'm doing +numbers in a very different range, and so the planner was able to know +that it would not likely find that number. + +Thanks for pointing out what the query planner was thinking, I was able +to work around it. + +John +=:-> + +--------------enigCDEA57F1EE45456906C2BF68 +Content-Type: application/pgp-signature; name="signature.asc" +Content-Description: OpenPGP digital signature +Content-Disposition: attachment; filename="signature.asc" + +-----BEGIN PGP SIGNATURE----- +Version: GnuPG v1.2.4 (Cygwin) +Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org + +iD8DBQFBWuZeJdeBCYSNAAMRAnTJAKCj6O4RFEhlaH47pwjbdSx5TRiu6ACgnv2s +I5W1E4PfmcCViXjnpiMFfFQ= +=yMm2 +-----END PGP SIGNATURE----- + +--------------enigCDEA57F1EE45456906C2BF68-- + +From pgsql-performance-owner@postgresql.org Wed Sep 29 18:44:43 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 187CF329D14 + for ; + Wed, 29 Sep 2004 18:44:36 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 34983-06 + for ; + Wed, 29 Sep 2004 17:44:15 +0000 (GMT) +Received: from fe08.axelero.hu (fe08.axelero.hu [195.228.240.96]) + by svr1.postgresql.org (Postfix) with ESMTP id 735E432A014 + for ; + Wed, 29 Sep 2004 18:43:56 +0100 (BST) +Received: from fe08 (localhost-02 [127.0.2.1]) + by fe08.axelero.hu (8.12.11/8.12.11) with SMTP id i8THgkiv045880; + Wed, 29 Sep 2004 19:42:46 +0200 (CEST) +Received: from fe08.axelero.hu [127.0.2.1] via SMTP gateway + by fe08 [195.228.240.96]; id A0B33542AB7 + at Wed, 29 Sep 2004 19:42:46 +0200 +Received: from fejleszt4 (121-248-182-81.adsl-fixip.axelero.hu + [81.182.248.121]) + by fe08.axelero.hu (8.12.11/8.12.11) with SMTP id i8THgi4j045846; + Wed, 29 Sep 2004 19:42:44 +0200 (CEST) +Message-ID: <030201c4a64b$ef96ec20$0403a8c0@fejleszt4> +From: =?iso-8859-2?B?U1rbQ1MgR+Fib3I=?= +To: +Cc: +Subject: stubborn query confuses two different servers +Date: Wed, 29 Sep 2004 19:44:13 +0200 +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-2" +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 6.00.2800.1437 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 +X-RAVMilter-Version: 8.4.3(snapshot 20030217) (fe08.axelero.hu) +Content-Transfer-Encoding: quoted-printable +X-MIME-Autoconverted: from 8bit to quoted-printable by fe08.axelero.hu id + i8THgi4j045846 +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/329 +X-Sequence-Number: 8457 + +Dear Gurus, + +Here is this strange query that can't find the optimum plan unless I disable +some scan modes or change the costs. + +(A) is a 2x2.4GHz server with hw raid5 and v7.3.4 database. It chooses +hashjoin. +(B) is a 300MHz server with 7200rpm ide and v7.4.2 database. It chooses +seqscan. + +If I disable hashjoin/seqscan+hashjoin+mergejoin, both choose index scan. +(A) goes from 1000ms to 55ms +(B) goes from 5000+ms to 300ms + +If your expert eyes could catch something missing (an index, analyze or +something), I'd be greatly honoured :) Also, tips about which optimizer +costs may be too high or too low are highly appreciated. + +As far as I fumbled with (B), disabling plans step by step got worse until +after disabled all tree. Reducing random_page_cost from 2 to 1.27 or lower +instantly activated the index scan, but I fear that it hurt most of our +other queries. The faster server did not respond to any changes, even with +rpc=3D1 and cpu_index_tuple_cost=3D0.0001, it chose hash join. + +All that I discovered is that both servers fail to find the right index +(szlltlvl_ttl_szlltlvl) unless forced to. + +In hope of an enlightening answer, +Yours, +G. +%----------------------- cut here -----------------------% +-- QUERY: +explain analyze -- 5000msec. rpc1.27-: 300 +SELECT coalesce(szallitolevel,0) AS scope_kov_szallitolevel, +CASE 'rakt=E1ros' WHEN 'rakt=E1ros' THEN szallitolevel_bejovo_e(szallitolev= +el) +WHEN 'sof=F5r' THEN 1027=3D(SELECT coalesce(sofor,0) FROM szallitolevel WHE= +RE +az=3Dszallitolevel) ELSE true END +FROM +(SELECT l.az AS szallitolevel +FROM szallitolevel l, szallitolevel_tetele t +WHERE szallitas=3D1504 AND allapot NOT IN (6,7,8) +-- pakoland=F3 t=E9telekkel + AND t.szallitolevel =3D l.az AND NOT t.archiv +-- ha arch=EDv van, de most nincs, legf=F6ljebb k=F6v k=F6rben kibukik + AND t.fajta IN (4,90,100) +GROUP BY t.szallitolevel, l.az +HAVING count(t.*)>0) t1 +NATURAL FULL OUTER JOIN +(SELECT szallitolevel, az AS pakolas FROM pakolas WHERE szallitasba=3D1504 = +AND +sztornozott_pakolas IS NULL) t2 +WHERE pakolas IS NULL ORDER BY 2 DESC LIMIT 1; +%----------------------- cut here -----------------------% +-- plan of (A), hashjoin -- + +QUERY PLAN +---------------------------------------------------------------------------- +---------------------------------------------------------------------------- +-------------------------------------------------------- + Limit (cost=3D2795.58..2795.58 rows=3D1 width=3D12) (actual +time=3D1089.72..1089.72 rows=3D1 loops=3D1) + -> Sort (cost=3D2795.58..2804.26 rows=3D3472 width=3D12) (actual +time=3D1089.72..1089.72 rows=3D2 loops=3D1) + Sort Key: szallitolevel_bejovo_e(szallitolevel) + -> Merge Join (cost=3D2569.48..2591.39 rows=3D3472 width=3D12) (= +actual +time=3D1086.72..1089.67 rows=3D2 loops=3D1) + Merge Cond: ("outer".szallitolevel =3D "inner".szallitolevel) + Filter: ("inner".az IS NULL) + -> Sort (cost=3D1613.43..1614.15 rows=3D288 width=3D12) (a= +ctual +time=3D1054.21..1054.26 rows=3D80 loops=3D1) + Sort Key: t1.szallitolevel + -> Subquery Scan t1 (cost=3D1572.82..1601.65 rows=3D= +288 +width=3D12) (actual time=3D1050.72..1054.09 rows=3D80 loops=3D1) + -> Aggregate (cost=3D1572.82..1601.65 rows=3D2= +88 +width=3D12) (actual time=3D1050.70..1053.93 rows=3D80 loops=3D1) + Filter: (count("*") > 0) + -> Group (cost=3D1572.82..1594.44 rows= +=3D2883 +width=3D12) (actual time=3D1050.64..1052.98 rows=3D824 loops=3D1) + -> Sort (cost=3D1572.82..1580.03 +rows=3D2883 width=3D12) (actual time=3D1050.63..1051.24 rows=3D824 loops=3D= +1) + Sort Key: t.szallitolevel, l.az + -> Hash Join +(cost=3D531.09..1407.13 rows=3D2883 width=3D12) (actual time=3D8.13..1048.89 +rows=3D824 loops=3D1) + Hash Cond: +("outer".szallitolevel =3D "inner".az) + -> Index Scan using +szallitolevel_tetele_me on szallitolevel_tetele t (cost=3D0.00..2.25 +rows=3D167550 width=3D8) (actual time=3D0.18..871.77 rows=3D167888 loops=3D= +1) + Filter: ((NOT +archiv) AND ((fajta =3D 4) OR (fajta =3D 90) OR (fajta =3D 100))) + -> Hash +(cost=3D530.06..530.06 rows=3D411 width=3D4) (actual time=3D7.92..7.92 rows= +=3D0 +loops=3D1) + -> Index Scan +using szlltlvl_szllts on szallitolevel l (cost=3D0.00..530.06 rows=3D411 +width=3D4) (actual time=3D0.04..7.81 rows=3D92 loops=3D1) + Index Cond: +(szallitas =3D 1504) + Filter: +((allapot <> 6) AND (allapot <> 7) AND (allapot <> 8)) + -> Sort (cost=3D956.05..964.73 rows=3D3472 width=3D8) (act= +ual +time=3D27.80..30.24 rows=3D3456 loops=3D1) + Sort Key: pakolas.szallitolevel + -> Index Scan using pakolas_szallitasba on pakolas +(cost=3D0.00..751.87 rows=3D3472 width=3D8) (actual time=3D0.10..21.68 rows= +=3D3456 +loops=3D1) + Index Cond: (szallitasba =3D 1504) + Filter: (sztornozott_pakolas IS NULL) + Total runtime: 1090.30 msec +(28 rows) + +-- plan of (A), disabled hashjoin -- + +QUERY PLAN +---------------------------------------------------------------------------- +---------------------------------------------------------------------------- +--------------------------------------------- + Limit (cost=3D10616.86..10616.86 rows=3D1 width=3D12) (actual time=3D45.0= +4..45.04 +rows=3D1 loops=3D1) + -> Sort (cost=3D10616.86..10625.54 rows=3D3472 width=3D12) (actual +time=3D45.04..45.04 rows=3D2 loops=3D1) + Sort Key: szallitolevel_bejovo_e(szallitolevel) + -> Merge Join (cost=3D10390.77..10412.67 rows=3D3472 width=3D12) +(actual time=3D42.06..44.99 rows=3D2 loops=3D1) + Merge Cond: ("outer".szallitolevel =3D "inner".szallitolevel) + Filter: ("inner".az IS NULL) + -> Sort (cost=3D9434.71..9435.43 rows=3D288 width=3D12) (a= +ctual +time=3D19.83..19.89 rows=3D80 loops=3D1) + Sort Key: t1.szallitolevel + -> Subquery Scan t1 (cost=3D9394.10..9422.93 rows=3D= +288 +width=3D12) (actual time=3D16.39..19.71 rows=3D80 loops=3D1) + -> Aggregate (cost=3D9394.10..9422.93 rows=3D2= +88 +width=3D12) (actual time=3D16.39..19.56 rows=3D80 loops=3D1) + Filter: (count("*") > 0) + -> Group (cost=3D9394.10..9415.72 rows= +=3D2883 +width=3D12) (actual time=3D16.33..18.62 rows=3D824 loops=3D1) + -> Sort (cost=3D9394.10..9401.31 +rows=3D2883 width=3D12) (actual time=3D16.33..16.93 rows=3D824 loops=3D1) + Sort Key: t.szallitolevel, l.az + -> Nested Loop +(cost=3D0.00..9228.41 rows=3D2883 width=3D12) (actual time=3D0.07..14.79 ro= +ws=3D824 +loops=3D1) + -> Index Scan using +szlltlvl_szllts on szallitolevel l (cost=3D0.00..530.06 rows=3D411 width= +=3D4) +(actual time=3D0.04..7.97 rows=3D92 loops=3D1) + Index Cond: +(szallitas =3D 1504) + Filter: ((allapot +<> 6) AND (allapot <> 7) AND (allapot <> 8)) + -> Index Scan using +szlltlvl_ttl_szlltlvl on szallitolevel_tetele t (cost=3D0.00..20.99 rows= +=3D12 +width=3D8) (actual time=3D0.01..0.05 rows=3D9 loops=3D92) + Index Cond: +(t.szallitolevel =3D "outer".az) + Filter: ((NOT +archiv) AND ((fajta =3D 4) OR (fajta =3D 90) OR (fajta =3D 100))) + -> Sort (cost=3D956.05..964.73 rows=3D3472 width=3D8) (act= +ual tim +e=3D17.76..20.18 rows=3D3456 loops=3D1) + Sort Key: pakolas.szallitolevel + -> Index Scan using pakolas_szallitasba on pakolas +(cost=3D0.00..751.87 rows=3D3472 width=3D8) (actual time=3D0.02..11.56 rows= +=3D3456 +loops=3D1) + Index Cond: (szallitasba =3D 1504) + Filter: (sztornozott_pakolas IS NULL) + Total runtime: 45.62 msec +(27 rows) + +%----------------------- cut here -----------------------% +-- plan of (B), seqscan -- + +QUERY PLAN +---------------------------------------------------------------------------- +---------------------------------------------------------------------------- +------------------------------- + Limit (cost=3D9132.84..9132.84 rows=3D1 width=3D8) (actual +time=3D3958.144..3958.144 rows=3D0 loops=3D1) + -> Sort (cost=3D9132.84..9142.66 rows=3D3928 width=3D8) (actual +time=3D3958.132..3958.132 rows=3D0 loops=3D1) + Sort Key: szallitolevel_bejovo_e(COALESCE(t1.szallitolevel, +pakolas.szallitolevel)) + -> Merge Full Join (cost=3D8834.40..8898.34 rows=3D3928 width=3D= +8) +(actual time=3D3958.099..3958.099 rows=3D0 loops=3D1) + Merge Cond: ("outer".szallitolevel =3D "inner".szallitolevel) + Filter: ("inner".az IS NULL) + -> Sort (cost=3D7737.61..7743.49 rows=3D2352 width=3D4) (a= +ctual +time=3D3798.439..3798.594 rows=3D85 loops=3D1) + Sort Key: t1.szallitolevel + -> Subquery Scan t1 (cost=3D7570.63..7605.91 rows=3D= +2352 +width=3D4) (actual time=3D3796.553..3797.981 rows=3D85 loops=3D1) + -> HashAggregate (cost=3D7570.63..7582.39 +rows=3D2352 width=3D12) (actual time=3D3796.535..3797.493 rows=3D85 loops= +=3D1) + Filter: (count("*") > 0) + -> Hash Join (cost=3D628.69..7552.99 +rows=3D2352 width=3D12) (actual time=3D62.874..3785.188 rows=3D899 loops=3D= +1) + Hash Cond: ("outer".szallitolevel = +=3D +"inner".az) + -> Seq Scan on szallitolevel_tetele +t (cost=3D0.00..6062.06 rows=3D167743 width=3D8) (actual time=3D0.236..307= +2.882 +rows=3D167637 loops=3D1) + Filter: ((NOT archiv) AND +((fajta =3D 4) OR (fajta =3D 90) OR (fajta =3D 100))) + -> Hash (cost=3D627.86..627.86 +rows=3D335 width=3D4) (actual time=3D54.973..54.973 rows=3D0 loops=3D1) + -> Index Scan using +szlltlvl_szllts on szallitolevel l (cost=3D0.00..627.86 rows=3D335 width= +=3D4) +(actual time=3D0.592..54.298 rows=3D91 loops=3D1) + Index Cond: (szallitas = +=3D +1504) + Filter: ((allapot <> 6) +AND (allapot <> 7) AND (allapot <> 8)) + -> Sort (cost=3D1096.79..1106.61 rows=3D3928 width=3D8) (a= +ctual +time=3D137.216..143.009 rows=3D3458 loops=3D1) + Sort Key: pakolas.szallitolevel + -> Index Scan using pakolas_szallitasba on pakolas +(cost=3D0.00..862.30 rows=3D3928 width=3D8) (actual time=3D0.581..107.542 r= +ows=3D3458 +loops=3D1) + Index Cond: (szallitasba =3D 1504) + Filter: (sztornozott_pakolas IS NULL) + Total runtime: 3971.008 ms +(25 rows) + +-- plan of (B), disabled seqscan, hashjoin, mergejoin -- + +QUERY PLAN +---------------------------------------------------------------------------- +---------------------------------------------------------------------------- +------------------------------------ + Limit (cost=3D100012622.51..100012622.51 rows=3D1 width=3D8) (actual +time=3D295.102..295.102 rows=3D0 loops=3D1) + -> Sort (cost=3D100012622.51..100012632.33 rows=3D3928 width=3D8) (act= +ual +time=3D295.091..295.091 rows=3D0 loops=3D1) + Sort Key: szallitolevel_bejovo_e(COALESCE(t1.szallitolevel, +pakolas.szallitolevel)) + -> Merge Full Join (cost=3D100012324.08..100012388.02 rows=3D3928 +width=3D8) (actual time=3D295.057..295.057 rows=3D0 loops=3D1) + Merge Cond: ("outer".szallitolevel =3D "inner".szallitolevel) + Filter: ("inner".az IS NULL) + -> Sort (cost=3D11227.29..11233.17 rows=3D2352 width=3D4) = +(actual +time=3D139.055..139.200 rows=3D85 loops=3D1) + Sort Key: t1.szallitolevel + -> Subquery Scan t1 (cost=3D11060.30..11095.58 +rows=3D2352 width=3D4) (actual time=3D137.166..138.588 rows=3D85 loops=3D1) + -> HashAggregate (cost=3D11060.30..11072.06 +rows=3D2352 width=3D12) (actual time=3D137.150..138.106 rows=3D85 loops=3D1) + Filter: (count("*") > 0) + -> Nested Loop (cost=3D0.00..11042.66 +rows=3D2352 width=3D12) (actual time=3D14.451..127.809 rows=3D899 loops=3D1) + -> Index Scan using szlltlvl_szllts +on szallitolevel l (cost=3D0.00..627.86 rows=3D335 width=3D4) (actual +time=3D0.579..53.503 rows=3D91 loops=3D1) + Index Cond: (szallitas =3D 150= +4) + Filter: ((allapot <> 6) AND +(allapot <> 7) AND (allapot <> 8)) + -> Index Scan using +szlltlvl_ttl_szlltlvl on szallitolevel_tetele t (cost=3D0.00..30.91 rows= +=3D14 +width=3D8) (actual time=3D0.232..0.714 rows=3D10 loops=3D91) + Index Cond: (t.szallitolevel = +=3D +"outer".az) + Filter: ((NOT archiv) AND +((fajta =3D 4) OR (fajta =3D 90) OR (fajta =3D 100))) + -> Sort (cost=3D1096.79..1106.61 rows=3D3928 width=3D8) (a= +ctual +time=3D133.517..139.338 rows=3D3458 loops=3D1) + Sort Key: pakolas.szallitolevel + -> Index Scan using pakolas_szallitasba on pakolas +(cost=3D0.00..862.30 rows=3D3928 width=3D8) (actual time=3D0.526..103.313 r= +ows=3D3458 +loops=3D1) + Index Cond: (szallitasba =3D 1504) + Filter: (sztornozott_pakolas IS NULL) + Total runtime: 297.604 ms +(24 rows) + + +%----------------------- cut here -----------------------% + + +From pgsql-performance-owner@postgresql.org Wed Sep 29 20:41:41 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id A8665329EAD + for ; + Wed, 29 Sep 2004 20:41:36 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 75996-07 + for ; + Wed, 29 Sep 2004 19:41:32 +0000 (GMT) +Received: from aari.shi.ar (shiar.net [213.84.17.17]) + by svr1.postgresql.org (Postfix) with ESMTP id 3DBC832A0D9 + for ; + Wed, 29 Sep 2004 20:41:33 +0100 (BST) +Received: by aari.shi.ar (Postfix, from userid 1000) + id 6D6E031285; Wed, 29 Sep 2004 21:41:31 +0200 (CEST) +Date: Wed, 29 Sep 2004 21:41:31 +0200 +From: Shiar +To: pgsql-performance@postgresql.org +Subject: index not used when using function +Message-ID: <20040929194131.GH22917@shiar.org> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +X-Mailer: Mutt 1.5.4i + Vim 6.2 (Debian Sid GNU/Linux 2.6.2) +X-Face: VcS>5pP95[crO3y%~/D\dP`^QY|ah,r=QQSNBrO%EA#21cv.`uXP^w{xH^/BJM% + 'r:6P~{Nx\5Rrr\r1C[B{{ZbP9g}T1pG\9l%QIe@9):fgn-(ma.hb~n{LUmXRA + 4%/z+K; dzq@{C=VXd$NAv<|sy!r1?; + eYKcRjgzC_f(%O6@#Zxb7gJIX4QK{!'$=H_d<7rB +X-URL: http://shiar.org/ +X-Accept-Language: nl, eo, en +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/330 +X-Sequence-Number: 8458 + +Hi all, a small question: + +I've got this table "songs" and an index on column artist. Since there's about +one distinct artist for every 10 rows, it would be nice if it could use this +index when counting artists. It doesn't however: + +lyrics=> EXPLAIN ANALYZE SELECT count(DISTINCT artist) FROM songs; + Aggregate (cost=31961.26..31961.26 rows=1 width=14) (actual time=808.863..808.864 rows=1 loops=1) + -> Seq Scan on songs (cost=0.00..31950.41 rows=4341 width=14) (actual time=26.801..607.172 rows=25207 loops=1) + Total runtime: 809.106 ms + +Even with enable_seqscan to off, it just can't seem to use the index. The same +query without the count() works just fine: + +lyrics=> EXPLAIN ANALYZE SELECT DISTINCT artist FROM songs; + Unique (cost=0.00..10814.96 rows=828 width=14) (actual time=0.029..132.903 rows=3280 loops=1) + -> Index Scan using songs_artist_key on songs (cost=0.00..10804.11 rows=4341 width=14) (actual time=0.027..103.448 rows=25207 loops=1) + Total runtime: 135.697 ms + +Of course I can just take the number of rows from the latter query, but I'm +still wondering why it can't use indexes with functions. + +Thanks +-- +Shiar - http://www.shiar.org +> Faktoj estas malamik del verajh + +From pgsql-performance-owner@postgresql.org Wed Sep 29 23:16:22 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id EE8C632A072 + for ; + Wed, 29 Sep 2004 23:16:18 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 26893-06 + for ; + Wed, 29 Sep 2004 22:16:05 +0000 (GMT) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by svr1.postgresql.org (Postfix) with ESMTP id E081532A04D + for ; + Wed, 29 Sep 2004 23:16:07 +0100 (BST) +Received: from news.hub.org (news.hub.org [200.46.204.72]) + by news.hub.org (8.12.9/8.12.9) with ESMTP id i8TMG4fg029184 + for ; Wed, 29 Sep 2004 22:16:04 GMT + (envelope-from news@news.hub.org) +Received: (from news@localhost) + by news.hub.org (8.12.9/8.12.9/Submit) id i8TM0xcI025712 + for pgsql-performance@postgresql.org; Wed, 29 Sep 2004 22:00:59 GMT +From: Gaetano Mendola +X-Newsgroups: comp.databases.postgresql.performance +Subject: Re: Interest in perf testing? +Date: Thu, 30 Sep 2004 00:00:44 +0200 +Organization: PYRENET Midi-pyrenees Provider +Lines: 16 +Message-ID: <415B308C.5030904@bigfoot.com> +References: <200409281053.53355.josh@agliodbs.com> +Mime-Version: 1.0 +Content-Type: text/plain; charset=ISO-8859-1; format=flowed +Content-Transfer-Encoding: 7bit +X-Complaints-To: abuse@pyrenet.fr +To: Josh Berkus +User-Agent: Mozilla Thunderbird 0.8 (Windows/20040913) +X-Accept-Language: en-us, en +In-Reply-To: <200409281053.53355.josh@agliodbs.com> +X-Enigmail-Version: 0.86.1.0 +X-Enigmail-Supports: pgp-inline, pgp-mime +To: pgsql-performance@postgresql.org +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/331 +X-Sequence-Number: 8459 + +Josh Berkus wrote: + > Folks, + > + > I'm beginning a series of tests on OSDL's Scalable Test Platform in order to + > determine some recommended settings for many of the new PostgreSQL.conf + > parameters as well as pg_autovacuum. + > + > Is anyone else interested in helping me with this? + > + +What do you need ? + + +Regards +Gaetano Mendola + + +From pgsql-performance-owner@postgresql.org Thu Sep 30 02:46:12 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 4BFC932A1E9 + for ; + Thu, 30 Sep 2004 02:46:06 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 72835-10 + for ; + Thu, 30 Sep 2004 01:45:48 +0000 (GMT) +Received: from mail.osdl.org (fw.osdl.org [65.172.181.6]) + by svr1.postgresql.org (Postfix) with ESMTP id E2E9132A049 + for ; + Thu, 30 Sep 2004 02:45:46 +0100 (BST) +Received: (from markw@localhost) + by mail.osdl.org (8.11.6/8.11.6) id i8U1jAG20493; + Wed, 29 Sep 2004 18:45:10 -0700 +Date: Wed, 29 Sep 2004 18:45:10 -0700 +From: Mark Wong +To: Tom Lane +Cc: Bruce Momjian , + Neil Conway , Guy Thornley , + pgsql-performance@postgresql.org +Subject: Re: O_DIRECT setting +Message-ID: <20040929184510.B15723@osdl.org> +References: <200409231335.i8NDZjR21993@candle.pha.pa.us> + <26123.1095951461@sss.pgh.pa.us> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +User-Agent: Mutt/1.2.5i +In-Reply-To: <26123.1095951461@sss.pgh.pa.us>; + from tgl@sss.pgh.pa.us on Thu, Sep 23, 2004 at 10:57:41AM -0400 +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/332 +X-Sequence-Number: 8460 + +On Thu, Sep 23, 2004 at 10:57:41AM -0400, Tom Lane wrote: +> Bruce Momjian writes: +> > TODO has: +> > * Consider use of open/fcntl(O_DIRECT) to minimize OS caching +> > Should the item be removed? +> +> I think it's fine ;-) ... it says "consider it", not "do it". The point +> is that we could do with more research in this area, even if O_DIRECT +> per se is not useful. Maybe you could generalize the entry to +> "investigate ways of fine-tuning OS caching behavior". +> +> regards, tom lane +> + +I talked to Jan a little about this during OSCon since Linux filesystems +(ext2, ext3, etc) let you use O_DIRECT. He felt the only place where +PostgreSQL may benefit from this now, without managing its own buffer first, +would be with the log writer. I'm probably going to get this wrong, but +he thought it would be interesting to try an experiment by taking X number +of pages to be flushed, sort them (by age? where they go on disk?) and +write them out. He thought this would be a relatively easy thing to try, +a day or two of work. We'd really love to experiment with it. + +Mark + +From pgsql-performance-owner@postgresql.org Thu Sep 30 04:04:09 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 2CEA432A179 + for ; + Thu, 30 Sep 2004 04:03:59 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 94847-10 + for ; + Thu, 30 Sep 2004 03:03:53 +0000 (GMT) +Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) + by svr1.postgresql.org (Postfix) with ESMTP id 8313232A172 + for ; + Thu, 30 Sep 2004 04:03:51 +0100 (BST) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id i8U33cRH008907; + Wed, 29 Sep 2004 23:03:38 -0400 (EDT) +To: Mark Wong +Cc: Bruce Momjian , + Neil Conway , Guy Thornley , + pgsql-performance@postgresql.org +Subject: Re: O_DIRECT setting +In-reply-to: <20040929184510.B15723@osdl.org> +References: <200409231335.i8NDZjR21993@candle.pha.pa.us> + <26123.1095951461@sss.pgh.pa.us> <20040929184510.B15723@osdl.org> +Comments: In-reply-to Mark Wong + message dated "Wed, 29 Sep 2004 18:45:10 -0700" +Date: Wed, 29 Sep 2004 23:03:38 -0400 +Message-ID: <8906.1096513418@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/333 +X-Sequence-Number: 8461 + +Mark Wong writes: +> I talked to Jan a little about this during OSCon since Linux filesystems +> (ext2, ext3, etc) let you use O_DIRECT. He felt the only place where +> PostgreSQL may benefit from this now, without managing its own buffer first, +> would be with the log writer. I'm probably going to get this wrong, but +> he thought it would be interesting to try an experiment by taking X number +> of pages to be flushed, sort them (by age? where they go on disk?) and +> write them out. + +Hmm. Most of the time the log writer has little choice about page write +order --- certainly if all your transactions are small it's not going to +have any choice. I think this would mainly be equivalent to O_SYNC with +the extra feature of stopping the kernel from buffering the WAL data in +its own buffer cache. Which is probably useful, but I doubt it's going +to make a huge difference. + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Thu Sep 30 08:02:50 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 27B9C329CB0 + for ; + Thu, 30 Sep 2004 08:02:49 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 55725-04 + for ; + Thu, 30 Sep 2004 07:02:38 +0000 (GMT) +Received: from mail.esphion.com (mail.esphion.com [202.6.75.178]) + by svr1.postgresql.org (Postfix) with ESMTP id 2B8BE32A0A1 + for ; + Thu, 30 Sep 2004 08:02:35 +0100 (BST) +Received: (qmail 22644 invoked from network); 30 Sep 2004 07:01:57 -0000 +Received: from unknown (HELO conker.?none?) (10.0.1.137) + by mail.esphion.com with SMTP; 30 Sep 2004 07:01:57 -0000 +Received: (nullmailer pid 21525 invoked by uid 10001); + Thu, 30 Sep 2004 07:02:33 -0000 +Date: Thu, 30 Sep 2004 19:02:32 +1200 +From: Guy Thornley +To: Mark Wong +Cc: pgsql-performance@postgresql.org +Subject: Re: O_DIRECT setting +Message-ID: <20040930070232.GA8139@conker.esphion.com> +Reply-To: Guy Thornley +References: <20040920075734.GK21733@conker.esphion.com> + <20040924080703.A27640@osdl.org> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <20040924080703.A27640@osdl.org> +User-Agent: Mutt/1.5.5.1+cvs20040105i +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/334 +X-Sequence-Number: 8462 + +Sorry about the belated reply, its been busy around here. + +> > Incidentally, postgres heap files suffer really, really bad fragmentation, +> > which affects sequential scan operations (VACUUM, ANALYZE, REINDEX ...) +> > quite drastically. We have in-house patches that somewhat alleiviate this, +> > but they are not release quality. Has anybody else suffered this? +> > +> +> Any chance I could give those patches a try? I'm interested in seeing +> how they may affect our DBT-3 workload, which execute DSS type queries. + +Like I said, the patches are not release quality... if you run them on a +metadata journalling filesystem, without an 'ordered write' mode, its +possible to end up with corrupt heaps after a crash because of garbage data +in the extended files. + +If/when we move to postgres 8 I'll try to ensure the patches get re-done +with releasable quality + +Guy Thornley + +From pgsql-performance-owner@postgresql.org Thu Sep 30 14:46:01 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 2DD83329FF1; + Thu, 30 Sep 2004 14:45:58 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 96466-04; Thu, 30 Sep 2004 13:45:49 +0000 (GMT) +Received: from Herge.rcsinc.local (mail.rcsonline.com [205.217.85.91]) + by svr1.postgresql.org (Postfix) with ESMTP id 9CACD329F21; + Thu, 30 Sep 2004 14:45:51 +0100 (BST) +Content-class: urn:content-classes:message +MIME-Version: 1.0 +Content-Type: text/plain; + charset="US-ASCII" +Content-Transfer-Encoding: quoted-printable +X-MimeOLE: Produced By Microsoft Exchange V6.5.6944.0 +Subject: spurious function execution in prepared statements. +Date: Thu, 30 Sep 2004 09:45:51 -0400 +Message-ID: <6EE64EF3AB31D5448D0007DD34EEB3412A74DD@Herge.rcsinc.local> +X-MS-Has-Attach: +X-MS-TNEF-Correlator: +Thread-Topic: spurious function execution in prepared statements. +Thread-Index: AcSm88ytueeE4/ipRg2yDo3TrEZgdQ== +From: "Merlin Moncure" +To: +Cc: +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/335 +X-Sequence-Number: 8463 + +OK, I have a situation that might be a performance problem, a bug, or an +unavoidable consequence of using prepared statements. The short version +is that I am getting function executions for rows not returned in a +result set when they are in a prepared statement. + +In other words, I have a query: +select f(t.c) from t where [boolean expr on t] limit 1; + +because of the limit phrase, obviously, at most one record is returned +and f executes at most once regardless of the plan used (in practice, +sometimes index, sometimes seq_scan. + +Now, if the same query is executed as a prepared statement, +prepare ps(...) as select f(t.c) from t where [expr] limit 1; +execute ps; + +now, if ps ends up using a index scan on t, everything is ok. However, +if ps does a seqscan, f executes for every row on t examined until the +[expr] criteria is met. Is this a bug? If necessary I should be able +to set up a reproducible example. The easy workaround is to not use +prepared statements in these situations, but I need to be able to +guarantee that f only executes once (even if that means exploring +subqueries). + +Merlin + +From pgsql-performance-owner@postgresql.org Thu Sep 30 15:13:41 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 0CC5E329D55; + Thu, 30 Sep 2004 15:13:38 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 07285-07; Thu, 30 Sep 2004 14:13:25 +0000 (GMT) +Received: from mail1.panix.com (mail1.panix.com [166.84.1.72]) + by svr1.postgresql.org (Postfix) with ESMTP id CD01232A345; + Thu, 30 Sep 2004 15:13:27 +0100 (BST) +Received: from panix2.panix.com (panix2.panix.com [166.84.1.2]) + by mail1.panix.com (Postfix) with ESMTP id 4334548719; + Thu, 30 Sep 2004 10:13:24 -0400 (EDT) +Received: (from adler@localhost) + by panix2.panix.com (8.11.6p2-a/8.8.8/PanixN1.1) id i8UEDOL25410; + Thu, 30 Sep 2004 10:13:24 -0400 (EDT) +Date: Thu, 30 Sep 2004 10:13:24 -0400 +From: Michael Adler +To: Merlin Moncure +Cc: pgsql-performance@postgresql.org, pgsql-hackers@postgresql.org +Subject: Re: [HACKERS] spurious function execution in prepared statements. +Message-ID: <20040930141324.GA9170@pobox.com> +References: <6EE64EF3AB31D5448D0007DD34EEB3412A74DD@Herge.rcsinc.local> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <6EE64EF3AB31D5448D0007DD34EEB3412A74DD@Herge.rcsinc.local> +User-Agent: Mutt/1.4.2.1i +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/336 +X-Sequence-Number: 8464 + +On Thu, Sep 30, 2004 at 09:45:51AM -0400, Merlin Moncure wrote: +> Now, if the same query is executed as a prepared statement, +> prepare ps(...) as select f(t.c) from t where [expr] limit 1; +> execute ps; +> +> now, if ps ends up using a index scan on t, everything is ok. However, +> if ps does a seqscan, f executes for every row on t examined until the +> [expr] criteria is met. Is this a bug? If necessary I should be able +> to set up a reproducible example. The easy workaround is to not use +> prepared statements in these situations, but I need to be able to +> guarantee that f only executes once (even if that means exploring +> subqueries). + + +Here's another workaround that may let you use a prepared statement: + +prepare ps(...) as +select f(c) from (select c from t where [expr] limit 1) as t1 + +-Mike + +From pgsql-performance-owner@postgresql.org Thu Sep 30 15:19:30 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id A631E32A37A; + Thu, 30 Sep 2004 15:19:24 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 11733-01; Thu, 30 Sep 2004 14:19:12 +0000 (GMT) +Received: from Herge.rcsinc.local (mail.rcsonline.com [205.217.85.91]) + by svr1.postgresql.org (Postfix) with ESMTP id 63A9932A348; + Thu, 30 Sep 2004 15:19:14 +0100 (BST) +Content-class: urn:content-classes:message +MIME-Version: 1.0 +Content-Type: text/plain; + charset="US-ASCII" +Content-Transfer-Encoding: quoted-printable +X-MimeOLE: Produced By Microsoft Exchange V6.5.6944.0 +Subject: Re: [HACKERS] spurious function execution in prepared statements. +Date: Thu, 30 Sep 2004 10:19:12 -0400 +Message-ID: <6EE64EF3AB31D5448D0007DD34EEB3412A74DE@Herge.rcsinc.local> +X-MS-Has-Attach: +X-MS-TNEF-Correlator: +Thread-Topic: [HACKERS] spurious function execution in prepared statements. +Thread-Index: AcSm96aaYwjSUg9WSNqftgFXAJxevQAAAknA +From: "Merlin Moncure" +To: "Michael Adler" +Cc: , + +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/337 +X-Sequence-Number: 8465 + +> Here's another workaround that may let you use a prepared statement: +>=20 +> prepare ps(...) as +> select f(c) from (select c from t where [expr] limit 1) as t1 +>=20 +> -Mike + +I was just exploring that. In fact, the problem is not limited to +prepared statements...it's just that they are more likely to run a +seqscan so I noticed it there first. Since I am in a situation where I +need very strict control over when and why f gets executed, I pretty +much have to go with the subquery option.=20=20 + +That said, it just seems that out of result set excecutions of f should +be in violation of something...=20 + +Merlin + + +From pgsql-performance-owner@postgresql.org Thu Sep 30 15:46:04 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 469E732A0FA; + Thu, 30 Sep 2004 15:45:57 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 21777-08; Thu, 30 Sep 2004 14:45:52 +0000 (GMT) +Received: from megazone.bigpanda.com (megazone.bigpanda.com [64.147.171.210]) + by svr1.postgresql.org (Postfix) with ESMTP id BE05F32A09B; + Thu, 30 Sep 2004 15:45:55 +0100 (BST) +Received: by megazone.bigpanda.com (Postfix, from userid 1001) + id D7DCD3510F; Thu, 30 Sep 2004 07:45:40 -0700 (PDT) +Received: from localhost (localhost [127.0.0.1]) + by megazone.bigpanda.com (Postfix) with ESMTP + id D5E8E3510A; Thu, 30 Sep 2004 07:45:40 -0700 (PDT) +Date: Thu, 30 Sep 2004 07:45:40 -0700 (PDT) +From: Stephan Szabo +To: Merlin Moncure +Cc: pgsql-performance@postgresql.org, pgsql-hackers@postgresql.org +Subject: Re: spurious function execution in prepared statements. +In-Reply-To: <6EE64EF3AB31D5448D0007DD34EEB3412A74DD@Herge.rcsinc.local> +Message-ID: <20040930074054.T8163@megazone.bigpanda.com> +References: <6EE64EF3AB31D5448D0007DD34EEB3412A74DD@Herge.rcsinc.local> +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/338 +X-Sequence-Number: 8466 + + +On Thu, 30 Sep 2004, Merlin Moncure wrote: + +> OK, I have a situation that might be a performance problem, a bug, or an +> unavoidable consequence of using prepared statements. The short version +> is that I am getting function executions for rows not returned in a +> result set when they are in a prepared statement. +> +> In other words, I have a query: +> select f(t.c) from t where [boolean expr on t] limit 1; + +An actual boolean expr on t? Or on a column in t? + +> because of the limit phrase, obviously, at most one record is returned +> and f executes at most once regardless of the plan used (in practice, +> sometimes index, sometimes seq_scan. +> +> Now, if the same query is executed as a prepared statement, +> prepare ps(...) as select f(t.c) from t where [expr] limit 1; +> execute ps; +> +> now, if ps ends up using a index scan on t, everything is ok. However, +> if ps does a seqscan, f executes for every row on t examined until the +> [expr] criteria is met. Is this a bug? If necessary I should be able +> to set up a reproducible example. The easy workaround is to not use +> prepared statements in these situations, but I need to be able to +> guarantee that f only executes once (even if that means exploring +> subqueries). + +I think a reproducible example would be good. Simple attempts to duplicate +this on 8.0b2 have failed for me, unless I'm using order by. + +From pgsql-performance-owner@postgresql.org Thu Sep 30 15:46:40 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 79A2D32A135 + for ; + Thu, 30 Sep 2004 15:46:38 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 21835-08 + for ; + Thu, 30 Sep 2004 14:46:33 +0000 (GMT) +Received: from ms-smtp-03-eri0.ohiordc.rr.com + (ms-smtp-03-smtplb.ohiordc.rr.com [65.24.5.137]) + by svr1.postgresql.org (Postfix) with ESMTP id CBAFD32A11D + for ; + Thu, 30 Sep 2004 15:46:36 +0100 (BST) +Received: from scott (rrcs-70-60-69-178.central.biz.rr.com [70.60.69.178]) + by ms-smtp-03-eri0.ohiordc.rr.com (8.12.10/8.12.7) with ESMTP id + i8UEkZVd018812 for ; + Thu, 30 Sep 2004 10:46:35 -0400 (EDT) +Message-Id: <200409301446.i8UEkZVd018812@ms-smtp-03-eri0.ohiordc.rr.com> +From: "Scott Dunn" +To: +Subject: Web server to Database Taking forever +Date: Thu, 30 Sep 2004 10:46:27 -0400 +MIME-Version: 1.0 +Content-Type: multipart/alternative; + boundary="----=_NextPart_000_004D_01C4A6DA.BD2F6DE0" +X-Mailer: Microsoft Office Outlook, Build 11.0.6353 +Thread-Index: AcSm/EPp7LQF0BQJTz+o3JZxe9zgHQ== +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 +X-Virus-Scanned: Symantec AntiVirus Scan Engine +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.8 tagged_above=0.0 required=5.0 tests=HTML_40_50, + HTML_FONTCOLOR_BLUE, HTML_FONTCOLOR_RED, HTML_FONTCOLOR_UNSAFE, + HTML_MESSAGE +X-Spam-Level: +X-Archive-Number: 200409/339 +X-Sequence-Number: 8467 + +This is a multi-part message in MIME format. + +------=_NextPart_000_004D_01C4A6DA.BD2F6DE0 +Content-Type: text/plain; + charset="us-ascii" +Content-Transfer-Encoding: 7bit + +Sometimes when you click on a link on my site to access my postgres database +it takes forever for it to connect. You can click this link and see how long +it takes. + +http://www.3idiots.com:8080/example.../wantedlist.jsp + +It doesn't do it all the time. Sometimes its really fast. I can't figure out +what is wrong. If I go on the server where the database is I can connect and +run queries with no problem. I can also access the database from Access and +run queries with no problems. It is only a problem when you come from the +web. Tomcat and apache are both working. You can see this by going here + +http://www.3idiots.com:8080/example...moviesearch.jsp + +I am using +psql (PostgreSQL) 7.2.1 +tomcat 4.0.1 +apache-1.3.9-4 +Redhat linux 6.2 + +Does anyone know what I can check to see what is causing this. It seemed to +have happened all of sudden one day. I don't know what could have changed to +cause this. I have rebooted the server and it still happens. Any help will +be greatly appreciated. + +Also I need to add that I never get an error message. It just sits there for +quite some time. Eventually it will work. + + +Scott + +Scott Dunn +The Software House, Inc. +513.563.7780 + + +------=_NextPart_000_004D_01C4A6DA.BD2F6DE0 +Content-Type: text/html; + charset="us-ascii" +Content-Transfer-Encoding: quoted-printable + + + + + + +
+
Sometimes=20 +when you click on a link on my site to access my postgres database it takes= +=20 +forever for it to connect. You can click this link and see how long it=20 +takes.
http://www.3idiots.com:8080/example.../wantedlist.jsp

It doesn't do it all the time. Sometimes its really fast. I = +can't=20 +figure out what is wrong. If I go on the server where the database is I can= +=20 +connect and run queries with no problem. I can also access the database fro= +m=20 +Access and run queries with no problems. It is only a problem when you come= + from=20 +the web. Tomcat and apache are both working. You can see this by going here= +=20 +
http://www.3idiots.com:8080/example...moviesearch.jsp

I am using
psql (PostgreSQL) 7.2.1
tomcat=20 +4.0.1
apache-1.3.9-4
Redhat linux 6.2

Does anyone know what I = +can=20 +check to see what is causing this. It seemed to have happened all of sudden= + one=20 +day. I don't know what could have changed to cause this. I have rebooted th= +e=20 +server and it still happens. Any help will be greatly appreciated.

A= +lso I=20 +need to add that I never get an error message. It just sits there for quite= + some=20 +time. Eventually it will work.

+
 
+
+
<= +SPAN=20 +class=3D216330819-14042003>Scott=20 +
+
 
+
+
<= +SPAN=20 +class=3D216330819-14042003>Scott Dunn
+
<= +SPAN=20 +class=3D216330819-14042003>The Software House, Inc.= +
+
<= +SPAN=20 +class=3D216330819-14042003>513.563.7780
+
 
+ +------=_NextPart_000_004D_01C4A6DA.BD2F6DE0-- + + +From pgsql-performance-owner@postgresql.org Thu Sep 30 15:54:55 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 4DFB232A1D4; + Thu, 30 Sep 2004 15:54:53 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 26711-04; Thu, 30 Sep 2004 14:54:47 +0000 (GMT) +Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) + by svr1.postgresql.org (Postfix) with ESMTP id 39EDC32A1D2; + Thu, 30 Sep 2004 15:54:50 +0100 (BST) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id i8UEsoP5016574; + Thu, 30 Sep 2004 10:54:51 -0400 (EDT) +To: "Merlin Moncure" +Cc: pgsql-performance@postgresql.org, pgsql-hackers@postgresql.org +Subject: Re: [HACKERS] spurious function execution in prepared statements. +In-reply-to: <6EE64EF3AB31D5448D0007DD34EEB3412A74DD@Herge.rcsinc.local> +References: <6EE64EF3AB31D5448D0007DD34EEB3412A74DD@Herge.rcsinc.local> +Comments: In-reply-to "Merlin Moncure" + message dated "Thu, 30 Sep 2004 09:45:51 -0400" +Date: Thu, 30 Sep 2004 10:54:50 -0400 +Message-ID: <16573.1096556090@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/340 +X-Sequence-Number: 8468 + +"Merlin Moncure" writes: +> now, if ps ends up using a index scan on t, everything is ok. However, +> if ps does a seqscan, f executes for every row on t examined until the +> [expr] criteria is met. Is this a bug? + +Works for me. + +regression=# create function f(int) returns int as ' +regression'# begin +regression'# raise notice ''f(%)'', $1; +regression'# return $1; +regression'# end' language plpgsql; +CREATE FUNCTION +regression=# select f(unique2) from tenk1 where unique2%2 = 1 limit 2; +NOTICE: f(1) +NOTICE: f(3) + f +--- + 1 + 3 +(2 rows) + +regression=# prepare ps as +regression-# select f(unique2) from tenk1 where unique2%2 = 1 limit 2; +PREPARE +regression=# execute ps; +NOTICE: f(1) +NOTICE: f(3) + f +--- + 1 + 3 +(2 rows) + +regression=# + +You sure you aren't using f() in the WHERE clause? + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Thu Sep 30 15:58:43 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id E384332A17D; + Thu, 30 Sep 2004 15:58:40 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 26711-09; Thu, 30 Sep 2004 14:58:32 +0000 (GMT) +Received: from Herge.rcsinc.local (mail.rcsonline.com [205.217.85.91]) + by svr1.postgresql.org (Postfix) with ESMTP id 70E5F32A160; + Thu, 30 Sep 2004 15:58:34 +0100 (BST) +Content-class: urn:content-classes:message +MIME-Version: 1.0 +Content-Type: text/plain; + charset="US-ASCII" +Content-Transfer-Encoding: quoted-printable +X-MimeOLE: Produced By Microsoft Exchange V6.5.6944.0 +Subject: Re: spurious function execution in prepared statements. +Date: Thu, 30 Sep 2004 10:58:34 -0400 +Message-ID: <6EE64EF3AB31D5448D0007DD34EEB3412A74DF@Herge.rcsinc.local> +X-MS-Has-Attach: +X-MS-TNEF-Correlator: +Thread-Topic: [PERFORM] spurious function execution in prepared statements. +Thread-Index: AcSm/DBKY6gJgo9GRoKcOvodYpdOfwAADsfg +From: "Merlin Moncure" +To: "Stephan Szabo" +Cc: , + , "Tom Lane" +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/341 +X-Sequence-Number: 8469 + +Stephan Szabo wrote: +> On Thu, 30 Sep 2004, Merlin Moncure wrote: +>=20 +> > OK, I have a situation that might be a performance problem, a bug, +or an +> > unavoidable consequence of using prepared statements. The short +version +> > is that I am getting function executions for rows not returned in a +> > result set when they are in a prepared statement. +> An actual boolean expr on t? Or on a column in t? +[...] +> I think a reproducible example would be good. Simple attempts to +duplicate +> this on 8.0b2 have failed for me, unless I'm using order by. + +Note: I confirmed that breaking out the 'where' part of the query into +subquery suppresses the behavior. + +Here is the actual query: +select lock_cuid(id), * + from data3.wclaim_line_file + where wcl_vin_no >=3D '32-MHAB-C-X-7243' and=20 + (wcl_vin_no > '32-MHAB-C-X-7243' or wcl_claim_no >=3D +001) and=20 + (wcl_vin_no > '32-MHAB-C-X-7243' or wcl_claim_no > +001 or id > 2671212)=20=20 + order by wcl_vin_no, wcl_claim_no, id + limit 1 + + +Here is the prepared statement declaration: +prepare data3_read_next_wclaim_line_file_1_lock (character varying, +numeric, int8, numeric) + as select lock_cuid(id), * + from data3.wclaim_line_file + where wcl_vin_no >=3D $1 and=20 + (wcl_vin_no > $1 or wcl_claim_no >=3D $2) and=20 + (wcl_vin_no > $1 or wcl_claim_no > $2 or id > $3)=20=20 + order by wcl_vin_no, wcl_claim_no, id limit $4 + + +Here is the plan when it runs lock_cuid repeatedly (aside: disabling +seqscans causes an index plan, but that's not the point): + +esp=3D# explain execute data3_read_next_wclaim_line_file_1_lock +('32-MHAB-C-X-7243', 001, 2671212, 1); + + + QUERY PLAN + +------------------------------------------------------------------------ +---------------------------- +------------------------------------------------------------------------ +---------------------------- +-------------------------------- + Limit (cost=3D13108.95..13162.93 rows=3D21592 width=3D260) + -> Sort (cost=3D13108.95..13162.93 rows=3D21592 width=3D260) + Sort Key: wcl_vin_no, wcl_claim_no, id + -> Seq Scan on wclaim_line_file (cost=3D0.00..11554.52 +rows=3D21592 width=3D260) + Filter: (((wcl_vin_no)::text >=3D ($1)::text) AND +(((wcl_vin_no)::text > ($1)::text) OR + ((wcl_claim_no)::numeric >=3D $2)) AND (((wcl_vin_no)::text > ($1)::text) +OR ((wcl_claim_no)::numeric + > $2) OR ((id)::bigint > $3))) +(5 rows) + +From pgsql-performance-owner@postgresql.org Thu Sep 30 16:02:07 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id DA4DA32A1B4 + for ; + Thu, 30 Sep 2004 16:02:04 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 29311-04 + for ; + Thu, 30 Sep 2004 15:02:03 +0000 (GMT) +Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) + by svr1.postgresql.org (Postfix) with ESMTP id 997F232A1AC + for ; + Thu, 30 Sep 2004 16:02:02 +0100 (BST) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id i8UF21Dl016698; + Thu, 30 Sep 2004 11:02:01 -0400 (EDT) +To: "Merlin Moncure" +Cc: "Stephan Szabo" , + pgsql-performance@postgresql.org, pgsql-hackers@postgresql.org +Subject: Re: spurious function execution in prepared statements. +In-reply-to: <6EE64EF3AB31D5448D0007DD34EEB3412A74DF@Herge.rcsinc.local> +References: <6EE64EF3AB31D5448D0007DD34EEB3412A74DF@Herge.rcsinc.local> +Comments: In-reply-to "Merlin Moncure" + message dated "Thu, 30 Sep 2004 10:58:34 -0400" +Date: Thu, 30 Sep 2004 11:02:01 -0400 +Message-ID: <16697.1096556521@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/342 +X-Sequence-Number: 8470 + +"Merlin Moncure" writes: +> Here is the actual query: +> select lock_cuid(id), * +> ... +> order by wcl_vin_no, wcl_claim_no, id +> limit 1 + +Looks like Stephan made the right guess. + +Logically the LIMIT executes after the ORDER BY, so the sorted result +has to be formed completely. The fact that we are able to optimize +this in some cases does not represent a promise that we can do it in +all cases. Ergo, it's not a bug. + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Thu Sep 30 17:33:46 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id EE1A332A20F + for ; + Thu, 30 Sep 2004 17:33:44 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 60722-07 + for ; + Thu, 30 Sep 2004 16:33:40 +0000 (GMT) +Received: from mail.osdl.org (fw.osdl.org [65.172.181.6]) + by svr1.postgresql.org (Postfix) with ESMTP id 4507832A202 + for ; + Thu, 30 Sep 2004 17:33:38 +0100 (BST) +Received: (from markw@localhost) + by mail.osdl.org (8.11.6/8.11.6) id i8UGXYg18295; + Thu, 30 Sep 2004 09:33:34 -0700 +Date: Thu, 30 Sep 2004 09:33:34 -0700 +From: Mark Wong +To: Guy Thornley +Cc: pgsql-performance@postgresql.org +Subject: Re: O_DIRECT setting +Message-ID: <20040930093334.C11282@osdl.org> +References: <20040920075734.GK21733@conker.esphion.com> + <20040924080703.A27640@osdl.org> + <20040930070232.GA8139@conker.esphion.com> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +User-Agent: Mutt/1.2.5i +In-Reply-To: <20040930070232.GA8139@conker.esphion.com>; + from guy@esphion.com on Thu, Sep 30, 2004 at 07:02:32PM +1200 +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/343 +X-Sequence-Number: 8471 + +On Thu, Sep 30, 2004 at 07:02:32PM +1200, Guy Thornley wrote: +> Sorry about the belated reply, its been busy around here. +> +> > > Incidentally, postgres heap files suffer really, really bad fragmentation, +> > > which affects sequential scan operations (VACUUM, ANALYZE, REINDEX ...) +> > > quite drastically. We have in-house patches that somewhat alleiviate this, +> > > but they are not release quality. Has anybody else suffered this? +> > > +> > +> > Any chance I could give those patches a try? I'm interested in seeing +> > how they may affect our DBT-3 workload, which execute DSS type queries. +> +> Like I said, the patches are not release quality... if you run them on a +> metadata journalling filesystem, without an 'ordered write' mode, its +> possible to end up with corrupt heaps after a crash because of garbage data +> in the extended files. +> +> If/when we move to postgres 8 I'll try to ensure the patches get re-done +> with releasable quality +> +> Guy Thornley + +That's ok, we like to help test and proof things, we don't need patches to be +release quality. + +Mark + +From pgsql-performance-owner@postgresql.org Thu Sep 30 17:39:45 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 9563E329E48 + for ; + Thu, 30 Sep 2004 17:39:44 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 62980-09 + for ; + Thu, 30 Sep 2004 16:39:35 +0000 (GMT) +Received: from davinci.ethosmedia.com (server226.ethosmedia.com + [209.128.84.226]) + by svr1.postgresql.org (Postfix) with ESMTP id 3CA3532A20A + for ; + Thu, 30 Sep 2004 17:39:33 +0100 (BST) +Received: from [63.195.55.98] (account josh@agliodbs.com HELO spooky) + by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.1.8) + with ESMTP id 6436510; Thu, 30 Sep 2004 09:40:55 -0700 +From: Josh Berkus +Organization: Aglio Database Solutions +To: "Scott Dunn" +Subject: Re: Web server to Database Taking forever +Date: Thu, 30 Sep 2004 09:39:04 -0700 +User-Agent: KMail/1.6.2 +References: <200409301446.i8UEkZVd018812@ms-smtp-03-eri0.ohiordc.rr.com> +In-Reply-To: <200409301446.i8UEkZVd018812@ms-smtp-03-eri0.ohiordc.rr.com> +Cc: pgsql-performance@postgresql.org +MIME-Version: 1.0 +Content-Disposition: inline +Content-Type: text/plain; + charset="utf-8" +Content-Transfer-Encoding: 7bit +Message-Id: <200409300939.04719.josh@agliodbs.com> +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/344 +X-Sequence-Number: 8472 + +Scott, + +> Sometimes when you click on a link on my site to access my postgres +> database it takes forever for it to connect. You can click this link and +> see how long it takes. +> +> http://www.3idiots.com:8080/example.../wantedlist.jsp + +Sounds like it's a problem with your Tomcat and/or JDBC setup. Try the +pgsql-jdbc mailing list for help. + +-- +Josh Berkus +Aglio Database Solutions +San Francisco + +From pgsql-performance-owner@postgresql.org Thu Sep 30 19:58:54 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 37C9132A154 + for ; + Thu, 30 Sep 2004 19:58:53 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 08054-04 + for ; + Thu, 30 Sep 2004 18:58:43 +0000 (GMT) +Received: from ms-smtp-03-eri0.ohiordc.rr.com + (ms-smtp-03-smtplb.ohiordc.rr.com [65.24.5.137]) + by svr1.postgresql.org (Postfix) with ESMTP id 4BC5932A139 + for ; + Thu, 30 Sep 2004 19:58:42 +0100 (BST) +Received: from scott (rrcs-70-60-69-178.central.biz.rr.com [70.60.69.178]) + by ms-smtp-03-eri0.ohiordc.rr.com (8.12.10/8.12.7) with ESMTP id + i8UIwZVd027480; Thu, 30 Sep 2004 14:58:35 -0400 (EDT) +Message-Id: <200409301858.i8UIwZVd027480@ms-smtp-03-eri0.ohiordc.rr.com> +From: "Scott Dunn" +To: "'Josh Berkus'" +Cc: +Subject: Re: Web server to Database Taking forever +Date: Thu, 30 Sep 2004 14:58:27 -0400 +MIME-Version: 1.0 +Content-Type: text/plain; + charset="us-ascii" +Content-Transfer-Encoding: 7bit +X-Mailer: Microsoft Office Outlook, Build 11.0.6353 +Thread-Index: AcSnDktsdKVEMQknQdKe7q+a30gRcQAERgLA +In-Reply-To: <200409300939.04719.josh@agliodbs.com> +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 +X-Virus-Scanned: Symantec AntiVirus Scan Engine +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/345 +X-Sequence-Number: 8473 + +It is all working now. The thing is I didn't change anything. So do you +still think its Tomcat or the jdbc driver? + +-----Original Message----- +From: pgsql-performance-owner@postgresql.org +[mailto:pgsql-performance-owner@postgresql.org] On Behalf Of Josh Berkus +Sent: Thursday, September 30, 2004 12:39 PM +To: Scott Dunn +Cc: pgsql-performance@postgresql.org +Subject: Re: [PERFORM] Web server to Database Taking forever + +Scott, + +> Sometimes when you click on a link on my site to access my postgres +> database it takes forever for it to connect. You can click this link +> and see how long it takes. +> +> http://www.3idiots.com:8080/example.../wantedlist.jsp + +Sounds like it's a problem with your Tomcat and/or JDBC setup. Try the +pgsql-jdbc mailing list for help. + +-- +Josh Berkus +Aglio Database Solutions +San Francisco + +---------------------------(end of broadcast)--------------------------- +TIP 9: the planner will ignore your desire to choose an index scan if your + joining column's datatypes do not match + + +From pgsql-performance-owner@postgresql.org Thu Sep 30 20:17:22 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id B0627329ECE + for ; + Thu, 30 Sep 2004 20:17:21 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 12899-10 + for ; + Thu, 30 Sep 2004 19:17:18 +0000 (GMT) +Received: from mproxy.gmail.com (rproxy.gmail.com [64.233.170.197]) + by svr1.postgresql.org (Postfix) with ESMTP id 3848D329ED6 + for ; + Thu, 30 Sep 2004 20:17:15 +0100 (BST) +Received: by mproxy.gmail.com with SMTP id v18so3575162rnb + for ; + Thu, 30 Sep 2004 12:17:10 -0700 (PDT) +Received: by 10.38.1.72 with SMTP id 72mr570292rna; + Thu, 30 Sep 2004 12:17:10 -0700 (PDT) +Received: by 10.38.206.67 with HTTP; Thu, 30 Sep 2004 12:17:10 -0700 (PDT) +Message-ID: <376dd195040930121731d29be3@mail.gmail.com> +Date: Fri, 1 Oct 2004 03:17:10 +0800 +From: Edwin Eyan Moragas +Reply-To: Edwin Eyan Moragas +To: Scott Dunn +Subject: Re: Web server to Database Taking forever +Cc: Josh Berkus , pgsql-performance@postgresql.org +In-Reply-To: <200409301858.i8UIwZVd027480@ms-smtp-03-eri0.ohiordc.rr.com> +Mime-Version: 1.0 +Content-Type: text/plain; charset=US-ASCII +Content-Transfer-Encoding: 7bit +References: <200409300939.04719.josh@agliodbs.com> + <200409301858.i8UIwZVd027480@ms-smtp-03-eri0.ohiordc.rr.com> +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/346 +X-Sequence-Number: 8474 + +On Thu, 30 Sep 2004 14:58:27 -0400, Scott Dunn wrote: +> It is all working now. The thing is I didn't change anything. So do you +> still think its Tomcat or the jdbc driver? +> + +a suspect might be the nature of JSP. on the first hit, +JSP is converted to a Servlet, the compiled and loaded +by Tomcat. consequent hits would be fast. first one is always +slow. + +how did you connect to the database? +-- +stp, +eyan + +inhale... inhale... hold... expectorate! + +From pgsql-performance-owner@postgresql.org Thu Sep 30 21:17:36 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id F0E1F32A105 + for ; + Thu, 30 Sep 2004 21:17:34 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 29386-06 + for ; + Thu, 30 Sep 2004 20:17:29 +0000 (GMT) +Received: from mpls-qmqp-01.inet.qwest.net (mpls-qmqp-01.inet.qwest.net + [63.231.195.112]) + by svr1.postgresql.org (Postfix) with SMTP id DD235329F21 + for ; + Thu, 30 Sep 2004 21:17:28 +0100 (BST) +Received: (qmail 19125 invoked by uid 0); 30 Sep 2004 20:17:26 -0000 +Received: from unknown (63.231.195.13) + by mpls-qmqp-01.inet.qwest.net with QMQP; 30 Sep 2004 20:17:25 -0000 +Received: from 63-227-127-37.dnvr.qwest.net (HELO ?10.0.0.2?) (63.227.127.37) + by mpls-pop-13.inet.qwest.net with SMTP; 30 Sep 2004 20:17:24 -0000 +Date: Thu, 30 Sep 2004 14:19:21 -0600 +Message-Id: <1096575561.8192.32.camel@localhost.localdomain> +From: "Scott Marlowe" +To: "Scott Dunn" +Cc: "'Josh Berkus'" , + pgsql-performance@postgresql.org +Subject: Re: Web server to Database Taking forever +In-Reply-To: <200409301858.i8UIwZVd027480@ms-smtp-03-eri0.ohiordc.rr.com> +References: <200409301858.i8UIwZVd027480@ms-smtp-03-eri0.ohiordc.rr.com> +Content-Type: text/plain +Mime-Version: 1.0 +X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/347 +X-Sequence-Number: 8475 + +On Thu, 2004-09-30 at 12:58, Scott Dunn wrote: +> It is all working now. The thing is I didn't change anything. So do you +> still think its Tomcat or the jdbc driver? + +Are getting an unnaturally large number of processes or threads or +pooled connections or what-not somewhere maybe? Have you tried logging +output from something like top or iostat to see what's going crazy when +this happens? Just wondering. + + +From pgsql-performance-owner@postgresql.org Thu Sep 30 23:11:12 2004 +X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org +Received: from localhost (unknown [200.46.204.144]) + by svr1.postgresql.org (Postfix) with ESMTP id 35B1932A1A3 + for ; + Thu, 30 Sep 2004 23:11:11 +0100 (BST) +Received: from svr1.postgresql.org ([200.46.204.71]) + by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) + with ESMTP id 62895-05 + for ; + Thu, 30 Sep 2004 22:11:06 +0000 (GMT) +Received: from flake.decibel.org (flake.decibel.org [66.143.173.58]) + by svr1.postgresql.org (Postfix) with ESMTP id 15D0B32A18A + for ; + Thu, 30 Sep 2004 23:11:07 +0100 (BST) +Received: by flake.decibel.org (Postfix, from userid 1001) + id 4F4031C8B0; Thu, 30 Sep 2004 22:11:07 +0000 (GMT) +Date: Thu, 30 Sep 2004 17:11:07 -0500 +From: "Jim C. Nasby" +To: Matt Clark +Cc: Rod Taylor , 'Aaron Werman' , + 'Scott Kirkwood' , + Postgresql Performance +Subject: Re: Caching of Queries +Message-ID: <20040930221107.GP1297@decibel.org> +References: <00e801c4a4b6$5526dd30$8300a8c0@solent> + <1096306670.40463.173.camel@jester> <41587867.4090505@ymogen.net> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <41587867.4090505@ymogen.net> +X-Operating-System: FreeBSD 4.10-RELEASE-p2 i386 +X-Distributed: Join the Effort! http://www.distributed.net +User-Agent: Mutt/1.5.6i +X-Virus-Scanned: by amavisd-new at hub.org +X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= +X-Spam-Level: +X-Archive-Number: 200409/348 +X-Sequence-Number: 8476 + +On Mon, Sep 27, 2004 at 09:30:31PM +0100, Matt Clark wrote: +> It's certainly the case that the typical web app (which, along with +> warehouses, seems to be one half of the needy apps), could probably do +> worse than use pooling as well. I'm not well up enough on pooling to +> know how bulletproof it is though, which is why I included it in my list +> of things that make me go 'hmm....'. It would be really nice not to +> have to take both things together. + +If you're not using a connection pool of some kind then you might as +well forget query plan caching, because your connect overhead will swamp +the planning cost. This does not mean you have to use something like +pgpool (which makes some rather questionable claims IMO); any decent web +application language/environment will support connection pooling. +-- +Jim C. Nasby, Database Consultant decibel@decibel.org +Give your computer some brain candy! www.distributed.net Team #1828 + +Windows: "Where do you want to go today?" +Linux: "Where do you want to go tomorrow?" +FreeBSD: "Are you guys coming, or what?" +