From 84510c45902242d3cdb2d12cb7d50150a7bca675 Mon Sep 17 00:00:00 2001 From: zikaeroh <48577114+zikaeroh@users.noreply.github.com> Date: Sun, 28 Jun 2020 16:18:13 -0700 Subject: [PATCH] Cache column names in stdlib Rows --- stdlib/sql.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/stdlib/sql.go b/stdlib/sql.go index 5e8a2ca4..a45750ac 100644 --- a/stdlib/sql.go +++ b/stdlib/sql.go @@ -412,15 +412,20 @@ type Rows struct { valueFuncs []rowValueFunc skipNext bool skipNextMore bool + + columnNames []string } func (r *Rows) Columns() []string { - fieldDescriptions := r.rows.FieldDescriptions() - names := make([]string, 0, len(fieldDescriptions)) - for _, fd := range fieldDescriptions { - names = append(names, string(fd.Name)) + if r.columnNames == nil { + fields := r.rows.FieldDescriptions() + r.columnNames = make([]string, len(fields)) + for i, fd := range fields { + r.columnNames[i] = string(fd.Name) + } } - return names + + return r.columnNames } // ColumnTypeDatabaseTypeName returns the database system type name. If the name is unknown the OID is returned.