-
-
Notifications
You must be signed in to change notification settings - Fork 209
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
Unbound variables in subqueries #383
Comments
Can you provide a short program that reproduces this problem? We have end-to-end tests of bind variables, but it seems like we are missing something. Thanks! Zach |
@zachmu no problem, will try to split things up and get a reproduce |
@zachmu I still don't have a reproduce but this commit fixes it 100%: aperturerobotics@2fe0a75 |
Running into this as well, but only in my storage method that performs a subquery. The query:
The error:
I can 't say for certain that the subquery is responsible, will try to investigate in the next 24h. |
subquery with bindvar has same error db, err := sql.Open("mysql", "root@tcp(localhost:3306)/mydb")
if err != nil {
panic(err)
}
var name string
err = db.QueryRow("select exists(select name from mytable where name=?)", "John Doe").Scan(&name)
if err != nil {
panic(err)
}
fmt.Println(name)
|
Seems likely that bindvars are not propagating to subqueries. @max-hoffman, please investigate as part of your work on prepared query optimization |
Met the same error. |
@max-hoffman Have you made any progress here? Seems like a real popular bug :-) |
This PR #795 implements prepared statements and doubles our testing coverage for |
@max-hoffman Thanks again for all your work on this. |
Max, let's address this bug separately from the above PR. Bindvars not propagating to subqueries is a very specific issue that has nothing to do with saving the query plan for efficiency between executions. |
cherry picked subquery specific fixes in this PR: #871 |
@max-hoffman I still have the issue on "main":
The issue is resolved if I apply this patch:
|
@paralin Can you share more info for how to reproduce the error? This seems like it deserves a new issue. Do you |
... and in cases where I'm passing binding values (I guess the case that fails that we're talking about here) DriverProvider uses sql.NewDatabaseProvider to build the provider, then return it to gdriver.Provider. Am using the full database/sql stack: import (
"context"
"database/sql"
gdriver "github.com/dolthub/go-mysql-server/driver"
)
// NewSqlDriver constructs a sql driver from a transaction.
func NewSqlDriver(tx *Tx, driverOpts *gdriver.Options) *gdriver.Driver {
provider := NewDriverProvider(tx)
return gdriver.New(provider, driverOpts)
}
// NewSqlDb opens the sql database driver.
func NewSqlDb(tx *Tx) (*sql.DB, error) {
driver := NewSqlDriver(tx, &gdriver.Options{})
// as of writing this: the dsn parsing only allows for overriding jsonAs
var dsn string
conn, err := driver.OpenConnector(dsn)
if err != nil {
return nil, err
}
return sql.OpenDB(conn), nil
} ... I'll try to make a reproduce repo here soon, sorry for the random code snippets. |
I think we have pretty good confidence that bindvars are being correctly propagated everywhere we know of now. If you find specific cases where this isn't true, please open another issue. |
@zachmu Thanks! |
When using the "driver" package, I kept running into the following errors:
The fix appears to be changing
driver/value.go
to add a "v" prefix to ordinal placeholder values:... because the SQL plan code appears to expect "v1" "v2" and so on.
The text was updated successfully, but these errors were encountered: