Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: v20.2.0-alpha.2: could not parse value as requested type - unknown type #52134

Closed
cockroach-teamcity opened this issue Jul 30, 2020 · 4 comments · Fixed by #52416
Closed
Assignees
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. O-sentry Originated from an in-the-wild panic report.

Comments

@cockroach-teamcity
Copy link
Member

This issue was autofiled by Sentry. It represents a crash or reported error on a live cluster with telemetry enabled.

Sentry link: https://sentry.io/organizations/cockroach-labs/issues/1815307939/?referrer=webhooks_plugin

Panic message:

*errors.errorString
*safedetails.withSafeDetails: unknown type %s (%T) (1)
parse_string.go:85: *withstack.withStack (top exception)
*assert.withAssertionFailure
*errutil.withMessage
*safedetails.withSafeDetails: could not parse %q as type %s (2)
datum.go:267: *withstack.withStack (3)
*pgerror.withCandidateCode: 22P02 (4)
(check the extra data payloads)

Stacktrace (expand for inline code snippets):

if err != nil {
return pgerror.Wrapf(err, pgcode.InvalidTextRepresentation,
"could not parse %q as type %s", s, typ)
in pkg/sql/sem/tree.makeParseError
if err != nil {
return ret, false, makeParseError(s, types.MakeArray(t), err)
}
in pkg/sql/sem/tree.ParseDArrayFromString
case types.ArrayFamily:
d, dependsOnContext, err = ParseDArrayFromString(ctx, s, t.ArrayContents())
case types.BitFamily:
in pkg/sql/sem/tree.ParseAndRequireString
default:
val, dependsOnContext, err := ParseAndRequireString(typ, expr.s, dummyParseTimeContext{})
if err != nil {
in pkg/sql/sem/tree.(*StrVal).ResolveAsType
if desired.Equivalent(typ) {
return c.ResolveAsType(ctx, semaCtx, desired)
}
in pkg/sql/sem/tree.typeCheckConstant
) (TypedExpr, error) {
return typeCheckConstant(ctx, semaCtx, expr, desired)
}
in pkg/sql/sem/tree.(*StrVal).TypeCheck
) (TypedExpr, error) {
exprTyped, err := expr.Expr.TypeCheck(ctx, semaCtx, desired)
if err != nil {
in pkg/sql/sem/tree.(*ParenExpr).TypeCheck
subExpr, err := expr.Expr.TypeCheck(ctx, semaCtx, types.MakeArray(desired))
if err != nil {
in pkg/sql/sem/tree.(*IndirectionExpr).TypeCheck
return expr.TypeCheck(ctx, semaCtx, desired)
}
in pkg/sql/sem/tree.TypeCheck
expr = s.walkExprTree(expr)
texpr, err := tree.TypeCheck(s.builder.ctx, expr, s.builder.semaCtx, desired)
if err != nil {
in pkg/sql/opt/optbuilder.(*scope).resolveType
texpr = inScope.resolveType(e.Expr, desired)
}
in pkg/sql/opt/optbuilder.(*Builder).analyzeSelectList
b.analyzeSelectList(selects, desiredTypes, inScope, outScope)
}
in pkg/sql/opt/optbuilder.(*Builder).analyzeProjectionList
// aggInScope and aggOutScope.
b.analyzeProjectionList(sel.Exprs, desiredTypes, fromScope, projectionsScope)
in pkg/sql/opt/optbuilder.(*Builder).buildSelectClause
case *tree.SelectClause:
outScope = b.buildSelectClause(t, orderBy, locking, desiredTypes, inScope)
in pkg/sql/opt/optbuilder.(*Builder).buildSelectStmtWithoutParens
return b.processWiths(with, inScope, func(inScope *scope) *scope {
return b.buildSelectStmtWithoutParens(
wrapped, orderBy, limit, locking, desiredTypes, inScope,
in pkg/sql/opt/optbuilder.(*Builder).buildSelect.func1
inScope.atRoot = false
outScope := buildStmt(inScope)
inScope.atRoot = prevAtRoot
in pkg/sql/opt/optbuilder.(*Builder).processWiths
return b.processWiths(with, inScope, func(inScope *scope) *scope {
return b.buildSelectStmtWithoutParens(
in pkg/sql/opt/optbuilder.(*Builder).buildSelect
case *tree.Select:
return b.buildSelect(stmt, noRowLocking, desiredTypes, inScope)
in pkg/sql/opt/optbuilder.(*Builder).buildStmt
return b.buildStmt(stmt, desiredTypes, inScope)
}
in pkg/sql/opt/optbuilder.(*Builder).buildStmtAtRoot
// and physical properties.
outScope := b.buildStmtAtRoot(b.stmt, nil /* desiredTypes */, b.allocScope())
in pkg/sql/opt/optbuilder.(*Builder).Build
bld.KeepPlaceholders = true
if err := bld.Build(); err != nil {
return nil, err
in pkg/sql.(*optPlanningCtx).buildReusableMemo
memo, err := opc.buildReusableMemo(ctx)
if err != nil {
in pkg/sql.(*planner).prepareUsingOptimizer
// future.
flags, err := p.prepareUsingOptimizer(ctx)
if err != nil {
in pkg/sql.(*connExecutor).populatePrepared
p.semaCtx.Annotations = tree.MakeAnnotations(stmt.NumAnnotations)
flags, err = ex.populatePrepared(ctx, txn, placeholderHints, p)
return err
in pkg/sql.(*connExecutor).prepare.func1

cockroach/pkg/kv/db.go

Lines 710 to 712 in d311992

err := txn.exec(ctx, func(ctx context.Context, txn *Txn) error {
return retryable(ctx, txn)
})
in pkg/kv.(*DB).Txn.func1

cockroach/pkg/kv/txn.go

Lines 802 to 804 in d311992

}
err = fn(ctx, txn)
in pkg/kv.(*Txn).exec

cockroach/pkg/kv/db.go

Lines 709 to 711 in d311992

txn.SetDebugName("unnamed")
err := txn.exec(ctx, func(ctx context.Context, txn *Txn) error {
return retryable(ctx, txn)
in pkg/kv.(*DB).Txn
// than bubbling them up to the connExecutor state machine.
if err := ex.server.cfg.DB.Txn(ctx, prepare); err != nil {
return nil, err
in pkg/sql.(*connExecutor).prepare
// Prepare the query. This completes the typing of placeholders.
prepared, err := ex.prepare(ctx, stmt, placeholderHints, origin)
if err != nil {
in pkg/sql.(*connExecutor).addPreparedStmt
ps, err := ex.addPreparedStmt(
ctx,
in pkg/sql.(*connExecutor).execPrepare
stmtCtx := withStatement(ctx, ex.curStmt)
ev, payload = ex.execPrepare(stmtCtx, tcmd)
case DescribeStmt:
in pkg/sql.(*connExecutor).execCmd
var err error
if err = ex.execCmd(ex.Ctx()); err != nil {
if errors.IsAny(err, io.EOF, errDrainingComplete) {
in pkg/sql.(*connExecutor).run

pkg/sql/sem/tree/datum.go in pkg/sql/sem/tree.makeParseError at line 267
pkg/sql/sem/tree/parse_array.go in pkg/sql/sem/tree.ParseDArrayFromString at line 161
pkg/sql/sem/tree/parse_string.go in pkg/sql/sem/tree.ParseAndRequireString at line 29
pkg/sql/sem/tree/constant.go in pkg/sql/sem/tree.(*StrVal).ResolveAsType at line 571
pkg/sql/sem/tree/constant.go in pkg/sql/sem/tree.typeCheckConstant at line 73
pkg/sql/sem/tree/type_check.go in pkg/sql/sem/tree.(*StrVal).TypeCheck at line 1370
pkg/sql/sem/tree/type_check.go in pkg/sql/sem/tree.(*ParenExpr).TypeCheck at line 1204
pkg/sql/sem/tree/type_check.go in pkg/sql/sem/tree.(*IndirectionExpr).TypeCheck at line 518
pkg/sql/sem/tree/type_check.go in pkg/sql/sem/tree.TypeCheck at line 253
pkg/sql/opt/optbuilder/scope.go in pkg/sql/opt/optbuilder.(*scope).resolveType at line 427
pkg/sql/opt/optbuilder/project.go in pkg/sql/opt/optbuilder.(*Builder).analyzeSelectList at line 150
pkg/sql/opt/optbuilder/project.go in pkg/sql/opt/optbuilder.(*Builder).analyzeProjectionList at line 84
pkg/sql/opt/optbuilder/select.go in pkg/sql/opt/optbuilder.(*Builder).buildSelectClause at line 1045
pkg/sql/opt/optbuilder/select.go in pkg/sql/opt/optbuilder.(*Builder).buildSelectStmtWithoutParens at line 982
pkg/sql/opt/optbuilder/select.go in pkg/sql/opt/optbuilder.(*Builder).buildSelect.func1 at line 955
pkg/sql/opt/optbuilder/with.go in pkg/sql/opt/optbuilder.(*Builder).processWiths at line 29
pkg/sql/opt/optbuilder/select.go in pkg/sql/opt/optbuilder.(*Builder).buildSelect at line 954
pkg/sql/opt/optbuilder/builder.go in pkg/sql/opt/optbuilder.(*Builder).buildStmt at line 248
pkg/sql/opt/optbuilder/builder.go in pkg/sql/opt/optbuilder.(*Builder).buildStmtAtRoot at line 212
pkg/sql/opt/optbuilder/builder.go in pkg/sql/opt/optbuilder.(*Builder).Build at line 183
pkg/sql/plan_opt.go in pkg/sql.(*optPlanningCtx).buildReusableMemo at line 350
pkg/sql/plan_opt.go in pkg/sql.(*planner).prepareUsingOptimizer at line 120
pkg/sql/conn_executor_prepare.go in pkg/sql.(*connExecutor).populatePrepared at line 238
pkg/sql/conn_executor_prepare.go in pkg/sql.(*connExecutor).prepare.func1 at line 180
pkg/kv/db.go in pkg/kv.(*DB).Txn.func1 at line 711
pkg/kv/txn.go in pkg/kv.(*Txn).exec at line 803
pkg/kv/db.go in pkg/kv.(*DB).Txn at line 710
pkg/sql/conn_executor_prepare.go in pkg/sql.(*connExecutor).prepare at line 192
pkg/sql/conn_executor_prepare.go in pkg/sql.(*connExecutor).addPreparedStmt at line 106
pkg/sql/conn_executor_prepare.go in pkg/sql.(*connExecutor).execPrepare at line 52
pkg/sql/conn_executor.go in pkg/sql.(*connExecutor).execCmd at line 1437
pkg/sql/conn_executor.go in pkg/sql.(*connExecutor).run at line 1296
Tag Value
Cockroach Release v20.2.0-alpha.2
Cockroach SHA: d311992
Platform darwin amd64
Distribution CCL
Environment v20.2.0-alpha.2
Command server
Go Version ``
# of CPUs
# of Goroutines
@cockroach-teamcity cockroach-teamcity added C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. O-sentry Originated from an in-the-wild panic report. labels Jul 30, 2020
@yuzefovich yuzefovich changed the title sentry: *errors.errorString *safedetails.withSafeDetails: unknown type %s (%T) (1) parse_string.go:85: *withstack.withStack (top exception) *assert.withAssertionFailure *errutil.withMessage *safedetails.withSafeDetails: could not parse %q as type %s (2) datum.go:267: *withstack.withStack (3) *pgerror.withCandidateCode: 22P02 (4) (check the extra data payloads) sql: v20.2.0-alpha.2: could not parse value as requested type - unknown type Jul 30, 2020
@yuzefovich
Copy link
Member

cc @rohany maybe you would know something

@rohany
Copy link
Contributor

rohany commented Jul 30, 2020

hmm, I'm a bit baffled as to how MakeParseError would panic.

@yuzefovich
Copy link
Member

I don't think it panicked - I think it is an assertion failure that got reported, and the user saw an internal error.

@RaduBerinde RaduBerinde self-assigned this Aug 5, 2020
@RaduBerinde
Copy link
Member

The error is coming from ParseAndRequireString, called under ParseDArrayFromString:

return nil, false, errors.AssertionFailedf("unknown type %s (%T)", t, t)

So we are trying to parse as an array, but we don't support the element type of that array (there are a few families that aren't handled by that function: Unknwon, ColaltedString). But we should only be tolerating the specific array types in StrValAvailAllParsable. I stared at this for a while and finally found one way in which this can happen - if we desire an Array of Any. Then Array of Any is equivalent to (say) StringArray and we would try to parse it using the Any type. And indeed, this is under a IndirectionExpr.TypeCheck call which uses types.MakeArray(desired) (and desired is frequently Any). Here's a repro:

[email protected]:36229/defaultdb> select '{1,2,3}'[0];
ERROR: internal error: could not parse "{1,2,3}" as type anyelement[]: unknown type anyelement (*types.T)

RaduBerinde added a commit to RaduBerinde/cockroach that referenced this issue Aug 5, 2020
The parse-constant-as-type code was allowing a desired type of `Array[Any]`, and
we can't parse elements as `Any`. This resulted in an internal error, rather
than a normal query error.

Fixes cockroachdb#52134.

Release note (bug fix): Fixed an internal error involving string literals used
as arrays.
craig bot pushed a commit that referenced this issue Aug 10, 2020
52416: sql: fix internal error when trying to parse strings as arrays r=RaduBerinde a=RaduBerinde

The parse-constant-as-type code was allowing a desired type of `Array[Any]`, and
we can't parse elements as `Any`. This resulted in an internal error, rather
than a normal query error.

Fixes #52134.

Release note (bug fix): Fixed an internal error involving string literals used
as arrays.

Co-authored-by: Radu Berinde <[email protected]>
@craig craig bot closed this as completed in 32522ea Aug 10, 2020
vxio pushed a commit to vxio/cockroach that referenced this issue Aug 11, 2020
The parse-constant-as-type code was allowing a desired type of `Array[Any]`, and
we can't parse elements as `Any`. This resulted in an internal error, rather
than a normal query error.

Fixes cockroachdb#52134.

Release note (bug fix): Fixed an internal error involving string literals used
as arrays.
RichardJCai pushed a commit to RichardJCai/cockroach that referenced this issue Aug 11, 2020
The parse-constant-as-type code was allowing a desired type of `Array[Any]`, and
we can't parse elements as `Any`. This resulted in an internal error, rather
than a normal query error.

Fixes cockroachdb#52134.

Release note (bug fix): Fixed an internal error involving string literals used
as arrays.
RaduBerinde added a commit to RaduBerinde/cockroach that referenced this issue Jan 15, 2021
The parse-constant-as-type code was allowing a desired type of `Array[Any]`, and
we can't parse elements as `Any`. This resulted in an internal error, rather
than a normal query error.

Fixes cockroachdb#52134.

Release note (bug fix): Fixed an internal error involving string literals used
as arrays.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. O-sentry Originated from an in-the-wild panic report.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants