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 1iSNLE-0004a5-Gs for pgsql-hackers@arkaria.postgresql.org; Wed, 06 Nov 2019 15:35:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iSNLD-0005l0-2y for pgsql-hackers@arkaria.postgresql.org; Wed, 06 Nov 2019 15:35:27 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1iSNLC-0005ks-Qg for pgsql-hackers@lists.postgresql.org; Wed, 06 Nov 2019 15:35:26 +0000 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iSNL9-0005yV-Rb for pgsql-hackers@postgresql.org; Wed, 06 Nov 2019 15:35:26 +0000 Received: by mail-pf1-x441.google.com with SMTP id x28so15977461pfo.6 for ; Wed, 06 Nov 2019 07:35:23 -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=hs24UTCr0XFqRLBznVHNyO/2pvxCWXItapA/uuQkxb8=; b=CQsyTS0QB9TLbKiWq8vWsZh830u3jYLWpv7tDEEKBQPyztM1T1AU12HRJtsDm7TYA1 BJ3AElbqC4HgW9bhp3d0vPa+npHvlqCYzbbQ3Pe9wnvtF5GhjNdoeVRNVsQP2/RWZ+nZ bDbeXrPZV4lQ/t9m0e9esfxcrD+jehUJxHAYGAndcBt/xkrja68H5DU43w1EMBWdd1T+ djQLl7IHxRp8vrs8NPtmggXx8FDXyqWY9+zmCDa+53+ygOVKm+x/0R5NaGMoNhsW+n/U mq39uEqHzNYsByUokXumf3HOBhIVhnNwuU8Pfoj9jfNk8kkUTaic3sqh2qMHJh6RHDgm B4+g== 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=hs24UTCr0XFqRLBznVHNyO/2pvxCWXItapA/uuQkxb8=; b=pic88j/D8yKMtC+2D57GJKw2ACREWfytPT9FLCDJBERJVk4YiivQofcxdST7QdJXhf aHS2O4ICjqI28KPYcQRgS6edmfUXYVH23Cn12p6nOTu0xR2furU1oRAMU2QxG0TXnboP KZwb91TTiVd5V9WIQgZTsN98MiCIX6nLHau+94D6KAnY9xEaUIocNV9yKYtzWGTLJNuK wU4YjnVH6KSwL6KVntBgOKB16g9wLLJ47EozuXTgxjs5Q4nHJVVq0m7yMzAiHyQekJ7I i3kc1RF56Um4MgI/Smf0170ifvNnb7Hjyo+Cmz6DWCTi/yHBhQRprG2z1z+QP/sDUHvg APpA== X-Gm-Message-State: APjAAAUlJgjNyXSFYHJNte2wzxbvxxUSmo3+xePlOio/z+xRA8zV+6HY VymQdHX823pKwyn0DLbhF2pmRK6Y X-Google-Smtp-Source: APXvYqw4ZHpDhMhY9csx+KYphY0H+Wk25l9igMFDquQCFplX+hVt7toAQbhYkBnC7zLN3rSDifUtLw== X-Received: by 2002:a62:e716:: with SMTP id s22mr4073394pfh.258.1573054521115; Wed, 06 Nov 2019 07:35:21 -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 q13sm3483367pjq.0.2019.11.06.07.35.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 06 Nov 2019 07:35:20 -0800 (PST) Subject: Re: Checking return value of SPI_execute To: Michael Paquier Cc: PostgreSQL-development References: <17d30445-4862-7917-170f-84328dcd292d@gmail.com> <20191106042757.GE1604@paquier.xyz> From: Mark Dilger Message-ID: <4bc8eca7-6efa-8174-a8cd-69167f233f6d@gmail.com> Date: Wed, 6 Nov 2019 07:35:18 -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: <20191106042757.GE1604@paquier.xyz> Content-Type: text/plain; charset=windows-1252; 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/5/19 8:27 PM, Michael Paquier wrote: > On Tue, Nov 05, 2019 at 05:21:25PM -0800, Mark Dilger wrote: >> please find attached a patch fixing a problem previously discussed [1] about >> the code inappropriately ignoring the return value from SPI_execute. >> >> I will be adding this to https://commitfest.postgresql.org/26/ >> shortly. > > Yes, this should be fixed. > >> - SPI_execute(query, true, 0); >> + spi_result = SPI_execute(query, true, 0); >> + if (spi_result < 0) >> + elog(ERROR, "SPI_execute returned %s", SPI_result_code_string(spi_result)); > > Any queries processed in xml.c are plain SELECT queries, so it seems > to me that you need to check after SPI_OK_SELECT as only valid > result. Other code that checks the return value from an SPI function is inconsistent about whether it checks for SPI_OK_SELECT or simply checks for a negative result. I was on the fence about which precedent to follow, and was just slightly in favor of testing for negative rather than SPI_OK_SELECT due to this function, query_to_oid_list, taking the query string as an argument and not controlling whether that argument is indeed a plain SELECT. I don't feel strongly about it. Mark Dilger