Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZahSM-00007D-FZ for pgsql-hackers@arkaria.postgresql.org; Sat, 12 Sep 2015 09:50:50 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZahSL-0000Fz-9D for pgsql-hackers@arkaria.postgresql.org; Sat, 12 Sep 2015 09:50:49 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZahSK-0000FC-1Z for pgsql-hackers@postgresql.org; Sat, 12 Sep 2015 09:50:48 +0000 Received: from mail-wi0-f175.google.com ([209.85.212.175]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1ZahSG-0002NZ-3D for pgsql-hackers@postgresql.org; Sat, 12 Sep 2015 09:50:46 +0000 Received: by wicgb1 with SMTP id gb1so87664111wic.1 for ; Sat, 12 Sep 2015 02:50:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :subject:references:in-reply-to:content-type :content-transfer-encoding; bh=VR86NmXJycp94QSxBxbMpmL89e7ARsATd1ujVnfEweM=; b=TD7v8uXLKLH2VPlqqHXfLMXPKPxrAMEq0EgtV6c1WRO4UYQQGww7kUx1sDUIHpD836 9pkW5zbavqqxTU26x2WdFxMmWpBWUylAccJf4j9DyRY42ondyqLynRQhCnpGjtPXW+Qa bEtMtnizgAqZzsiHdsbvz7rLXvaeuyKUSoszb0vwjnBAgr4Bl42BPrMR6tUn/ACGR7cc kcguk3+++Kcuw+bGBpWTk33J+4eYN0ObE3lUWRgRuLYw17q3KpgxX0Y6Cm2GBgBbbmby IL1EuL9E7vRuSoW3rqWNWPOqvJdyBszwisdLQo5o3oxZU26w9okAqngkppSCL4TBJ7/L dpQw== X-Gm-Message-State: ALoCoQlPYUpyvDEJjf0eTn5WPM2tZIN87Kr0IBiZ10befukVE0MHNQSpCavp2FHc6VkBsawchYOCBmAf3LBWjaniYpp8ql2t9lBuWdXGsBDcT7vHooyVQLEuToVFwqJcuz0Px7cwflGFLaziTYkHIU7qFAbvdxwOS9AJaqr53tLfYxWylK/KFo811kOdpD3pS4ApNnY0k/3Z X-Received: by 10.180.86.100 with SMTP id o4mr4940309wiz.59.1442051441783; Sat, 12 Sep 2015 02:50:41 -0700 (PDT) Received: from [10.137.2.12] (athedsl-4365271.home.otenet.gr. [79.130.11.199]) by smtp.gmail.com with ESMTPSA id h6sm3491460wiy.3.2015.09.12.02.50.40 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 12 Sep 2015 02:50:40 -0700 (PDT) Message-ID: <55F3F56C.4000604@2ndquadrant.com> Date: Sat, 12 Sep 2015 11:50:36 +0200 From: Tomas Vondra User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: pgsql-hackers@postgresql.org Subject: Re: On-demand running query plans using auto_explain and signals References: In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org Hi, I did a quick initial review of this patch today, so here are my comments so far: - ipcs.c should include utils/cmdstatus.h (the compiler complains about implicit declaration of two functions) - Attempts to get plan for simple insert queries like this INSERT INTO x SELECT * FROM x; end with a segfault, because ActivePortal->queryDesc is 0x0 for this query. Needs investigation. - The lockless approach seems fine to me, although I think the fear of performance issues is a bit moot (I don't think we expect large number of processes calling pg_cmdstatus at the same time). But it's not significantly more complex, so why not. - The patch contains pretty much no documentation, both comments at the code level and user docs. The lack of user docs is not that a big deal at this point (although the patch seems to be mature enough, although the user-level API will likely change). The lack of code comments is more serious, as it makes the review somewhat more difficult. For example it'd be very nice to document the contract for the lock-less interface. - I agree that pg_cmdstatus() is not the best API. Having something like EXPLAIN PID would be nice, but it does not really work for all the request types (just CMD_STATUS_REQUEST_EXPLAIN). Maybe there's not a single API for all cases, i.e. we should use EXPLAIN PID for one case and invent something different for the other? - Is there a particular reason why we allocate slots for auxiliary processes and not just for backends (NumBackends)? Do we expect those auxiliary processes to ever use this API? - CleanupCmdStatusSlot seems needlessly complicated. I don't quite see the need for the second argument, or the internal slot variable. Why not to simply use the MyCmdStatusSlot directly? - I also don't quite understand why we need to track css_pid for the slot? In what scenario will this actually matter? - While being able to get EXPLAIN from the running process is nice, I'm especially interested in getting EXPLAIN ANALYZE to get insight into the progress of the execution. The are other ways to get the EXPLAIN, e.g. by opening a different connection and actually running it (sure, the plan might have changed since then), but currently there's no way to get insight into the progress. From the thread I get the impression that Oleksandr also finds this useful - correct? What are the plans in this direction? ISTM we need at least two things for that to work: (a) Ability to enable instrumentation on all queries (effectively what auto_explain allows), otherwise we can't get EXPLAIN ANALYZE on the queries later. But auto_explain is an extension, so that does not seem as a good match if this is supposed to be in core. In that case a separate GUC seems appropriate. (b) Being able to run the InstrEnd* methods repeatedly - the initial message in this thread mentions issues with InstrEndLoop for example. So perhaps this is non-trivial. - And finally, I think we should really support all existing EXPLAIN formats, not just text. We need to support the other formats (yaml, json, xml) if we want to use the EXPLAIN PID approach, and it also makes the plans easier to process by additional tools. regards -- Tomas Vondra http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers