Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id CBF3BB5DBC7 for ; Mon, 17 Oct 2011 14:27:22 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 29676-02 for ; Mon, 17 Oct 2011 17:27:16 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from mail-pz0-f44.google.com (mail-pz0-f44.google.com [209.85.210.44]) by mail.postgresql.org (Postfix) with ESMTP id 57778B5D80A for ; Mon, 17 Oct 2011 14:27:16 -0300 (ADT) Received: by pzk4 with SMTP id 4so17586614pzk.3 for ; Mon, 17 Oct 2011 10:27:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=6Q4wYCmVNkNJEE0PtLbnYmO0+NmkWUvCRvOZhdiAXDM=; b=Q6x/iZPY1D5d1VNp/wIsaYXNZdBh9++v1Ed7UL336tWsjfFNM3DB/K7uoKnWO8rEBx OnsGsORqf46Yx16FHgbMeKCZPpVOQtku4K6pCEeqN5Pa3XGKxaA54enrEf8BNk8xPSqw M4IBgbEGCOFdNkMzW1Zwwfbe7X4YDmdfRfgYs= Received: by 10.68.22.195 with SMTP id g3mr39287949pbf.108.1318872435887; Mon, 17 Oct 2011 10:27:15 -0700 (PDT) Received: from [192.168.1.189] ([61.199.203.168]) by mx.google.com with ESMTPS id h5sm60729223pbq.11.2011.10.17.10.27.14 (version=SSLv3 cipher=OTHER); Mon, 17 Oct 2011 10:27:14 -0700 (PDT) Message-ID: <4E9C6573.8050507@gmail.com> Date: Tue, 18 Oct 2011 02:27:15 +0900 From: Shigeru Hanada User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:7.0.1) Gecko/20110929 Thunderbird/7.0.1 MIME-Version: 1.0 To: Etsuro Fujita CC: pgsql-hackers@postgresql.org Subject: Re: WIP: Collecting statistics on CSV file data References: <4E6DE18B.4010505@lab.ntt.co.jp> <4E7861C1.2000607@gmail.com> <4E8EC1D8.3080700@lab.ntt.co.jp> In-Reply-To: <4E8EC1D8.3080700@lab.ntt.co.jp> Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.899 tagged_above=-5 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001 X-Spam-Level: X-Archive-Number: 201110/952 X-Sequence-Number: 196758 (2011/10/07 18:09), Etsuro Fujita wrote: > Thank you for the review and the helpful information. > I rebased. Please find attached a patch. I'll add the patch to the next CF. > > Changes: > > * cleanups and fixes > * addition of the following to ALTER FOREIGN TABLE > ALTER [COLUMN] column SET STATISTICS integer > ALTER [COLUMN] column SET ( n_distinct = val ) (n_distinct only) > ALTER [COLUMN] column RESET ( n_distinct ) > * reflection of the force_not_null info in acquiring sample rows > * documentation The new patch could be applied with some shifts. Regression tests of core and file_fdw have passed cleanly. Though I've tested only simple tests, ANALYZE works for foreign tables for file_fdw, and estimation of costs and selectivity seem appropriate. New API AnalyzeForeignTable =========================== In your design, new handler function is called instead of do_analylze_rel. IMO this hook point would be good for FDWs which can provide statistics in optimized way. For instance, pgsql_fdw can simply copy statistics from remote PostgreSQL server if they are compatible. Possible another idea is to replace acquire_sample_rows so that other FDWs can reuse most part of fileAnalyzeForeignTable and file_fdw_do_analyze_rel. And I think that AnalyzeForeignTable should be optional, and it would be very useful if a default handler is provided. Probably a default handler can use basic FDW APIs to acquire sample rows from the result of "SELECT * FROM foreign_table" with skipping periodically. It won't be efficient but I think it's not so unreasonable. Other issues ============ There are some other comments about non-critical issues. - When there is no analyzable column, vac_update_relstats is not called. Is this behavior intentional? - psql can't complete foreign table name after ANALYZE. - A new parameter has been added to vac_update_relstats in a recent commit. Perhaps 0 is OK for that parameter. - ANALYZE without relation name ignores foreign tables because get_rel_oids doesn't list foreign tables. - IMO logging "analyzing foo.bar" should not be done in AnalyzeForeignTable handler of each FDW because some FDW might forget to do it. Maybe it should be pulled up to analyze_rel or somewhere in core. - It should be mentioned in a document that foreign tables are not analyzed automatically because they are read-only. Regards, -- Shigeru Hanada