Skip to content

opt: composite-insensitive INTERVAL::STRING cast may cause correctness bugs #80999

@mgartner

Description

@mgartner

A cast from INTERVAL to STRING is labelled as composite insensitive. You can see this by adding this test to pkg/sql/opt/memo/testdata/composite_sensitive:

composite-sensitive vars=(i interval)
i::string
----
false

I believe this is incorrect because INTERVAL is a composite type, even though we don't mark it as such:

case types.BoolFamily,
types.IntFamily,
types.DateFamily,
types.TimestampFamily,
types.IntervalFamily,
types.StringFamily,
types.BytesFamily,
types.TimestampTZFamily,
types.OidFamily,
types.UuidFamily,
types.INetFamily,
types.TimeFamily,
types.JsonFamily,
types.TimeTZFamily,
types.BitFamily,
types.GeometryFamily,
types.GeographyFamily,
types.EnumFamily,
types.Box2DFamily:
return false

Notice that an equal interval can present itself in different ways, making it composite:

SELECT i1, i2, i1 = i2 FROM t;
     i1    |  i2   | ?column?
-----------+-------+-----------
  24:00:00 | 1 day |   true

Marking an expression as composite insensitive when it is not actually composite insensitive can cause correctness bugs. I don't have an example of a correctness bug caused by this at the moment, but I have a strong feeling that one exists.

Jira issue: CRDB-15403

Epic: CRDB-20062

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.T-sql-queriesSQL Queries Team

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions