Skip to content

Commit

Permalink
Change output type of 'SHOW time_quantiles' to float8 (#770)
Browse files Browse the repository at this point in the history
* Change output type of 'SHOW time_quantiles' to float8

* Remove debug output
  • Loading branch information
EinKrebs authored Sep 16, 2024
1 parent 62c9895 commit 97ce149
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
26 changes: 22 additions & 4 deletions pkg/clientinteractor/interactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ func (pi *PSQLInteractor) CompleteMsg(rowCnt int) error {
// TEXTOID https://github.com/postgres/postgres/blob/master/src/include/catalog/pg_type.dat#L81
const TEXTOID = 25

// DOUBLEOID https://github.com/postgres/postgres/blob/master/src/include/catalog/pg_type.dat#L223
const DOUBLEOID = 701

// TODO : unit tests

// TextOidFD generates a pgproto3.FieldDescription object with the provided statement text.
Expand All @@ -103,6 +106,18 @@ func TextOidFD(stmt string) pgproto3.FieldDescription {
}
}

func FloatOidFD(stmt string) pgproto3.FieldDescription {
return pgproto3.FieldDescription{
Name: []byte(stmt),
TableOID: 0,
TableAttributeNumber: 0,
DataTypeOID: DOUBLEOID,
DataTypeSize: 8,
TypeModifier: -1,
Format: 0,
}
}

// TODO : unit tests

// WriteHeader sends the row description message with the specified field descriptions.
Expand Down Expand Up @@ -251,17 +266,20 @@ func (pi *PSQLInteractor) Version(_ context.Context) error {
//
// TODO: unit tests
func (pi *PSQLInteractor) Quantiles(_ context.Context) error {
if err := pi.WriteHeader("quantile_type", "value"); err != nil {
spqrlog.Zero.Error().Err(err).Msg("")
if err := pi.cl.Send(&pgproto3.RowDescription{
Fields: []pgproto3.FieldDescription{TextOidFD("quantile_type"), FloatOidFD("time, ms")},
}); err != nil {
spqrlog.Zero.Error().Err(err).Msg("Could not write header for time quantiles")
return err
}

quantiles := statistics.GetQuantiles()
spqrlog.Zero.Debug().Str("quantiles", fmt.Sprintf("%#v", quantiles)).Msg("Got quantiles")
for _, q := range *quantiles {
if err := pi.WriteDataRow(fmt.Sprintf("router_time_%.2f", q), fmt.Sprintf("%.2fms", statistics.GetTotalTimeQuantile(statistics.Router, q))); err != nil {
if err := pi.WriteDataRow(fmt.Sprintf("router_time_%.2f", q), fmt.Sprintf("%.2f", statistics.GetTotalTimeQuantile(statistics.Router, q))); err != nil {
return err
}
if err := pi.WriteDataRow(fmt.Sprintf("shard_time_%.2f", q), fmt.Sprintf("%.2fms", statistics.GetTotalTimeQuantile(statistics.Shard, q))); err != nil {
if err := pi.WriteDataRow(fmt.Sprintf("shard_time_%.2f", q), fmt.Sprintf("%.2f", statistics.GetTotalTimeQuantile(statistics.Shard, q))); err != nil {
return err
}
}
Expand Down
8 changes: 4 additions & 4 deletions test/regress/tests/console/expected/show_time_quantiles.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
https://github.com/pg-sharding/spqr/tree/master/docs

SHOW time_quantiles
quantile_type | value
------------------+--------
router_time_0.75 | 0.00ms
shard_time_0.75 | 0.00ms
quantile_type | time, ms
------------------+----------
router_time_0.75 | 0.00
shard_time_0.75 | 0.00
(2 rows)

0 comments on commit 97ce149

Please sign in to comment.