Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iSlEO-00087e-P4 for pgsql-hackers@arkaria.postgresql.org; Thu, 07 Nov 2019 17:06:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iSlEN-00081P-GZ for pgsql-hackers@arkaria.postgresql.org; Thu, 07 Nov 2019 17:05:59 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iSlEN-00081H-4i for pgsql-hackers@lists.postgresql.org; Thu, 07 Nov 2019 17:05:59 +0000 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iSlEK-0005bR-OW for pgsql-hackers@postgresql.org; Thu, 07 Nov 2019 17:05:57 +0000 Received: by mail-pg1-x541.google.com with SMTP id h27so2484890pgn.0 for ; Thu, 07 Nov 2019 09:05:56 -0800 (PST) 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-language:content-transfer-encoding; bh=Z3lxZLYhEQQVZZLe8NAaL888iZPQqwarxvH52bGHkD4=; b=VVuoTKNoOJTrm7sLng8aHFO9XT8DBNIKlwKfX3R2eFPTF8t/9dTL4Jt+BbwtuKDNiQ MM8KMbHMoRZVCX4bhEK3hLihhtnzcbvzbiny3ppU5ELMTsFfM0DNNjZvF4ZXpsn/av1z cw7NjMvEQ/1xUW6+l/5PXM7o62tbkdk+4EdxQkO25KPfT9Tk80n+5DJNKXYACaMEeMDU O4/+yTIDP3j/XX1jHmu+A6JNgsy6bE27UuRgFndFUm+Vl2V8cPibsWfJ+JGo/gjSLajL 2awpnABw0GdRqwLD3l1I+gla/5mdp5sRa80IlzyV9tW0KAQGuDqrRSCrDEYXBjml4ZzL LVHA== 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 :content-transfer-encoding; bh=Z3lxZLYhEQQVZZLe8NAaL888iZPQqwarxvH52bGHkD4=; b=Q5UdpuRR2kKHOVRGHtGw7sDmbtp6yt79tFpguse0QAQJt03K4zBywuQc+bN0dINKVC DMjLRuO2ndFu9CSZN1DrP4F80QDP+oXsKMwX4q7VjSFNucKe8eMhqpEIhjSBLtl4TEwR dtX5gZd5LSGQeRpIxt0qFjJcZq/k8hjulEhP8OzK0P661P93vUGKzmySNfhsu/QZDuVY 6tUJVBBXfBrl5QkJJ40Yi5+AqhVU474fl5SAKhA60HOh4R/F4Xe05mSPy8gFnWRLwKdQ hxU4zMml2iZMsojB01lJDu50H4D/9uM4skWVX+GRlzrKFKWDGCymPfQqvesKe/InlQ7f c+0g== X-Gm-Message-State: APjAAAX2uRBvhHQ3H627h6V5XKezRIYXq72714zhjFZdPF96nHiT/zQt 1fBeWpx8luPj0WvbRuWPNjc7jzyt X-Google-Smtp-Source: APXvYqwAA8IxtOuaQ9rfkMxdwWtBACruiJy52dqQYXJWMj3fQPqhdvIj8LKwItOKIdEx5kPPLjNR+A== X-Received: by 2002:a63:d306:: with SMTP id b6mr5640796pgg.338.1573146355064; Thu, 07 Nov 2019 09:05:55 -0800 (PST) Received: from [192.168.0.17] (24-113-193-150.wavecable.com. [24.113.193.150]) by smtp.gmail.com with ESMTPSA id c62sm3304309pfa.92.2019.11.07.09.05.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 Nov 2019 09:05:54 -0800 (PST) Subject: Re: Checking return value of SPI_execute To: Alvaro Herrera , Pavel Stehule Cc: Michael Paquier , PostgreSQL-development References: <20191106151112.GA12251@alvherre.pgsql> From: Mark Dilger Message-ID: <1de13b09-a5a0-4c6e-0470-5ecebc0a7784@gmail.com> Date: Thu, 7 Nov 2019 09:05:53 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.1 MIME-Version: 1.0 In-Reply-To: <20191106151112.GA12251@alvherre.pgsql> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 11/6/19 7:11 AM, Alvaro Herrera wrote: > On 2019-Nov-06, Pavel Stehule wrote: > >> My comment was about maybe obsolescence of this API. Probably it was >> designed before exception introduction. >> >> For example - syntax error is ended by exception. Wrong numbers of argument >> is signalized by error status. I didn't study this code, but maybe was much >> more effective to raise exceptions inside SPI instead return status code. >> These errors are finished by exceptions, but these exceptions coming from >> different places. For me it looks strange, if some functions returns error >> status, but can be ended by exception too. > > Yeah, I think I'd rather have more status codes and less exceptions, > than the other way around. The problem with throwing exceptions for > every kind of error is that we don't allow exceptions to be caught (per > project policy) except to be rethrown. It seems like for errors where > the SPI code can clean up its own resources (free memory, close portals > etc), it should do such cleanup then return SPI_SYNTAX_ERROR or whatever > and the caller can decide whether to turn this into an exception or > handle in a different way; whereas for exceptions thrown by callees (say > OOM) it would just propagate the exception. This mean callers are > forced into adding code to check for return codes, but it allows more > flexibility. > I like to distinguish between (a) errors that can happen when a well written bit of C code passes possibly bad SQL through SPI, and (b) errors that can only happen when SPI is called from a poorly written C program. Examples of (a) are SPI_ERROR_COPY and SPI_ERROR_TRANSACTION, which can both happen from disallowed actions within a plpgsql function. An example of (b) is SPI_ERROR_PARAM, which only gets returned if the caller passed into SPI a plan which has nargs > 0 but then negligently passed in NULL for the args and/or argtypes. I'd like to keep the status codes for (a) but deprecate error codes for (b) in favor of elog(ERROR). I don't see that these elogs should ever be a problem, since getting one in testing would indicate the need to fix bad C code, not the need to catch an exception and take remedial action at run time. Does this adequately address your concern? My research so far indicates that most return codes are either totally unused or of type (b), with only a few of type (a). -- Mark Dilger