cockroachdb / cockroach

CockroachDB — the cloud native, distributed SQL database designed for high availability, effortless scale, and control over data placement.
https://www.cockroachlabs.com
Other
29.96k stars 3.79k forks source link

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

Open mgartner opened 2 years ago

mgartner commented 2 years ago

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: https://github.com/cockroachdb/cockroach/blob/c1754fbf824a1a885c2cff2473b474c9479aca61/pkg/sql/catalog/colinfo/column_type_properties.go#L65-L84

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

github-actions[bot] commented 6 months ago

We have marked this issue as stale because it has been inactive for 18 months. If this issue is still relevant, removing the stale label or adding a comment will keep it active. Otherwise, we'll close it in 10 days to keep the issue queue tidy. Thank you for your contribution to CockroachDB!