Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qF5Ir-0003dV-LT for pgsql-bugs@arkaria.postgresql.org; Fri, 30 Jun 2023 04:00:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1qF5Ip-0001r1-Fs for pgsql-bugs@arkaria.postgresql.org; Fri, 30 Jun 2023 04:00:11 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qF5Ip-0001qs-7H for pgsql-bugs@lists.postgresql.org; Fri, 30 Jun 2023 04:00:11 +0000 Received: from mail-lf1-x133.google.com ([2a00:1450:4864:20::133]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qF5Ii-001DGv-PO for pgsql-bugs@lists.postgresql.org; Fri, 30 Jun 2023 04:00:10 +0000 Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-4fb77f21c63so2222936e87.2 for ; Thu, 29 Jun 2023 21:00:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688097603; x=1690689603; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=sTDGoKk0yTr4TnAV6wlNZO9fSDcUsPqtd0gJ48XFXrY=; b=bHQkoeiONXNKiz7q0Gxu6aZkby7yVj4doMh7597wPSdsHBzizn8JH1/a6wv9Gvf5MT aK8PlVfuQpAzvouRiobAtkUAToFiaoUU/qoD5ZVnoGJ+SS4L6d5Lf971vcPrqAUvq3NI 8vcb2CEVoHVgPb/i9AizumDtF9kAwjNMVM8VfsTnz0c/swZZ+kJyiQtBQDC1+Cm4HV2H 1Erd5/Lmk+pnSBxCiVbuKgHPM02l1ru1YjbiA5LUozRcPP0fC24R82XidlVa4qWMoBKa LXBpyQeR+4WcaWjHA08lVEO4YFXI7Yo7eUif0LBXWT0cfVasrN36S3QLvYWW98DJG1lB rsOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688097603; x=1690689603; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=sTDGoKk0yTr4TnAV6wlNZO9fSDcUsPqtd0gJ48XFXrY=; b=E+nnWAM70TgdnICKZGKfi38YZLlAmWlMI7Vq8S5V2H604TdzTi1oAmJ4XNsM51LZrU XA61mw8IncLGmlW0DwCxLXDAeHz8ArxedJLRx/Yy7bxaU7sXjA/Yd9ueTm/6R/0mYkZu 6I5Foqa5j6E43E8K85tOypnadq/xt751d+0c5achNLQGYZng4DGh7A1KMHtZC2oZCszC CDm9CPqBtzZ01rIyO4FqV9cG+6gwDjdaTJLbQicRP1DpTjhj7e+FAQiXIwpLVSXCARpA HX+qF9PlndKy9vH1hme/M1vDhKFAEgMqifZESSn1rJHHvQxAH5xRDhUmlZoDZ1CO2s7I fE8w== X-Gm-Message-State: ABy/qLZe64uK/Y+2PQ34mSgmplnc4nOsNUXlbKqEWAczd2S6WkhlORRz 8fH9BRF6Pt0oFvNL/lbzfouJGb0uyNY= X-Google-Smtp-Source: APBJJlHS9Yi5kY5VX9wNaSL8Emede8fuiZ5rIWVGrlCeLd8MKb6w6OZx0cGaFGBhZVZQ64nFURCi6Q== X-Received: by 2002:a05:6512:158b:b0:4f8:69f8:47a0 with SMTP id bp11-20020a056512158b00b004f869f847a0mr1476449lfb.29.1688097602738; Thu, 29 Jun 2023 21:00:02 -0700 (PDT) Received: from [1.0.0.7] ([178.155.23.108]) by smtp.gmail.com with ESMTPSA id o4-20020ac24344000000b004fb8118a1aasm1388434lfl.274.2023.06.29.21.00.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 29 Jun 2023 21:00:02 -0700 (PDT) Message-ID: <9390b442-5c09-897f-a58c-b73bef7dd88c@gmail.com> Date: Fri, 30 Jun 2023 07:00:00 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: BUG #17997: Assert failed in validatePartitionedIndex() when attaching partition index to child of valid index Content-Language: en-US To: Michael Paquier Cc: Tom Lane , pgsql-bugs@lists.postgresql.org References: <17997-a044c27aef95daf8@postgresql.org> <509915.1687704058@sss.pgh.pa.us> <14987634-43c0-0cb3-e075-94d423607e08@gmail.com> <3eaa2c33-2ed1-2996-c6b6-0e7552a64cae@gmail.com> <611182a0-172e-cb80-965d-d6c69a1bde62@gmail.com> From: Alexander Lakhin In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 29.06.2023 13:39, Michael Paquier wrote: > On Thu, Jun 29, 2023 at 12:00:00PM +0300, Alexander Lakhin wrote: >> That is, the partition tree is containing no invalid indexes now, but the >> upper-level indexes in the tree are still invalid. >> Moreover, I don't know how to make them valid: >> reindex index parted_isvalid_idx; / reindex index parted_isvalid_tab_1_expr_idx; >> doesn't affect their flags indisvalid. >> (Though REINDEX for a top-level index can make leaf indexes valid.) >> Reattaching parted_isvalid_tab_11 after "update parted_isvalid_tab_11 set b=1" >> doesn't help either. > DETACH PARTITION is not possible for indexes, but you should be able > to get back to a cleaner tree by detaching a partition, dropping an > index, and re-attaching back the partitions, so as > validatePartitionedIndex() is able to trigger a refresh of > indisvalid depending on the state of the tree. Yeah, I meant DETACH PARTITION for a table. And when I tried the sequence you have described, I couldn't get a completely valid tree: alter table parted_isvalid_tab_1 detach partition parted_isvalid_tab_11; drop index parted_isvalid_idx_11; update parted_isvalid_tab_11 set b = 1; alter table parted_isvalid_tab_1 attach partition parted_isvalid_tab_11 for values from (1) to (5);            indexrelid           | indisvalid | indrelid        |           inhparent --------------------------------+------------+-----------------------+-------------------------------  parted_isvalid_idx             | f          | parted_isvalid_tab    |  parted_isvalid_tab_11_expr_idx | t          | parted_isvalid_tab_11 | parted_isvalid_tab_1_expr_idx  parted_isvalid_tab_12_expr_idx | t          | parted_isvalid_tab_12 | parted_isvalid_tab_1_expr_idx  parted_isvalid_tab_1_expr_idx  | f          | parted_isvalid_tab_1  | parted_isvalid_idx  parted_isvalid_tab_2_expr_idx  | t          | parted_isvalid_tab_2  | parted_isvalid_idx (5 rows) The index  parted_isvalid_tab_11_expr_idx is created anew and it's valid, but the higher-level indexes are still invalid. > Anyway, DefineIndex() and its handling of indisvalid is clearly wrong > when it comes to multiple partition layers as it forgets that we may > have to update the parents recursively or we could once again trigger > the assertion from validatePartitionedIndex(), which would not be a > good idea.. So my previous patch fixes that, at least. Yeah, in regard to that, your patch looks good to me. Thank you! Best regards, Alexander