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 1iSNOF-0004iB-11 for pgsql-hackers@arkaria.postgresql.org; Wed, 06 Nov 2019 15:38:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iSNOD-00021F-Pc for pgsql-hackers@arkaria.postgresql.org; Wed, 06 Nov 2019 15:38:33 +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 1iSNOD-000216-GQ for pgsql-hackers@lists.postgresql.org; Wed, 06 Nov 2019 15:38:33 +0000 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iSNOA-00060O-Qp for pgsql-hackers@postgresql.org; Wed, 06 Nov 2019 15:38:33 +0000 Received: by mail-pf1-x444.google.com with SMTP id x28so15983320pfo.6 for ; Wed, 06 Nov 2019 07:38:30 -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=s2MBJBWHlP7bnIoZoGDSq/p3IV0tGQJl6ZbaGAu2Pfg=; b=eBb9P8y6IsgPe7HYTH4KR5b9QrEjjRWQjobRr++i0W3g54XSTNfEcZsZ4FsgNaxnrl 35+88LsIaQ+vyhkx+u0Or7Wp/02gX1pHTQrH0bR5p2JZLqNfbrjC7dbsvtp3U3E9jYB+ Bl29vetVpzZW7jXvkT+D5x34VWUmRXpQKYYV2B0kf6KyG8aNzOk1snSd4C/PeI3zFmj9 hXBCxeOqrzByTGcKkGZpjN+6KjqQoPdQ0ytinF6unDyZV70bzBoK1AgLeg/j5ufXFEgZ KPseg6G+Eyu8LgtkmAeQRf3WIhX9EeGaP/jkAmoHj6aBCfvdKp7ef5EAD6S15Hx4PeLu yf9A== 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=s2MBJBWHlP7bnIoZoGDSq/p3IV0tGQJl6ZbaGAu2Pfg=; b=P9v9as5bO8wr9SgTsV73TAZRD8ZRjK8GOzIKg27o13mVX3gIfT3Ojf8VWhG+juWPsp 8aZIRWDAPdflyWKTVIkWbOIsBpMUIxAdhZdZhfzX80evTX+FvtSqzxs6k/VoFhfRErf2 vgdwikVagks6yxzUce87vW+MZdDnsO1aPEOyt03VjbJwBKaJ+MsbfyVATnK8TsgT8art ul21PgyYJ4I+p1xJQ9HwJYsAbw1QQ+SovLh2/JQ3IQOVQCmn6BB/VOhwM0gOL4Lo9HM3 kbsYd3QMlHN+me3pfSm0N48HqJgBpnqpEkDzHVrv//bIhtk5osSFb+lwhLuRyCoffGi/ IPJw== X-Gm-Message-State: APjAAAUkS9aPagT4BhXC0/iJjiyf5R0ri6OW+YhcJaHc9UwUMu0IrDbL b9ytoVlheMHaVLl+dasDOVT+XPv4 X-Google-Smtp-Source: APXvYqz+UIA0t+THbCIayYEWtzCuc59eAeOOZ61ZmW8QUFC8pLoBBMkVwfmdTSnM4ea2AxD9vZAvQQ== X-Received: by 2002:a17:90a:970a:: with SMTP id x10mr856079pjo.39.1573054708636; Wed, 06 Nov 2019 07:38:28 -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 76sm11348891pfw.75.2019.11.06.07.38.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 06 Nov 2019 07:38:28 -0800 (PST) Subject: Re: Checking return value of SPI_execute To: Pavel Stehule , Michael Paquier Cc: PostgreSQL-development References: <17d30445-4862-7917-170f-84328dcd292d@gmail.com> <20191106042757.GE1604@paquier.xyz> From: Mark Dilger Message-ID: <2c4d660d-fbde-abb3-8ec9-7f417dbd0f41@gmail.com> Date: Wed, 6 Nov 2019 07:38:27 -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: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 11/5/19 9:54 PM, Pavel Stehule wrote: > > > st 6. 11. 2019 v 5:28 odesílatel Michael Paquier > napsal: > > 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. > > > Is generic question if this exception should not be raised somewhere in > spi.c - maybe at SPI_execute > > When you look to SPI_execute_plan, then checked errors has a character > +/- assertions. All SQL errors are ended by a exception. This API is not > too consistent after years what is used. > > I agree so this result code should be tested for better code quality. > But this API is not consistent now, and should be refactored to use a > exceptions instead result codes. Or instead error checking, a assertions > should be used. > > What do you think about it? I am creating another patch which removes most of the error codes from the interface and uses elog(ERROR) or ereport(ERROR) instead, but I anticipate a lot of debate about that design and wanted to get this simpler patch into the queue. I don't think we need to reject this patch in favor of redesigning the entire SPI API. Instead, we can apply this patch as a simple bug fix, and then if it gets removed later when the other, larger patch is committed, so be it. Does that plan seem acceptable? Mark Dilger