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 1pgr9d-0003Mm-BY for pgsql-bugs@arkaria.postgresql.org; Mon, 27 Mar 2023 18:01: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 1pgr8d-0006of-87 for pgsql-bugs@arkaria.postgresql.org; Mon, 27 Mar 2023 18:00:11 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pgr8c-0006oV-Tv for pgsql-bugs@lists.postgresql.org; Mon, 27 Mar 2023 18:00:10 +0000 Received: from mail-lj1-x22a.google.com ([2a00:1450:4864:20::22a]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pgr8W-0002Zl-LN for pgsql-bugs@lists.postgresql.org; Mon, 27 Mar 2023 18:00:10 +0000 Received: by mail-lj1-x22a.google.com with SMTP id 20so9975044lju.0 for ; Mon, 27 Mar 2023 11:00:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679940003; 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=aYNfTxJZVA5Sy1f2yjH13fvG3Iqh9qfrk2Ej3vqAUP0=; b=Odzo1jeFC1nk3+UlkgS8fMepJgjhTkLgX1sDHIfWBrxUX2dBi2iubNSkp3wo3xEey4 3J8HEseEgVywOdr62KiXBAvr+RglTW7uVRl4zDW1gQ/uurtk1gnCMS16NxhmAqekrGOw xhnCP8VTX4jMLBYIbxeMQlGyjp19YxgIWBE+B/8KltO5mvooff9yZiXkallRQ1XdDa6q C/IZmxx0Zex0FCQqoVUMuQgYwlcjiYh0LvuDwXCrWt8Ekz4+rSJqEQFroR8CufhzDgji CnUCYTN9fevgAs6nIcSvZHImDoM1B7j+9fyY2oG50o5tsKbOWRw5o54hm5QXmMSYAB/Q laAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679940003; 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=aYNfTxJZVA5Sy1f2yjH13fvG3Iqh9qfrk2Ej3vqAUP0=; b=bdn2HPaDc7s6jIcO0pHuPSTyZn/v2+ndry4uWBZFYJLQV0RPM0zEm+hMZTzNzYCqPa oeobIq+vZ1CXsgPsAKOVNJJZDT0XmcqdYMpHCSOs4CD8LMPM66s5Pw6WIdSeJCA32f3Y zumn9jUVqiWOJwV8pshhWnQFevmIDbgNYYb8tzmb40aXqCSyRp6ikRzu+freZESodSDr yEehd1iBiMoLOYG1bCWRItm2mmk2VesvvdnpMjdM67DmDUAUhsRCmC+0Ws9ghKyPk7IH gMkZyxTHrX/0Mfv1/xbXqUIEEfhyfbVBBGg1ZLrG8U87MST9sLTTlZQGAFgk+ic3RbRr mopQ== X-Gm-Message-State: AAQBX9fIcc4TEUMaNk3DR3DNhC3O/7O2LX5WWioj7pNiIB5wu+8O6c8n vNer3kGSGN185aoAkUd2mXE= X-Google-Smtp-Source: AKy350ZbSMO6JWAKWc1rKIU0MKNqbs5a5baOeqZ4QNjU7OtMXtAIgMNwYlqa93OU9shyGO/g6DompQ== X-Received: by 2002:a2e:9ece:0:b0:29b:b7ae:e2e4 with SMTP id h14-20020a2e9ece000000b0029bb7aee2e4mr3964565ljk.33.1679940002863; Mon, 27 Mar 2023 11:00:02 -0700 (PDT) Received: from [1.0.0.7] ([178.155.20.18]) by smtp.gmail.com with ESMTPSA id x20-20020a05651c105400b0029ee7bc0114sm2888892ljm.64.2023.03.27.11.00.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 27 Mar 2023 11:00:02 -0700 (PDT) Message-ID: <1aa2eec0-2017-3870-6d88-228d08c587d3@gmail.com> Date: Mon, 27 Mar 2023 21: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 #17872: Dropping an attribute of a composite type breaks indexes over the type silently Content-Language: en-US To: Tom Lane Cc: pgsql-bugs@lists.postgresql.org, Peter Eisentraut References: <17872-d0fbb799dc3fd85d@postgresql.org> <3169550.1679928579@sss.pgh.pa.us> <3182314.1679935605@sss.pgh.pa.us> From: Alexander Lakhin In-Reply-To: <3182314.1679935605@sss.pgh.pa.us> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Tom, 27.03.2023 19:46, Tom Lane wrote: > I wrote: >> PG Bug reporting form writes: >>> The following script: >>> CREATE TYPE ctype AS (i int, j int); >>> CREATE TABLE ctbl(a int, cf ctype); >>> CREATE UNIQUE INDEX ctbl_idx ON ctbl(cf); >>> INSERT INTO ctbl VALUES (1, '(1, 2)'::ctype), (2, '(1, 1)'::ctype); >>> ALTER TYPE ctype DROP ATTRIBUTE j; >>> Results in the UNIQUE constraint broken: >>> >> Meh. I'm happy to classify this as "so don't do that". > On the other hand, this seems considerably more troubling: > > regression=# CREATE TYPE ctype AS (i int, j int); > CREATE TYPE > regression=# CREATE TABLE ctbl(a int, b int); > CREATE TABLE > regression=# CREATE UNIQUE INDEX ctbl_idx ON ctbl((row(a,b)::ctype)); > CREATE INDEX > regression=# ALTER TYPE ctype ALTER ATTRIBUTE j type numeric; > ALTER TYPE > > If we had any data in the index, it'd now be completely broken. Yes, ALTERing the attribute/column leads to much worse things. In particular, I've seen a server crash and the "compressed pglz data is corrupt" error. (I can present the concrete queries if they can be of interest to you (maybe for including in regression tests).) As to the race condition possibility, I'm not sure that this consideration should be applicable only to this kind of DDL. (I've got a collection of crashes caused by race conditions in the existing code (#17182 and alike). I had plans to discuss this issue separately.) > This should be forbidden, but find_composite_type_dependencies > has no idea whatever that indexes might contain expression > columns of the target datatype. It does find a pg_depend > entry showing the index as dependent on the composite type, > but it ignores it because objsubid = 0 --- and would ignore it > also because of the relkind. > > I think what we should do, instead of just ignoring objsubid = 0, > is to look through the index's columns and see if any have > atttypid equal to the target type. If not, then the composite > type is used in an expression but not stored on disk, so it's > just as safe (or not) as a reference in a view. Yes, I think something like that can resolve the issue. But I would also note that the problem is not with indexes only, but also with "... partition by list(comp_type_value)", for example. Best regards, Alexander