SPI: process exit in SPI_exec when table not exist. error code not return.
<div>Hi.</div><div> </div><div>When running a query with a not exist table in SPI_exec. the process exit with -1 in SPI_exec function.</div><div>the error code SPI_ERROR_REL_NOT_FOUND never return.</div><div> </div><div>I made a minimal reproduction code in https://github.com/Sasasu/worker_spi_table_not_exist</div><div> </div><div>The core code is:</div><div> </div><div><div> int spi = SPI_exec("select * from not_exist_table", 0);</div><div> // can not reach here<br /> Assert(spi == SPI_ERROR_REL_NOT_FOUND);</div></div><div> </div><div><div>I think it is a bug, PG_TRY macro it not mentioned in SPI document.</div><div><div>The code inside SPI should be wrapped with PG_TRY macro.</div></div></div>
2021年2月5日(金) 11:38 sasa su <i@sasa.su>:
Hi.
When running a query with a not exist table in SPI_exec. the process exit
with -1 in SPI_exec function.
the error code SPI_ERROR_REL_NOT_FOUND never return.I made a minimal reproduction code in
https://github.com/Sasasu/worker_spi_table_not_existThe core code is:
int spi = SPI_exec("select * from not_exist_table", 0);
// can not reach here
Assert(spi == SPI_ERROR_REL_NOT_FOUND);
The list of return codes returned by SPI_exec is here:
https://www.postgresql.org/docs/current/spi-spi-execute.html
and doesn't include "SPI_ERROR_REL_NOT_FOUND". The only
function which does return that is SPI_unregister_relation, see:
https://www.postgresql.org/docs/current/spi-spi-unregister-relation.html
Regards
Ian Barwick
--
EnterpriseDB: https://www.enterprisedb.com
<div>Thanks barwick,</div><div> </div><div><div>Is the process crash also expected,</div><div> </div><div><div>And dose anyone considered enhancing this API?</div></div></div><div> </div><div>05.02.2021, 10:55, "Ian Lawrence Barwick" <barwick@gmail.com>:</div><blockquote><div><div><div>2021年2月5日(金) 11:38 sasa su <<a href="mailto:i@sasa.su" rel="noopener noreferrer">i@sasa.su</a>>:</div><blockquote style="border-left-color:rgb( 204 , 204 , 204 );border-left-style:solid;border-left-width:1px;margin:0px 0px 0px 0.8ex;padding-left:1ex"><div>Hi.</div><div> </div><div>When running a query with a not exist table in SPI_exec. the process exit with -1 in SPI_exec function.</div><div>the error code SPI_ERROR_REL_NOT_FOUND never return.</div><div> </div><div>I made a minimal reproduction code in <a href="https://github.com/Sasasu/worker_spi_table_not_exist" rel="noopener noreferrer" target="_blank">https://github.com/Sasasu/worker_spi_table_not_exist</a></div><div> </div><div>The core code is:</div><div> </div><div><div> int spi = SPI_exec("select * from not_exist_table", 0);</div><div> // can not reach here<br /> Assert(spi == SPI_ERROR_REL_NOT_FOUND);</div></div></blockquote><div> </div><div> </div><div>The list of return codes returned by SPI_exec is here:</div><div> </div><div> <a href="https://www.postgresql.org/docs/current/spi-spi-execute.html" rel="noopener noreferrer">https://www.postgresql.org/docs/current/spi-spi-execute.html</a></div><div> </div><div>and doesn't include "SPI_ERROR_REL_NOT_FOUND". The only</div><div>function which does return that is SPI_unregister_relation, see:</div><div> </div><div> <a href="https://www.postgresql.org/docs/current/spi-spi-unregister-relation.html" rel="noopener noreferrer">https://www.postgresql.org/docs/current/spi-spi-unregister-relation.html</a></div><div> </div><div> </div><div>Regards</div><div> </div><div>Ian Barwick</div></div><br /><br />--<div><div>EnterpriseDB: <a href="https://www.enterprisedb.com/" rel="noopener noreferrer" target="_blank">https://www.enterprisedb.com</a><div> </div></div></div></div></blockquote>