Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7a2a1ac

Browse files
committed
Add
1 parent56970c1 commit7a2a1ac

File tree

1 file changed

+125
-1
lines changed

1 file changed

+125
-1
lines changed

‎doc/TODO.detail/typeconv

Lines changed: 125 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ From tgl@sss.pgh.pa.us Sun May 14 17:30:56 2000
122122
Received: from renoir.op.net (root@renoir.op.net [207.29.195.4])
123123
by candle.pha.pa.us (8.9.0/8.9.0) with ESMTP id RAA05808
124124
for <pgman@candle.pha.pa.us>; Sun, 14 May 2000 17:30:52 -0400 (EDT)
125-
Received: from sss2.sss.pgh.pa.us (sss.pgh.pa.us [209.114.166.2]) by renoir.op.net (o1/$Revision: 1.2 $) with ESMTP id RAA16657 for <pgman@candle.pha.pa.us>; Sun, 14 May 2000 17:29:52 -0400 (EDT)
125+
Received: from sss2.sss.pgh.pa.us (sss.pgh.pa.us [209.114.166.2]) by renoir.op.net (o1/$Revision: 1.3 $) with ESMTP id RAA16657 for <pgman@candle.pha.pa.us>; Sun, 14 May 2000 17:29:52 -0400 (EDT)
126126
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
127127
by sss2.sss.pgh.pa.us (8.9.3/8.9.3) with ESMTP id RAA20914;
128128
Sun, 14 May 2000 17:29:30 -0400 (EDT)
@@ -633,3 +633,127 @@ types.)
633633

634634
regards, tom lane
635635

636+
From pgsql-hackers-owner+M1936@postgresql.org Sun Dec 10 13:17:54 2000
637+
Received: from mail.postgresql.org (webmail.postgresql.org [216.126.85.28])
638+
by candle.pha.pa.us (8.9.0/8.9.0) with ESMTP id NAA20676
639+
for <pgman@candle.pha.pa.us>; Sun, 10 Dec 2000 13:17:54 -0500 (EST)
640+
Received: from mail.postgresql.org (webmail.postgresql.org [216.126.85.28])
641+
by mail.postgresql.org (8.11.1/8.11.1) with SMTP id eBAIGvZ40566;
642+
Sun, 10 Dec 2000 13:16:57 -0500 (EST)
643+
(envelope-from pgsql-hackers-owner+M1936@postgresql.org)
644+
Received: from sss.pgh.pa.us (sss.pgh.pa.us [209.114.132.154])
645+
by mail.postgresql.org (8.11.1/8.11.1) with ESMTP id eBAI8HZ39820
646+
for <pgsql-hackers@postgreSQL.org>; Sun, 10 Dec 2000 13:08:17 -0500 (EST)
647+
(envelope-from tgl@sss.pgh.pa.us)
648+
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
649+
by sss.pgh.pa.us (8.11.1/8.11.1) with ESMTP id eBAI82o28682;
650+
Sun, 10 Dec 2000 13:08:02 -0500 (EST)
651+
To: Thomas Lockhart <lockhart@alumni.caltech.edu>
652+
cc: pgsql-hackers@postgresql.org
653+
Subject: [HACKERS] Unknown-type resolution rules, redux
654+
Date: Sun, 10 Dec 2000 13:08:02 -0500
655+
Message-ID: <28679.976471682@sss.pgh.pa.us>
656+
From: Tom Lane <tgl@sss.pgh.pa.us>
657+
Precedence: bulk
658+
Sender: pgsql-hackers-owner@postgresql.org
659+
Status: OR
660+
661+
parse_coerce.c contains the following conversation --- I believe the
662+
first XXX comment is from me and the second from you:
663+
664+
/*
665+
* Still too many candidates? Try assigning types for the unknown
666+
* columns.
667+
*
668+
* We do this by examining each unknown argument position to see if all
669+
* the candidates agree on the type category of that slot. If so, and
670+
* if some candidates accept the preferred type in that category,
671+
* eliminate the candidates with other input types. If we are down to
672+
* one candidate at the end, we win.
673+
*
674+
* XXX It's kinda bogus to do this left-to-right, isn't it? If we
675+
* eliminate some candidates because they are non-preferred at the
676+
* first slot, we won't notice that they didn't have the same type
677+
* category for a later slot.
678+
* XXX Hmm. How else would you do this? These candidates are here because
679+
* they all have the same number of matches on arguments with explicit
680+
* types, so from here on left-to-right resolution is as good as any.
681+
* Need a counterexample to see otherwise...
682+
*/
683+
684+
The comment is out of date anyway because it fails to mention the new
685+
rule about preferring STRING category. But to answer your request for
686+
a counterexample: consider
687+
688+
SELECT foo('bar', 'baz')
689+
690+
First, suppose the available candidates are
691+
692+
foo(float8, int4)
693+
foo(float8, point)
694+
695+
In this case, we examine the first argument position, see that all the
696+
candidates agree on NUMERIC category, so we consider resolving the first
697+
unknown input to float8. That eliminates neither candidate so we move
698+
on to the second argument position. Here there is a conflict of
699+
categories so we can't eliminate anything, and we decide the call is
700+
ambiguous. That's correct (or at least Operating As Designed ;-)).
701+
702+
But now suppose we have
703+
704+
foo(float8, int4)
705+
foo(float4, point)
706+
707+
Here, at the first position we will still see that all candidates agree
708+
on NUMERIC category, and then we will eliminate candidate 2 because it
709+
isn't the preferred type in that category. Now when we come to the
710+
second argument position, there's only one candidate left so there's
711+
no category conflict. Result: this call is considered non-ambiguous.
712+
713+
This means there is a left-to-right bias in the algorithm. For example,
714+
the exact same call *would* be considered ambiguous if the candidates'
715+
argument orders were reversed:
716+
717+
foo(int4, float8)
718+
foo(point, float4)
719+
720+
I do not like that. You could maybe argue that earlier arguments are
721+
more important than later ones for functions, but it's harder to make
722+
that case for binary operators --- and in any case this behavior is
723+
extremely difficult to explain in prose.
724+
725+
To fix this, I think we need to split the loop into two passes.
726+
The first pass does *not* remove any candidates. What it does is to
727+
look separately at each UNKNOWN-argument position and attempt to deduce
728+
a probable category for it, using the following rules:
729+
730+
* If any candidate has an input type of STRING category, use STRING
731+
category; else if all candidates agree on the category, use that
732+
category; else fail because no resolution can be made.
733+
734+
* The first pass must also remember whether any candidates are of a
735+
preferred type within the selected category.
736+
737+
The probable categories and exists-preferred-type booleans are saved in
738+
local arrays. (Note this has to be done this way because
739+
IsPreferredType currently allows more than one type to be considered
740+
preferred in a category ... so the first pass cannot try to determine a
741+
unique type, only a category.)
742+
743+
If we find a category for every UNKNOWN arg, then we enter a second loop
744+
in which we discard candidates. In this pass we discard a candidate if
745+
(a) it is of the wrong category, or (b) it is of the right category but
746+
is not of preferred type in that category, *and* we found candidate(s)
747+
of preferred type at this slot.
748+
749+
If we end with exactly one candidate then we win.
750+
751+
It is clear in this algorithm that there is no order dependency: the
752+
conditions for keeping or discarding a candidate are fixed before we
753+
start the second pass, and do not vary depending on which other
754+
candidates were discarded before it.
755+
756+
Comments?
757+
758+
regards, tom lane
759+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp