bitnine-oss / agensgraph

AgensGraph, a transactional graph database based on PostgreSQL
http://www.agensgraph.org
Other
1.32k stars 146 forks source link

AG2.12.0 graphid_labid argtype changed to integer and cause errors or terminate connection #569

Closed fourmicao closed 1 year ago

fourmicao commented 2 years ago

In AG 2.5.0 graphid_labid is defined like: CREATE OR REPLACE FUNCTION pg_catalog.graphid_labid( graphid) RETURNS integer LANGUAGE 'internal' COST 1 IMMUTABLE STRICT PARALLEL SAFE AS $BODY$ graphid_labid $BODY$; --according to pgadmin4 create script.

While in AG 2.12.0 graphid_labid is defined like: CREATE OR REPLACE FUNCTION pg_catalog.graphid_labid( integer) RETURNS bytea LANGUAGE 'internal' COST 1 IMMUTABLE STRICT PARALLEL SAFE AS $BODY$ graphid_labid $BODY$; --according to pgadmin4 create script.

When I execute function, will generate two type errors:

  1. If I use graphid_labid like AG2.5.0, will complain no compatible function type. $select graphid_labid(3.1::graphid) ERROR: function graphid_labid(graphid) does not exist LINE 1: select graphid_labid(3.1::graphid) ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. SQL state: 42883 Character: 8
  2. If I query label id using integer as parameter, will terminate connection $select graphid_labid(3); server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. The connection to the server was lost. Attempting reset: Failed.
fourmicao commented 2 years ago

I compared AG2.12.0 release sourcecode with current master branch, and found the reason:

  1. In AG2.12.0 release, pg_proc.dat defined: { oid => '7007', descr => 'get label ID of graphid', proname => 'graphid_labid', prorettype => 'bytea', proargtypes => 'int4', prosrc => 'graphid_labid' },
  2. In current master branch, pg_proc.dat defined: { oid => '7007', descr => 'get label ID of graphid',

    proname => 'graphid_labid', prorettype => 'int4', proargtypes => 'graphid', prosrc => 'graphid_labid' }

  3. According to the two definitions, AG2.12.0 is not correct and fixed in current master branch.

I did a test, just for POC and not a formal workaround, not for production :) Step 1: fix pg_proc argtype definition: postgres=# update pg_catalog.pg_proc set proargtypes=oidvectorin('7002'),prorettype=oidin('23') where proname = 'graphid_labid'; UPDATE 1

Step2: call function graphid_labid in AG2.5.0 style postgres=# select graphid_labid(3.1); graphid_labid

         3

(1 row) The result is ok now.

Step3:call function graphid_labid(integer) to check if connection will be killed after bug workaround. postgres=# select graphid_labid(3); ERROR: function graphid_labid(integer) does not exist LINE 1: select graphid_labid(3); ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts.

The result sound ok, and connection is alive.

Btw, I found many differences in pg_proc.dat between two versions. Due to lack of c programming skills, I will wait for next release, hopefully not too long to wait:).

emotionbug commented 2 years ago

Thanks for your reporting.

emotionbug commented 1 year ago

The task is complete and will be included in the next release. and, If want, you can test with a 2.12 branch.