Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e0rnF-0008RH-Sg for pgsql-hackers@arkaria.postgresql.org; Sat, 07 Oct 2017 16:17:38 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1e0rnF-0004b1-FN for pgsql-hackers@arkaria.postgresql.org; Sat, 07 Oct 2017 16:17:37 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1e0rlc-0007X6-AF for pgsql-hackers@postgresql.org; Sat, 07 Oct 2017 16:15:56 +0000 Received: from mail-lf0-x243.google.com ([2a00:1450:4010:c07::243]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1e0rlW-0000B3-J1 for pgsql-hackers@postgresql.org; Sat, 07 Oct 2017 16:15:55 +0000 Received: by mail-lf0-x243.google.com with SMTP id g70so7667982lfl.3 for ; Sat, 07 Oct 2017 09:15:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=oKIg6HYHaQIA9A6tVNNPuMmdAtGrSms1H3xgfDgEhMY=; b=XJ56U4G/37heVF6l0VgveTWHGKN2mOtnoSAN6N4KFp8PcEMzNVKY0w7wBHVpjIB34i XKEFBiOfo6pmrYDSduyYk/XtHM18vSokYuMI+m8MLc/LUPASJXPvKhDz60GJoKyWgK/q 7faX2L3NPHMXdUe5ZpnBx4Dt80WURnO9cCKlcSIgRjqsevzHjHl7HLxgE6ZpnySO6z5j 1Y6yvY99hNqHq6SS8JoUjzeZX/agzoH1b/YAXo+T6uVRbMtg5+qRID1ImgdoyWqXAMgs mlMLL0Am2H/TIsKOYCgDiE2McCHYurxcpPiS75QFU0fSLoShKAq0zW8tHvWlKyl7ro+A 4GIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=oKIg6HYHaQIA9A6tVNNPuMmdAtGrSms1H3xgfDgEhMY=; b=owxmjf42SNPsjqAXGIY1ItF/BsdLRO/bVvI1kSbg3p311VaRhTsISVz4An3FGwGD48 OkuqEoTRH9+blsmjNSlztBSUW0Qrnn97xWfMl2sq6yKIVmNJkdJ6H9L0jB5K2JnDKjZ4 i0lMikNcGwAFrKE+yL9y7zPiIbp4a/ITMscy1+2LwnodEq6rcqfDm1w/VSwC392v5ws+ MHGtv/qWNAfBxWagSo+WISe1y3vZO1rn3jR0Ouzrp3OQI7VjFkKWgSa1yb0vWNNU6pLA aWQboA95Cn3QE5NMadkZ7B9t/60QYQlnfMsPNSfm/LxO8LbLkiodVeu9+xCStxNUgXcf SJ9Q== X-Gm-Message-State: AMCzsaULRktD0ZXyNrFjlk0BDJPN8+BoDlvZ6JjQeq4krX3j8rOPd4B1 moBkXTXX+Ycjbw1qyQBVuQGfmmQgHyw= X-Google-Smtp-Source: AOwi7QCPdYfFChXJ4xfU84UFqUK15U4bhaVFT47dgu6FAmgfFI0/i4TU+rk9G2wmR1D35h9+AApMqg== X-Received: by 10.25.203.71 with SMTP id b68mr2173356lfg.27.1507392949551; Sat, 07 Oct 2017 09:15:49 -0700 (PDT) Received: from [192.168.43.70] ([176.59.42.11]) by smtp.gmail.com with ESMTPSA id v15sm596009ljd.0.2017.10.07.09.15.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 07 Oct 2017 09:15:48 -0700 (PDT) Subject: Re: Proposal: Local indexes for partitioned table To: Robert Haas , Alvaro Herrera Cc: Pg Hackers , Maksim Milyutin References: <20171006163715.oulhmymknz3m5mqm@alvherre.pgsql> From: Maksim Milyutin Message-ID: <5d082f83-1758-df56-a6a4-47439765048f@gmail.com> Date: Sat, 7 Oct 2017 19:15:46 +0300 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US 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 07.10.17 16:34, Robert Haas wrote: > On Fri, Oct 6, 2017 at 12:37 PM, Alvaro Herrera wrote: > One thing I'm a bit worried about is how to name these subordinate > indexes. They have to have names because that's how pg_class works, > and those names can't all be the same, again because that's how > pg_class works. There's no problem right away when you first create > the partitioned index, because you can just pick names out of a hat > using whatever name-generating algorithm seems best. However, when > you dump-and-restore (including but not limited to the pg_upgrade > case) you've got to preserve those names. If you just generate a new > name that may or may not be the same as the old one, then it may > collide with a user-specified name that only occurs later in the dump. > Also, you'll have trouble if the user has applied a COMMENT or a > SECURITY LABEL to the index because that command works by name, or if > the user has a reference to the index name inside a function or > whatever. > > These are pretty annoying corner-case bugs because they're not likely > to come up very often. Most people won't notice or care if the index > name changes. But I don't think it's acceptable to just ignore the > problem. An idea I had was to treat the abstract index - to use your > term - sort of the way we treat an extension. Normally, when you > create an index on a partitioned table, it cascades, but for dump and > restore purpose, we tag on some syntax that says "well, don't actually > create the subordinate indexes, i'll tell you about those later". > Then for each subordinate index we issue a separate CREATE INDEX > command followed by ALTER INDEX abstract_index ATTACH PARTITION > concrete_index or something of that sort. That means you can't > absolutely count on the parent index to have all of the children it's > supposed to have but maybe that's OK. AFAICS, the main problem with naming is generating new unique names for subordinate indexes on the stage of migrating data scheme (pg_dump, pg_upgrade, etc). And we cannot specify these names in the 'CREATE INDEX partitioned_index' statement therefore we have to regenerate their. In this case I propose to restore index names' hierarchy *bottom-up*, i.e. first of all create indexes for the leaf partitions and then create ones for parents up to root explicitly specifying names. When creating index on parent table we have to check is there exist any index on child table that could be child index (identical criteria). If so, not generate new index but implicitly attach that index into parent one. If we have incomplete index hierarchy, e.g. we dropped some indexes of partitions previously, then recreating of parent's index would regenerate (not attach) indexes for those partitions. We could drop those odd generated indexes after building of parent's index. This decision is not straightforward but provides to consider 'CREATE INDEX paritioned_table' statement as a cascade operation. As a result, we can specify name for each concrete index while recreating a whole hierarchy. -- Regards, Maksim Milyutin -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers