Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1er4vc-0001ts-5q for pgsql-hackers@arkaria.postgresql.org; Wed, 28 Feb 2018 16:50:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1er4vb-0008PJ-2y for pgsql-hackers@arkaria.postgresql.org; Wed, 28 Feb 2018 16:50:03 +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.89) (envelope-from ) id 1er4va-0008P9-ON for pgsql-hackers@lists.postgresql.org; Wed, 28 Feb 2018 16:50:02 +0000 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1er4vS-0004hl-F9 for pgsql-hackers@postgresql.org; Wed, 28 Feb 2018 16:50:02 +0000 Received: by mail-wm0-x241.google.com with SMTP id w128so6353844wmw.0 for ; Wed, 28 Feb 2018 08:49:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language; bh=gtcwd1Qf4DRl4g5DSXqChBStD9sXc2Iaz0P+eL0How8=; b=qdJG8SVDI6dPP24Rij9XSHX2649KFXWd0m+ibbyl4CZ35kqRcW35jgcQ6S78LMi862 /EOoKdcUpP768k7Pl5nYcfL1OXly1wMrjgwO/MCvGtV6xyICQUyNCaTpzj2kAmwTUr2U Oj0dXU8pcKWIiYfs6m2FLK8WTJO6BNZ295/fh65eaxDK7ReleOniHfvXhWVoZpAYI/Tm JvN4G081Ii0wlrGQrqWkxzGIM5uyhdq7vkZMTJDxUWKYVeJseqAbaw66XGztclQsMKeT 0LtVaNYc0foMRSdkB3n2JsOIKtZTmvji9TmTS4ER4F91UcPISswHoFiBmkKVnVmzAGnj 7m4g== 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-language; bh=gtcwd1Qf4DRl4g5DSXqChBStD9sXc2Iaz0P+eL0How8=; b=LWJgGcN0eLB7J2quP+JukCWUgXsRNC7o004azT6jUoL19NfR4OqBU0/c8j12Rpfvnm 6yu/OnhXYjwdrKHm2AypMqcxro8/I8pu2jaF+K2QqnzmOK2dWdgOpVhIzLdBRwQWicnO QHJvdlssEvEU27RB6vmpq64fI0J0vQ3lbG09TroA6cfZ23Jlh0/WYYB+3Fx4vIRZuQmt nm1ZSAcFzn4Gk1q4NASE8Y8dlx5AckJwMtEGq4l8V6iMEidlEWSiIo0zn4NsaCw1qhUz ieSdWPRO0WjmL4y3bZyvsRljSfESF7648uCAIpwnEq91Sxyrnnb+NqbLNDsNTZcVBlRt KDxQ== X-Gm-Message-State: APf1xPDFvq07kPYB96qa9+EG6IIhOV827mISMfPBJHuginiENDYgxVLC VPu+ezsSL1G141PF/ZzrwPjeXV4AB9IMoZFlHH+Vh/XuCUkmyB7yNKXd20rm7XIjWj+t49Do2qP /4ZvsmazGJXbgOBk9rwNIdPa3Jkm/hr/Bez92NbI3Up7EKkq+o2suyApAda1zI1MmLZATu5caVN N4TNAHn7ys X-Google-Smtp-Source: AG47ELvmQ97y0SA03T5XaaSp4h6/wkz81pHLftFe9g3CCJ+01F6BQD24WLcYMNFrxHT/ZMgQA3JDJw== X-Received: by 10.28.136.74 with SMTP id k71mr9500052wmd.46.1519836592979; Wed, 28 Feb 2018 08:49:52 -0800 (PST) Received: from [10.137.2.19] (ip-78-102-97-226.net.upcbroadband.cz. [78.102.97.226]) by smtp.gmail.com with ESMTPSA id h1sm1644866wre.16.2018.02.28.08.49.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Feb 2018 08:49:50 -0800 (PST) Subject: Re: [HACKERS] user-defined numeric data types triggering ERROR: unsupported type To: Tom Lane Cc: PostgreSQL-development References: <9389.1506003842@sss.pgh.pa.us> <4b444362-4240-49e0-3523-724e5932b060@2ndquadrant.com> <24767.1506180446@sss.pgh.pa.us> From: Tomas Vondra Message-ID: Date: Wed, 28 Feb 2018 17:49:46 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <24767.1506180446@sss.pgh.pa.us> Content-Type: multipart/mixed; boundary="------------049FBF37C45BF6B58B3F53E7" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------049FBF37C45BF6B58B3F53E7 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit OK, time to revive this old thread ... On 09/23/2017 05:27 PM, Tom Lane wrote: > Tomas Vondra writes: >>>> [ scalarineqsel may fall over when used by extension operators ] > >> What about using two-pronged approach: > >> 1) fall back to mid bucket in back branches (9.3 - 10) >> 2) do something smarter (along the lines you outlined) in PG11 > > Sure. We need to test the fallback case anyway. > Attached is a minimal fix adding a flag to convert_numeric_to_scalar, tracking when it fails because of unsupported data type. If any of the 3 calls (value + lo/hi boundaries) sets it to 'true' we simply fall back to the default estimate (0.5) within the bucket. >>> [ sketch of a more extensible design ] > >> Sounds reasonable to me, I guess - I can't really think about anything >> simpler giving us the same flexibility. > > Actually, on further thought, that's still too simple. If you look > at convert_string_to_scalar() you'll see it's examining all three > values concurrently (the probe value, of one datatype, and two bin > boundary values of possibly a different type). The reason is that > it's stripping off whatever common prefix those strings have before > trying to form a numeric equivalent. While certainly > convert_string_to_scalar is pretty stupid in the face of non-ASCII > sort orders, the prefix-stripping is something I really don't want > to give up. So the design I sketched of considering each value > totally independently isn't good enough. > > We could, perhaps, provide an API that lets an operator estimation > function replace convert_to_scalar in toto, but that seems like > you'd still end up duplicating code in many cases. Not sure about > how to find a happy medium. > I plan to work on this improvement next, once I polish a couple of other patches for the upcoming commit fest. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services --------------049FBF37C45BF6B58B3F53E7 Content-Type: text/x-patch; name="minimal-fix-custom-numeric-types-v1.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="minimal-fix-custom-numeric-types-v1.patch" diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c index fcc8323..5f6019a 100644 --- a/src/backend/utils/adt/selfuncs.c +++ b/src/backend/utils/adt/selfuncs.c @@ -176,7 +176,7 @@ static bool estimate_multivariate_ndistinct(PlannerInfo *root, static bool convert_to_scalar(Datum value, Oid valuetypid, double *scaledvalue, Datum lobound, Datum hibound, Oid boundstypid, double *scaledlobound, double *scaledhibound); -static double convert_numeric_to_scalar(Datum value, Oid typid); +static double convert_numeric_to_scalar(Datum value, Oid typid, bool *unknown_type); static void convert_string_to_scalar(char *value, double *scaledvalue, char *lobound, @@ -4071,10 +4071,15 @@ convert_to_scalar(Datum value, Oid valuetypid, double *scaledvalue, case REGDICTIONARYOID: case REGROLEOID: case REGNAMESPACEOID: - *scaledvalue = convert_numeric_to_scalar(value, valuetypid); - *scaledlobound = convert_numeric_to_scalar(lobound, boundstypid); - *scaledhibound = convert_numeric_to_scalar(hibound, boundstypid); - return true; + { + bool unknown_type = false; + + *scaledvalue = convert_numeric_to_scalar(value, valuetypid, &unknown_type); + *scaledlobound = convert_numeric_to_scalar(lobound, boundstypid, &unknown_type); + *scaledhibound = convert_numeric_to_scalar(hibound, boundstypid, &unknown_type); + + return (!unknown_type); + } /* * Built-in string types @@ -4147,7 +4152,7 @@ convert_to_scalar(Datum value, Oid valuetypid, double *scaledvalue, * Do convert_to_scalar()'s work for any numeric data type. */ static double -convert_numeric_to_scalar(Datum value, Oid typid) +convert_numeric_to_scalar(Datum value, Oid typid, bool *unknown_type) { switch (typid) { @@ -4185,9 +4190,11 @@ convert_numeric_to_scalar(Datum value, Oid typid) /* * Can't get here unless someone tries to use scalarineqsel() on an - * operator with one numeric and one non-numeric operand. + * operator with one numeric and one non-numeric operand. Or more + * precisely, operand that we don't know how to transform to scalar. */ - elog(ERROR, "unsupported type: %u", typid); + *unknown_type = true; + return 0; } --------------049FBF37C45BF6B58B3F53E7--