Skip to content

Commit 02dbcd3

Browse files
committed
Merge remote-tracking branch 'origin/main' into nicktobey/vector2
2 parents b3ba4c7 + 2269c83 commit 02dbcd3

File tree

277 files changed

+3312
-3967
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

277 files changed

+3312
-3967
lines changed

_example/main_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"database/sql"
1919
"fmt"
2020
"testing"
21+
"time"
2122

2223
_ "github.com/go-sql-driver/mysql"
2324
"github.com/gocraft/dbr/v2"
@@ -42,6 +43,8 @@ func TestExampleUsersDisabled(t *testing.T) {
4243
main()
4344
}()
4445

46+
// Wait for the database to start
47+
time.Sleep(1 * time.Second)
4548
conn, err := dbr.Open("mysql", fmt.Sprintf("no_user:@tcp(%s:%d)/%s", address, port, dbName), nil)
4649
require.NoError(t, err)
4750
require.NoError(t, conn.Ping())
@@ -60,7 +63,6 @@ func TestExampleRootUserEnabled(t *testing.T) {
6063
go func() {
6164
main()
6265
}()
63-
6466
conn, err := dbr.Open("mysql", fmt.Sprintf("no_user:@tcp(%s:%d)/%s", address, port, dbName), nil)
6567
require.NoError(t, err)
6668
require.ErrorContains(t, conn.Ping(), "User not found")
@@ -82,7 +84,6 @@ func TestExampleLoadedUser(t *testing.T) {
8284
go func() {
8385
main()
8486
}()
85-
8687
conn, err := dbr.Open("mysql", fmt.Sprintf("no_user:@tcp(%s:%d)/%s", address, port, dbName), nil)
8788
require.NoError(t, err)
8889
require.ErrorContains(t, conn.Ping(), "User not found")
@@ -108,7 +109,6 @@ func TestIssue1621(t *testing.T) {
108109
go func() {
109110
main()
110111
}()
111-
112112
conn, err := dbr.Open("mysql",
113113
fmt.Sprintf("root:@tcp(localhost:%d)/mydb", port), nil)
114114
require.NoError(t, err)

driver/conn.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ import (
2323

2424
// Conn is a connection to a database.
2525
type Conn struct {
26-
dsn string
27-
options *Options
28-
dbConn *dbConn
2926
session sql.Session
3027
contexts ContextBuilder
28+
options *Options
29+
dbConn *dbConn
3130
indexes *sql.IndexRegistry
3231
views *sql.ViewRegistry
32+
dsn string
3333
}
3434

3535
// DSN returns the driver connection string.

driver/driver.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,11 @@ type ProviderWithSessionBuilder interface {
8282
// A Driver exposes an engine as a stdlib SQL driver.
8383
type Driver struct {
8484
provider Provider
85-
options *Options
8685
sessions SessionBuilder
8786
contexts ContextBuilder
88-
89-
mu sync.Mutex
90-
dbs map[string]*dbConn
87+
options *Options
88+
dbs map[string]*dbConn
89+
mu sync.Mutex
9190
}
9291

9392
// New returns a driver using the specified provider.
@@ -223,9 +222,9 @@ func (c *dbConn) close() error {
223222
type Connector struct {
224223
driver *Driver
225224
options *Options
225+
dbConn *dbConn
226226
serverName string
227227
dsn string
228-
dbConn *dbConn
229228
}
230229

231230
// Driver returns the driver.

driver/rows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ import (
2626

2727
// Rows is an iterator over an executed query's results.
2828
type Rows struct {
29+
rows sql.RowIter
2930
options *Options
3031
ctx *sql.Context
3132
cols sql.Schema
32-
rows sql.RowIter
3333
}
3434

3535
// Columns returns the names of the columns. The number of

driver/stmt.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,10 @@ func (s *Stmt) query(ctx context.Context, bindings map[string]sqlparser.Expr) (d
117117
return nil, err
118118
}
119119

120-
return &Rows{s.conn.options, qctx, cols, rows}, nil
120+
return &Rows{
121+
options: s.conn.options,
122+
ctx: qctx,
123+
cols: cols,
124+
rows: rows,
125+
}, nil
121126
}

engine.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,16 @@ func init() {
5353
type Config struct {
5454
// VersionPostfix to display with the `VERSION()` UDF.
5555
VersionPostfix string
56+
// TemporaryUsers adds any users that should be included when the engine is created. By default, authentication is
57+
// disabled, and including any users here will enable authentication. All users in this list will have full access.
58+
// This field is only temporary, and will be removed as development on users and authentication continues.
59+
TemporaryUsers []TemporaryUser
5660
// IsReadOnly sets the engine to disallow modification queries.
5761
IsReadOnly bool
5862
IsServerLocked bool
5963
// IncludeRootAccount adds the root account (with no password) to the list of accounts, and also enables
6064
// authentication.
6165
IncludeRootAccount bool
62-
// TemporaryUsers adds any users that should be included when the engine is created. By default, authentication is
63-
// disabled, and including any users here will enable authentication. All users in this list will have full access.
64-
// This field is only temporary, and will be removed as development on users and authentication continues.
65-
TemporaryUsers []TemporaryUser
6666
}
6767

6868
// TemporaryUser is a user that will be added to the engine. This is for temporary use while the remaining features
@@ -136,18 +136,18 @@ func (p *PreparedDataCache) UncacheStmt(sessId uint32, query string) {
136136

137137
// Engine is a SQL engine.
138138
type Engine struct {
139+
Parser sql.Parser
140+
ProcessList sql.ProcessList
139141
Analyzer *analyzer.Analyzer
140142
LS *sql.LockSubsystem
141-
ProcessList sql.ProcessList
142143
MemoryManager *sql.MemoryManager
143144
BackgroundThreads *sql.BackgroundThreads
144-
ReadOnly atomic.Bool
145-
IsServerLocked bool
146145
PreparedDataCache *PreparedDataCache
147146
mu *sync.Mutex
148-
Version sql.AnalyzerVersion
149147
EventScheduler *eventscheduler.EventScheduler
150-
Parser sql.Parser
148+
ReadOnly atomic.Bool
149+
IsServerLocked bool
150+
Version sql.AnalyzerVersion
151151
}
152152

153153
var _ sql.StatementRunner = (*Engine)(nil)

enginetest/enginetests.go

Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -866,43 +866,7 @@ func TestOrderByGroupBy(t *testing.T, harness Harness) {
866866
}
867867
require.Equal(t, rowCount, 3)
868868

869-
// TODO: this should error; the order by doesn't count towards ONLY_FULL_GROUP_BY
870-
_, rowIter, _, err = e.Query(ctx, "select id, team from members group by team order by id")
871-
require.NoError(t, err)
872-
rowCount = 0
873-
for {
874-
row, err = rowIter.Next(ctx)
875-
if err == io.EOF {
876-
break
877-
}
878-
rowCount++
879-
require.NoError(t, err)
880-
881-
var val int64
882-
switch v := row[0].(type) {
883-
case int64:
884-
val = v
885-
case int32:
886-
val = int64(v)
887-
default:
888-
panic(fmt.Sprintf("unexpected type %T", v))
889-
}
890-
891-
team, ok, err := sql.Unwrap[string](ctx, row[1])
892-
require.True(t, ok)
893-
require.NoError(t, err)
894-
switch team {
895-
case "red":
896-
require.True(t, val == 3 || val == 4)
897-
case "orange":
898-
require.True(t, val == 5 || val == 6 || val == 7)
899-
case "purple":
900-
require.True(t, val == 8)
901-
default:
902-
panic("received non-existent team")
903-
}
904-
}
905-
require.Equal(t, rowCount, 3)
869+
AssertErr(t, e, harness, "select id, team from members group by team order by id", nil, analyzererrors.ErrValidationGroupBy)
906870
})
907871
}
908872

@@ -4586,8 +4550,8 @@ func TestPreparedStatements(t *testing.T, harness Harness) {
45864550
e := mustNewEngine(t, harness)
45874551
defer e.Close()
45884552

4589-
for _, query := range queries.PreparedScriptTests {
4590-
TestScript(t, harness, query)
4553+
for _, script := range queries.PreparedScriptTests {
4554+
TestScript(t, harness, script)
45914555
}
45924556
}
45934557

@@ -4597,6 +4561,9 @@ func TestShowTableStatus(t *testing.T, harness Harness) {
45974561
for _, tt := range queries.ShowTableStatusQueries {
45984562
TestQuery(t, harness, tt.Query, tt.Expected, nil, nil)
45994563
}
4564+
for _, script := range queries.ShowTableStatusScripts {
4565+
TestScript(t, harness, script)
4566+
}
46004567
}
46014568

46024569
func TestDateParse(t *testing.T, harness Harness) {

enginetest/join_planning_tests.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ order by 1;`,
512512
},
513513
{
514514
// group by doesn't transform
515-
q: "select * from xy where y-1 in (select u from uv group by v having v = 2 order by 1) order by 1;",
515+
q: "select * from xy where y-1 in (select u from uv group by u having u = 2 order by 1) order by 1;",
516516
types: []plan.JoinType{plan.JoinTypeSemi},
517517
exp: []sql.Row{{3, 3}},
518518
},

enginetest/queries/check_scripts.go

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -540,16 +540,36 @@ var ChecksOnUpdateScriptTests = []ScriptTest{
540540
},
541541
Assertions: []ScriptTestAssertion{
542542
{
543-
Query: "UPDATE sales JOIN (SELECT year_built FROM sales) AS t ON sales.year_built = t.year_built SET sales.year_built = 1901;",
544-
Expected: []sql.Row{{types.OkResult{1, 0, plan.UpdateInfo{1, 1, 0}}}},
543+
Query: "UPDATE sales JOIN (SELECT year_built FROM sales) AS t ON sales.year_built = t.year_built SET sales.year_built = 1901;",
544+
Expected: []sql.Row{
545+
{
546+
types.OkResult{
547+
RowsAffected: 1,
548+
Info: plan.UpdateInfo{
549+
Matched: 1,
550+
Updated: 1,
551+
},
552+
},
553+
},
554+
},
545555
},
546556
{
547557
Query: "select * from sales;",
548558
Expected: []sql.Row{{1901}},
549559
},
550560
{
551-
Query: "UPDATE sales as s1 JOIN (SELECT year_built FROM sales) AS t SET S1.year_built = 1902;",
552-
Expected: []sql.Row{{types.OkResult{1, 0, plan.UpdateInfo{1, 1, 0}}}},
561+
Query: "UPDATE sales as s1 JOIN (SELECT year_built FROM sales) AS t SET S1.year_built = 1902;",
562+
Expected: []sql.Row{
563+
{
564+
types.OkResult{
565+
RowsAffected: 1,
566+
Info: plan.UpdateInfo{
567+
Matched: 1,
568+
Updated: 1,
569+
},
570+
},
571+
},
572+
},
553573
},
554574
{
555575
Query: "select * from sales;",
@@ -599,8 +619,18 @@ var ChecksOnUpdateScriptTests = []ScriptTest{
599619
Expected: []sql.Row{{"WA"}},
600620
},
601621
{
602-
Query: "UPDATE sales JOIN locations SET sales.year_built = 2000, locations.state = 'CA';",
603-
Expected: []sql.Row{{types.OkResult{2, 0, plan.UpdateInfo{2, 2, 0}}}},
622+
Query: "UPDATE sales JOIN locations SET sales.year_built = 2000, locations.state = 'CA';",
623+
Expected: []sql.Row{
624+
{
625+
types.OkResult{
626+
RowsAffected: 2,
627+
Info: plan.UpdateInfo{
628+
Matched: 2,
629+
Updated: 2,
630+
},
631+
},
632+
},
633+
},
604634
},
605635
{
606636
Query: "select * from sales;",

enginetest/queries/column_alias_queries.go

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,10 @@ var ColumnAliasQueries = []ScriptTest{
210210
Query: "SELECT 1 as a, (select a) as b;",
211211
Expected: []sql.Row{{1, 1}},
212212
},
213+
{
214+
Query: `SELECT 1 as a, (select a union select a) as b;`,
215+
Expected: []sql.Row{{1, 1}},
216+
},
213217
{
214218
Query: "SELECT 1 as a, (select a) as b from dual;",
215219
Expected: []sql.Row{{1, 1}},
@@ -226,6 +230,22 @@ var ColumnAliasQueries = []ScriptTest{
226230
Query: "SELECT 1 as a, (select a) from xy;",
227231
Expected: []sql.Row{{1, 1}, {1, 1}, {1, 1}, {1, 1}},
228232
},
233+
{
234+
// https://github.com/dolthub/dolt/issues/4256
235+
Query: `SELECT *, (select i union select i) as a from mytable;`,
236+
Expected: []sql.Row{
237+
{1, "first row", 1},
238+
{2, "second row", 2},
239+
{3, "third row", 3}},
240+
},
241+
{
242+
Query: "select 1 as b, (select b group by b order by b) order by 1;",
243+
Expected: []sql.Row{{1, 1}},
244+
},
245+
{
246+
Query: `select 1 as a, (select b), 0 as b;`,
247+
ExpectedErr: sql.ErrColumnNotFound,
248+
},
229249
},
230250
},
231251
{
@@ -245,39 +265,15 @@ var ColumnAliasQueries = []ScriptTest{
245265
},
246266
{
247267
Name: "various broken alias queries",
268+
Skip: true,
248269
Assertions: []ScriptTestAssertion{
249-
{
250-
// The second query in the union subquery returns "x" instead of mytable.i
251-
// https://github.com/dolthub/dolt/issues/4256
252-
Query: `SELECT *, (select i union select i) as a from mytable;`,
253-
Expected: []sql.Row{
254-
{1, "first row", 1},
255-
{2, "second row", 2},
256-
{3, "third row", 3}},
257-
},
258-
{
259-
Query: `SELECT 1 as a, (select a union select a) as b;`,
260-
Expected: []sql.Row{{1, 1}},
261-
},
262-
{
263-
// GMS executes this query, but it is not valid because of the forward ref of alias b.
264-
// GMS should return an error about an invalid forward-ref.
265-
Skip: true,
266-
Query: `select 1 as a, (select b), 0 as b;`,
267-
ExpectedErr: sql.ErrColumnNotFound,
268-
},
269270
{
270271
// GMS returns "expression 'dt.two' doesn't appear in the group by expressions", but MySQL will execute
271272
// this query.
272273
Query: "select 1 as a, one + 1 as mod1, dt.* from mytable as t1, (select 1, 2 from mytable) as dt (one, two) where dt.one > 0 group by one;",
273274
// column names: a, mod1, one, two
274275
Expected: []sql.Row{{1, 2, 1, 2}},
275276
},
276-
{
277-
// GMS returns `ambiguous column or alias name "b"` on both cases of `group by b` and `group by 1` inside subquery, but MySQL executes.
278-
Query: "select 1 as b, (select b group by b order by b) order by 1;",
279-
Expected: []sql.Row{{1, 1}},
280-
},
281277
},
282278
},
283279
}

0 commit comments

Comments
 (0)