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 1n8CZY-00033D-7l for pgsql-hackers@arkaria.postgresql.org; Fri, 14 Jan 2022 02:44:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1n8CZX-0007VE-5J for pgsql-hackers@arkaria.postgresql.org; Fri, 14 Jan 2022 02:44: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 1n8CZW-0007V4-SX for pgsql-hackers@lists.postgresql.org; Fri, 14 Jan 2022 02:44:10 +0000 Received: from mail-pg1-x533.google.com ([2607:f8b0:4864:20::533]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1n8CZU-0001zi-L9 for pgsql-hackers@lists.postgresql.org; Fri, 14 Jan 2022 02:44:09 +0000 Received: by mail-pg1-x533.google.com with SMTP id c5so1584055pgk.12 for ; Thu, 13 Jan 2022 18:44:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=sDpauyVc2MVLrAU9gu9u7eOR/AXZ8XgubDwQjd6Tw2c=; b=YNsY3HnH/VdIona3Bcn/CBYogbxI7RqSw9tePOkWgjC5iYZs3ulELNZjh+t/BDTxAl 9mwhNOJYg55eS7MKsj7P+XandMfbX2y5+eEiRPlvi0GoytVepVu9f0yttdakDu0ZnQ/7 NAmec+EHvb9zjPAXtihvlpmyUe/x9e82UNI1ns1heGmpA+B30IuSnA1qhNLDgngU5ic0 pTVy07yfKWE1HGWKJM8EaUpdiUzhC/W63Rt9Sn7OJDk8aYLVpi/V/KPsX9J+2iFNlLdS rrZ0LS5krqGiecVZSeIfLgr8VXIUYumrRUwJV0lSvnWFiF1f51y+DuIJuC1J8g3EWP60 6cog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=sDpauyVc2MVLrAU9gu9u7eOR/AXZ8XgubDwQjd6Tw2c=; b=hlPX1JkSoAK91vPVrkZSocaTSkrO/BCnE96rrt8DGbznB9OET+4NDK60G/Ysyll8Jn 2SFxxx446VsaBOFa5YDAl6ZzoXQ4Ad7a2uUlMSQq8VGYardt1pamtoeypHj2CEpcmD4Q 57F+2NMl+MOF88vw97j11MRNZxQNGp/xJtKGITafgdVUFJ04k7PkEVkPad3sXSJTLbUX QEQkLrR8BksD79Q/vtlhAO2tVpfCvsppfSInG11OkmCX+6HjDsUg58viJN3LoggwvS8N 3wKT0eglUdsk4Is7SF08v+2ooV0U3bZ0fn8epmVnLKHdb1wVQA7Pw3HopYLF7OF6pq1N 2SEA== X-Gm-Message-State: AOAM532mLaqcDKW/824Thuy+g+APkyKm+bqRs3aGIsZIZRwoIh+0zyV8 bhDQz9qN9n/DggEY+UPzDoQ= X-Google-Smtp-Source: ABdhPJxkH/EdQvf7x7fLCLNj9b4iHrruk8uNXIYz5kWUIA0zj1P1dv41bhEAx9Enl2QaQUcaMdloNw== X-Received: by 2002:a63:3445:: with SMTP id b66mr6316085pga.397.1642128247511; Thu, 13 Jan 2022 18:44:07 -0800 (PST) Received: from jrouhaud (1-171-185-43.dynamic-ip.hinet.net. [1.171.185.43]) by smtp.gmail.com with ESMTPSA id p18sm3896173pfq.174.2022.01.13.18.44.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jan 2022 18:44:07 -0800 (PST) Date: Fri, 14 Jan 2022 10:44:02 +0800 From: Julien Rouhaud To: Pavel Stehule Cc: Dean Rasheed , Joel Jacobson , PostgreSQL Hackers Subject: Re: Schema variables - new implementation for Postgres 15 Message-ID: <20220114024402.btyn7vrpkhnso2bq@jrouhaud> References: <68eedf25-79ca-d0e7-1af6-bad225fdcd97@enterprisedb.com> <1ebeaf57-da83-42e1-9302-fb126281814d@www.fastmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On Thu, Jan 13, 2022 at 07:32:26PM +0100, Pavel Stehule wrote: > čt 13. 1. 2022 v 19:23 odesílatel Dean Rasheed > napsal: > > > On Thu, 13 Jan 2022 at 17:42, Pavel Stehule > > wrote: > > > > > > I like the idea of prioritizing tables over variables with warnings when > > collision is detected. It cannot break anything. And it allows to using > > short identifiers when there is not collision. > > > > Yeah, that seems OK, as long as it's clearly documented. I don't think > > a warning is necessary. What should be the behavior for a cached plan that uses a variable when a conflicting relation is later created? I think that it should be the same as a search_path change and the plan should be discarded. > The warning can be disabled by default, but I think it should be there. > This is a signal, so some in the database schema should be renamed. Maybe - > session_variables_ambiguity_warning. I agree that having a way to know that a variable has been bypassed can be useful. > > (FWIW, testing with dbfiddle, that appears to match Db2's behaviour). > > > > Thank you for check Do you know what's oracle's behavior on that? I've been looking at the various dependency handling, and I noticed that collation are ignored, while they're accepted syntax-wise: =# create collation mycollation (locale = 'fr-FR', provider = 'icu'); CREATE COLLATION =# create variable myvariable text collate mycollation; CREATE VARIABLE =# select classid::regclass, objid, objsubid, refclassid::regclass, refobjid, refobjsubid from pg_depend where classid::regclass::text = 'pg_variable' or refclassid::regclass::text = 'pg_variable'; classid | objid | objsubid | refclassid | refobjid | refobjsubid -------------+-------+----------+--------------+----------+------------- pg_variable | 16407 | 0 | pg_namespace | 2200 | 0 (1 row) =# let myvariable = 'AA'; LET =# select 'AA' collate "en-x-icu" < myvariable; ?column? ---------- f (1 row) =# select 'AA' collate "en-x-icu" < myvariable collate mycollation; ERROR: 42P21: collation mismatch between explicit collations "en-x-icu" and "mycollation" LINE 1: select 'AA' collate "en-x-icu" < myvariable collate mycollat... So it's missing both dependency recording for variable's collation and also teaching various code that variables can have a collation. It's also missing some invalidation detection. For instance: =# create variable myval text; CREATE VARIABLE =# let myval = 'pg_class'; LET =# prepare s(text) as select relname from pg_class where relname = $1 or relname = myval; PREPARE =# set plan_cache_mode = force_generic_plan ; SET =# execute s (''); relname ---------- pg_class (1 row) =# drop variable myval ; DROP VARIABLE =# create variable myval int; CREATE VARIABLE =# execute s (''); ERROR: XX000: cache lookup failed for session variable 16408 The plan should have been discarded and the new plan should fail for type problem. Strangely, subsequent calls don't error out: =# execute s(''); relname --------- (0 rows) But doing an explain shows that there's a problem: =# explain execute s(''); ERROR: XX000: cache lookup failed for variable 16408