[PG] Another example of FCSA

发布时间 2023-11-02 20:45:49作者: winter-loo

function actual arguments and cadidates

T = (193341, 23, 23)
C = [(193341, 1700, 1700), (1700, 1700, 1700), (1043, 1700, 1700)]

query type information,

select oid, typname, typcategory typcat, typispreferred preferred from pg_type where oid in (193341, 23, 1700, 1043);

its output,

  oid   | typname | typcat | preferred
--------+---------+--------+-----------
     23 | int4    | N      | f
   1043 | varchar | S      | f
   1700 | numeric | N      | f
 193341 | clob    | S      | f

check steps:

  1. no exact match
  2. implicitly convert input function arguments to candidate function arguments

CanCoerceType(T, C0)?

193341 is 193341
23 can be numeric
23 can be numeric

Keep C0

CanCoerceType(T, C1)?

193341 can not be numeric

Throw C1

CanCoerceType(T, C2)?

193341 can be 1043
23 can be numeric
23 can be numeric

Keep C1.

Now, state changes to,

T = (193341, 23, 23)
C = [(1043, 1700, 1700), (193341, 1700, 1700)]
  1. get the base type oid of input function arguments
193341(clob) -> 25(text)
23(int4) -> 23
23 -> 23

B = (25, 23, 23)
  1. comparing C with B using scoring algorithm
B = (25, 23, 23)
C = [(1043, 1700, 1700), (193341, 1700, 1700)]
B = 25,     23,    23
C = 1043,   1700,  1700
S = 0,      0,     0

S1 = 0

Keep it now

B = 25,     23,    23
C = 193341, 1700,  1700
S = 0,      0,     0

S2 = 0

S2 equals S1, keep it also.

Final candidates,

C = [(1043, 1700, 1700), (193341, 1700, 1700)]
  1. get the type category of input function arguments
B = (25, 23, 23) -> K = ('S', 'N', 'N')
  1. comparing B with C using K.

B with C0

B =         25,     23,    23
C0 =        1043,   1700,  1700
Ck =        'S',    'N',   'N'
K  =        'S',    'N',   'N'
Preferred = f,      f,     f
S =         0,      0,     0

S1 = S(0) + S(1) + S(2) = 0

Keep it now.

B with C1

B =         25,     23,    23
C1 =        193341, 1700,  1700
Ck =        'S',    'N',   'N'
K  =        'S',    'N',   'N'
Preferred = f,      f,     f
S =         0,      0,     0

S2 = S(0) + S(1) + S(2) = 0

S2 equals to S1,

Candidates not changed,

C = [(1043, 1700, 1700), (193341, 1700, 1700)]

Still have unresolved function candidaes and have no unkown input arguments. The algorithm fails!!!