Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TnBYY-0002NQ-8p for pgsql-performance@arkaria.postgresql.org; Mon, 24 Dec 2012 17:11:14 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1TnBYX-0007Za-Pt for pgsql-performance@arkaria.postgresql.org; Mon, 24 Dec 2012 17:11:13 +0000 Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TnBYW-0007ZV-PF for pgsql-performance@postgresql.org; Mon, 24 Dec 2012 17:11:13 +0000 Received: from mail-la0-f50.google.com ([209.85.215.50]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TnBYV-0004sx-0P for pgsql-performance@postgresql.org; Mon, 24 Dec 2012 17:11:12 +0000 Received: by mail-la0-f50.google.com with SMTP id c1so8619854lah.23 for ; Mon, 24 Dec 2012 09:11:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:content-type:mime-version:subject:from:in-reply-to:date :cc:content-transfer-encoding:message-id:references:to:x-mailer; bh=PO8pHFMjN26fOwCD3IqmT0/TI66vt6WG/shBcy9WZ+U=; b=JKRsbYHP3r/IONGcwhtEoCUZJCCE91viB+9Tohge6G85eJBc+tv48FP1BqCrO+61Wr Cof27Wt1ztDaBcBYs1u9naEBHncuQXq931S8K+EUF4wbTFieK2q6fE2LqLfHA6QJcUCE 2VoMEkCq4RHMOLGDvX9LxJpaLTt/xB2GV6amYc/9JJP+gUENwwXWUPlJUt1uZaDlkuOX Mzrg0XNUPBswoybI2DZAkCAykyiceHEuPgKWkRonDCdGDgGcih/H1Oi/HMcTZzX05S7+ yO7WGHJzEpqk8F35HYFrmZhtYGNCL+kXQb1TsCvbLzkj9HP+bHntYo9feax2gxUQ+kDm aIkw== X-Received: by 10.152.114.65 with SMTP id je1mr20968567lab.33.1356369069413; Mon, 24 Dec 2012 09:11:09 -0800 (PST) Received: from [192.168.20.2] ([176.195.167.53]) by mx.google.com with ESMTPS id er8sm7595478lbb.9.2012.12.24.09.11.08 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 24 Dec 2012 09:11:08 -0800 (PST) Content-Type: text/plain; charset=iso-8859-2 Mime-Version: 1.0 (Mac OS X Mail 6.2 \(1499\)) Subject: Re: Performance on Bulk Insert to Partitioned Table From: Evgeny Shishkin In-Reply-To: Date: Mon, 24 Dec 2012 21:11:07 +0400 Cc: Jeff Janes , =?iso-8859-2?Q?Ondrej_Ivani=E8?= , "pgsql-performance@postgresql.org" Content-Transfer-Encoding: quoted-printable Message-Id: References: , , , , To: Charles Gomes X-Mailer: Apple Mail (2.1499) X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org On Dec 24, 2012, at 9:07 PM, Charles Gomes wrote: > By the way, I've just re-wrote the code to target the partitions individu= ally and I've got almost 4 times improvement. > Shouldn't it be faster to process the trigger, I would understand if ther= e was no CPU left, but there is lots of cpu to chew. I saw your 20% idle cpu and raise eyebrows. > It seems that there will be no other way to speedup unless the insert cod= e is partition aware. >=20 > ---------------------------------------- >> From: charlesrg@outlook.com >> To: jeff.janes@gmail.com >> CC: ondrej.ivanic@gmail.com; pgsql-performance@postgresql.org >> Subject: Re: [PERFORM] Performance on Bulk Insert to Partitioned Table >> Date: Mon, 24 Dec 2012 10:51:12 -0500 >>=20 >> ________________________________ >>> Date: Sun, 23 Dec 2012 14:55:16 -0800 >>> Subject: Re: [PERFORM] Performance on Bulk Insert to Partitioned Table >>> From: jeff.janes@gmail.com >>> To: charlesrg@outlook.com >>> CC: ondrej.ivanic@gmail.com; pgsql-performance@postgresql.org >>>=20 >>> On Thursday, December 20, 2012, Charles Gomes wrote: >>> True, that's the same I feel, I will be looking to translate the >>> trigger to C if I can find good examples, that should accelerate. >>>=20 >>> I think your performance bottleneck is almost certainly the dynamic >>> SQL. Using C to generate that dynamic SQL isn't going to help much, >>> because it is still the SQL engine that has to parse, plan, and execute >>> it. >>>=20 >>> Are the vast majority if your inserts done on any given day for records >>> from that same day or the one before; or are they evenly spread over >>> the preceding year? If the former, you could use static SQL in IF and >>> ELSIF for those days, and fall back on the dynamic SQL for the >>> exceptions in the ELSE block. Of course that means you have to update >>> the trigger every day. >>>=20 >>>=20 >>> Using rules would be totally bad as I'm partitioning daily and after >>> one year having 365 lines of IF won't be fun to maintain. >>>=20 >>> Maintaining 365 lines of IF is what Perl was invented for. That goes >>> for triggers w/ static SQL as well as for rules. >>>=20 >>> If you do the static SQL in a trigger and the dates of the records are >>> evenly scattered over the preceding year, make sure your IFs are nested >>> like a binary search, not a linear search. And if they are mostly for >>> "today's" date, then make sure you search backwards. >>>=20 >>> Cheers, >>>=20 >>> Jeff >>=20 >> Jeff, I've changed the code from dynamic to: >>=20 >> CREATE OR REPLACE FUNCTION quotes_insert_trigger() >> RETURNS trigger AS $$ >> DECLARE >> r_date text; >> BEGIN >> r_date =3D to_char(new.received_time, 'YYYY_MM_DD'); >> case r_date >> when '2012_09_10' then >> insert into quotes_2012_09_10 values (NEW.*) using new; >> return; >> when '2012_09_11' then >> insert into quotes_2012_09_11 values (NEW.*) using new; >> return; >> when '2012_09_12' then >> insert into quotes_2012_09_12 values (NEW.*) using new; >> return; >> when '2012_09_13' then >> insert into quotes_2012_09_13 values (NEW.*) using new; >> return; >> when '2012_09_14' then >> insert into quotes_2012_09_14 values (NEW.*) using new; >> return; >> when '2012_09_15' then >> insert into quotes_2012_09_15 values (NEW.*) using new; >> return; >> when '2012_09_16' then >> insert into quotes_2012_09_16 values (NEW.*) using new; >> return; >> when '2012_09_17' then >> insert into quotes_2012_09_17 values (NEW.*) using new; >> return; >> when '2012_09_18' then >> insert into quotes_2012_09_18 values (NEW.*) using new; >> return; >> when '2012_09_19' then >> insert into quotes_2012_09_19 values (NEW.*) using new; >> return; >> when '2012_09_20' then >> insert into quotes_2012_09_20 values (NEW.*) using new; >> return; >> when '2012_09_21' then >> insert into quotes_2012_09_21 values (NEW.*) using new; >> return; >> when '2012_09_22' then >> insert into quotes_2012_09_22 values (NEW.*) using new; >> return; >> when '2012_09_23' then >> insert into quotes_2012_09_23 values (NEW.*) using new; >> return; >> when '2012_09_24' then >> insert into quotes_2012_09_24 values (NEW.*) using new; >> return; >> end case >> RETURN NULL; >> END; >> $$ >> LANGUAGE plpgsql; >>=20 >>=20 >> However I've got no speed improvement. >> I need to keep two weeks worth of partitions at a time, that's why all t= he WHEN statements. >> Wish postgres could automate the partition process natively like the oth= er sql db. >>=20 >> Thank you guys for your help. >>=20 >> -- >> Sent via pgsql-performance mailing list (pgsql-performance@postgresql.or= g) >> To make changes to your subscription: >> http://www.postgresql.org/mailpref/pgsql-performance=20=09=09=20=09=20= =20=20=09=09=20=20 >=20 > --=20 > Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-performance --=20 Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance