Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 31 additions & 23 deletions enginetest/queries/query_plans.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions enginetest/server_engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,51 @@ func TestServerPreparedStatements(t *testing.T) {
},
},
},
{
name: "regression test for incorrectly setting QFlagMax1Row flag",
setup: []string{
"create table test(c0 int not null, c1 int not null, pk int primary key, key (c0, c1));",
"insert into test values (2, 3, 1), (5, 6, 4), (2, 3, 7);",
},
assertions: []serverScriptTestAssertion{
{
query: "select * from test where c0 = 2 and c1 = 3;",
expectedRows: []any{
[]uint64{uint64(2), uint64(3), uint64(1)},
[]uint64{uint64(2), uint64(3), uint64(7)},
},
checkRows: func(rows *gosql.Rows, expectedRows []any) (bool, error) {
var c0, c1, pk uint64
var rowNum int
for rows.Next() {
err := rows.Scan(&c0, &c1, &pk)
require.NoError(t, err)
if err != nil {
return false, err
}
require.Less(t, rowNum, len(expectedRows))
if rowNum >= len(expectedRows) {
return false, nil
}
require.Equal(t, c0, expectedRows[rowNum].([]uint64)[0])
if c0 != expectedRows[rowNum].([]uint64)[0] {
return false, nil
}
require.Equal(t, c1, expectedRows[rowNum].([]uint64)[1])
if c1 != expectedRows[rowNum].([]uint64)[1] {
return false, nil
}
require.Equal(t, pk, expectedRows[rowNum].([]uint64)[2])
if pk != expectedRows[rowNum].([]uint64)[2] {
return false, nil
}
rowNum++
}
return true, nil
},
},
},
},
}

port, perr := findEmptyPort()
Expand Down Expand Up @@ -315,6 +360,8 @@ func TestServerPreparedStatements(t *testing.T) {
if assertion.expectErr {
require.Error(t, err)
return
} else {
require.NoError(t, err)
}
ok, err := assertion.checkRows(rows, assertion.expectedRows)
require.NoError(t, err)
Expand Down
9 changes: 7 additions & 2 deletions sql/analyzer/costed_index_scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -1227,12 +1227,17 @@ func (c *indexCoster) costIndexScanAnd(filter *iScanAnd, s sql.Statistic, bucket
}
}

var conjFDs *sql.FuncDepSet
if idx.IsUnique() {
conjFDs = conj.getFds()
}

if exact.Len()+conj.applied.Len() == filter.childCnt() {
// matched all filters
return conj.hist, conj.getFds(), sql.NewFastIntSet(int(filter.id)), conj.missingPrefix, nil
return conj.hist, conjFDs, sql.NewFastIntSet(int(filter.id)), conj.missingPrefix, nil
}

return conj.hist, conj.getFds(), exact.Union(conj.applied), conj.missingPrefix, nil
return conj.hist, conjFDs, exact.Union(conj.applied), conj.missingPrefix, nil
}

func (c *indexCoster) costIndexScanOr(filter *iScanOr, s sql.Statistic, buckets []sql.HistogramBucket, ordinals map[string]int, idx sql.Index) ([]sql.HistogramBucket, *sql.FuncDepSet, bool, error) {
Expand Down
Loading