On Fri, 2005-03-25 at 01:58 -0500, Tom Lane wrote:
> Christopher Kings-Lynne <[EMAIL PROTECTED]> writes:
> >> In that case there's a datatype mismatch between the referencing and
> >> referenced columns, which prevents the index from being used for the
> >> FK check.
> > Is creating such a foreign key a WARNING yet?
> I believe so as of 8.0.  It's a bit tricky since 8.0 does allow some
> cross-type cases to be indexed, but IIRC we have a test that understands
> about that...

src/backend/commands/tablecmds.c, line 3966 in CVSTIP
 * Check that the found operator is compatible with the PK index,
 * and generate a warning if not, since otherwise costly seqscans
 * will be incurred to check FK validity.
if (!op_in_opclass(oprid(o), opclasses[i]))
        (errmsg("foreign key constraint \"%s\" "
                "will require costly sequential scans",
         errdetail("Key columns \"%s\" and \"%s\" "
                "are of different types: %s and %s.",
                 strVal(list_nth(fkconstraint->fk_attrs, i)),
                 strVal(list_nth(fkconstraint->pk_attrs, i)),

So, yes to the WARNING. Not sure about the cross-type cases...

Karim: Did this happen? If not, can you drop and re-create and confirm
that you get the WARNING? If not, we have problems.

I vote to make this an ERROR in 8.1 - I see little benefit in allowing
this situation to continue. If users do create a FK like this, it just
becomes another performance problem on list...

Best Regards, Simon Riggs

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
      joining column's datatypes do not match

Reply via email to