cockroachdb / cockroachdb/cockroach
sql: `walkStmt` does not walk through every expression
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description
**Describe the problem**
[There is a comment](https://github.com/cockroachdb/cockroach/blob/bc5db235a2fa5aa2b9b4ffa4ada6d697b0919921/pkg/sql/sem/tree/walk.go#L1971) describing that `walkStmt` actually doesn't walk through everything, and it's hard to tell what is walked and what's not other than the `JoinCond` mentioned.
This is kinda bad because we depend on the `SimpleStmtVisit` is used in several places to do the query rewriting (for example rewriting sequence names into ID references, type names into ID references), we also use it to deserialize rewritten queries back to human readable object names. The reasoning behind it is that things can be renamed if we reference them by ID instead of name, and the roundtrip returns what users can read.
Now, if we don't walk everything...the roundtrip assumption can be broken in some cases, even though we should have cover more than 95% of the cases that so far not a lot of complains on such issue.
One example:
```
CREATE VIEW public.v (
b
) AS SELECT t.b FROM movr.public.t JOIN movr.public.g ON t.a = g.a AND t.b = 'a'::movr.public.e
```
Ideally, the `'a'::movr.public.e` part is rewritten as `b'\\x80':::@100112`, so that when type is renamed the view still works. Unfortunately, it breaks because the `JoinCond` is not walked.
Jira issue: CRDB-27229
Epic CRDB-60948
Contributor guide
Assessment
This issue has not been assessed yet.