Skip to content

Commit

Permalink
Add LogStats#IndexesUsed in Executor#logExecutionEnd (#5224)
Browse files Browse the repository at this point in the history
* Add LogStats#IndexesUsed in Executor#logExecutionEnd

Signed-off-by: Rafer Hazen <rafer@ralua.com>

* Test that indexes used, rows read are copied from result to logstats

Signed-off-by: Rafer Hazen <rafer@ralua.com>

* Formatting

Signed-off-by: Rafer Hazen <rafer@ralua.com>

---------

Signed-off-by: Rafer Hazen <rafer@ralua.com>
  • Loading branch information
rafer authored May 22, 2024
1 parent acc69ca commit dcd1a3c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
24 changes: 24 additions & 0 deletions go/vt/vtgate/insights_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
"time"

"vitess.io/vitess/go/sqltypes"
"vitess.io/vitess/go/vt/vtgate/engine"
"vitess.io/vitess/go/vt/vtgate/vindexes"

"vitess.io/vitess/go/vt/vterrors"

Expand Down Expand Up @@ -443,6 +445,28 @@ func TestInsightsStreaminResultReceiver(t *testing.T) {
assert.Equal(t, map[[3]string]bool{{"db", "tbl", "idx1"}: true, {"db", "tbl", "idx2"}: true, {"db", "tbl", "idx3"}: true}, receiver.indexesUsed)
}

func TestInsightsExecutorLogExecutionEnd(t *testing.T) {
result := sqltypes.Result{
IndexesUsed: map[[3]string]bool{{"db", "tbl", "idx1"}: true, {"db", "tbl", "idx2"}: true},
RowsRead: 10,
}
ls := logstats.LogStats{}
executor := Executor{}

plan := engine.Plan{
Instructions: &engine.Route{
RoutingParameters: &engine.RoutingParameters{
Opcode: engine.Unsharded,
Keyspace: &vindexes.Keyspace{},
},
},
}

executor.logExecutionEnd(&ls, time.Now(), &plan, nil, &result)
assert.Equal(t, [][3]string{{"db", "tbl", "idx1"}, {"db", "tbl", "idx2"}}, ls.IndexesUsed)
assert.Equal(t, uint64(10), ls.RowsRead)
}

func TestInsightsSchemaChanges(t *testing.T) {
insightsTestHelper(t, true, setupOptions{},
[]insightsQuery{
Expand Down
5 changes: 5 additions & 0 deletions go/vt/vtgate/plan_execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,11 @@ func (e *Executor) logExecutionEnd(logStats *logstats.LogStats, execStart time.T
logStats.RowsAffected = qr.RowsAffected
logStats.RowsReturned = uint64(len(qr.Rows))
logStats.RowsRead = qr.RowsRead

logStats.IndexesUsed = make([][3]string, 0, len(qr.IndexesUsed))
for index := range qr.IndexesUsed {
logStats.IndexesUsed = append(logStats.IndexesUsed, index)
}
}
return errCount
}
Expand Down

0 comments on commit dcd1a3c

Please sign in to comment.