From 4944142ed2ea18c0bdf9be9721c94f74eed1e538 Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Mon, 20 May 2024 12:49:39 +0500 Subject: [PATCH] Revert "rewrite" This reverts commit 557c13ed380fea930e238084ebf86f9c3fa9444c. --- backup/queries_statistics.go | 31 ++++++++----------------------- backup/wrappers.go | 32 ++++++++++---------------------- 2 files changed, 18 insertions(+), 45 deletions(-) diff --git a/backup/queries_statistics.go b/backup/queries_statistics.go index 5ebe8c3d2..4f9a4eac7 100644 --- a/backup/queries_statistics.go +++ b/backup/queries_statistics.go @@ -11,7 +11,6 @@ import ( "github.com/greenplum-db/gp-common-go-libs/dbconn" "github.com/greenplum-db/gp-common-go-libs/gplog" "github.com/greenplum-db/gpbackup/utils" - "github.com/jmoiron/sqlx" "github.com/lib/pq" ) @@ -54,7 +53,7 @@ type AttributeStatistic struct { Values5 pq.StringArray `db:"stavalues5"` } -func GetAttributeStatisticsRows(connectionPool *dbconn.DBConn, tables []Table) (*sqlx.Rows, error) { +func GetAttributeStatistics(connectionPool *dbconn.DBConn, tables []Table) map[uint32][]AttributeStatistic { inheritClause := "" statSlotClause := "" if connectionPool.Version.AtLeast("6") { @@ -120,20 +119,13 @@ func GetAttributeStatisticsRows(connectionPool *dbconn.DBConn, tables []Table) ( inheritClause, statSlotClause, statCollationClause, SchemaFilterClause("n"), utils.SliceToQuotedString(tablenames)) - return connectionPool.Query(query) -} - -func GetAttributeStatistics(connectionPool *dbconn.DBConn, tables []Table) map[uint32][]AttributeStatistic { - results, err := GetAttributeStatisticsRows(connectionPool, tables) + results := make([]AttributeStatistic, 0) + err := connectionPool.Select(&results, query) gplog.FatalOnError(err) stats := make(map[uint32][]AttributeStatistic) - for results.Next() { - var stat AttributeStatistic - err = results.StructScan(&stat) - gplog.FatalOnError(err) + for _, stat := range results { stats[stat.Oid] = append(stats[stat.Oid], stat) } - gplog.FatalOnError(results.Err()) return stats } @@ -145,7 +137,7 @@ type TupleStatistic struct { RelTuples float64 } -func GetTupleStatisticsRows(connectionPool *dbconn.DBConn, tables []Table) (*sqlx.Rows, error) { +func GetTupleStatistics(connectionPool *dbconn.DBConn, tables []Table) map[uint32]TupleStatistic { tablenames := make([]string, 0) for _, table := range tables { tablenames = append(tablenames, table.FQN()) @@ -163,19 +155,12 @@ func GetTupleStatisticsRows(connectionPool *dbconn.DBConn, tables []Table) (*sql ORDER BY n.nspname, c.relname`, SchemaFilterClause("n"), utils.SliceToQuotedString(tablenames)) - return connectionPool.Query(query) -} - -func GetTupleStatistics(connectionPool *dbconn.DBConn, tables []Table) map[uint32]TupleStatistic { - results, err := GetTupleStatisticsRows(connectionPool, tables) + results := make([]TupleStatistic, 0) + err := connectionPool.Select(&results, query) gplog.FatalOnError(err) stats := make(map[uint32]TupleStatistic) - for results.Next() { - var stat TupleStatistic - err = results.StructScan(&stat) - gplog.FatalOnError(err) + for _, stat := range results { stats[stat.Oid] = stat } - gplog.FatalOnError(results.Err()) return stats } diff --git a/backup/wrappers.go b/backup/wrappers.go index a3cead4c5..9cd0376ba 100644 --- a/backup/wrappers.go +++ b/backup/wrappers.go @@ -773,30 +773,18 @@ func backupExtendedStatistic(metadataFile *utils.FileWithByteCount) { func backupTableStatistics(statisticsFile *utils.FileWithByteCount, tables []Table) { backupSessionGUC(statisticsFile) - tupleStats, err := GetTupleStatisticsRows(connectionPool, tables) - gplog.FatalOnError(err) - for tupleStats.Next() { - var stat TupleStatistic - err = tupleStats.StructScan(&stat) - gplog.FatalOnError(err) - table := Table{Relation: Relation{Schema: stat.Schema, Name: stat.Table}} - tupleQuery := GenerateTupleStatisticsQuery(table, stat) - printStatisticsStatementForTable(statisticsFile, globalTOC, table, tupleQuery) - } - gplog.FatalOnError(tupleStats.Err()) - attStats, err := GetAttributeStatisticsRows(connectionPool, tables) - gplog.FatalOnError(err) - for attStats.Next() { - var stat AttributeStatistic - err = attStats.StructScan(&stat) - gplog.FatalOnError(err) - table := Table{Relation: Relation{Schema: stat.Schema, Name: stat.Table}} - attributeQueries := GenerateAttributeStatisticsQueries(table, stat) - for _, attrQuery := range attributeQueries { - printStatisticsStatementForTable(statisticsFile, globalTOC, table, attrQuery) + + length := len(tables) + slice := 10000 + for start := 0; start < length; start += slice { + end := start + slice + if end > length { + end = length } + attStats := GetAttributeStatistics(connectionPool, tables[start:end]) + tupleStats := GetTupleStatistics(connectionPool, tables[start:end]) + PrintStatisticsStatements(statisticsFile, globalTOC, tables[start:end], attStats, tupleStats) } - gplog.FatalOnError(attStats.Err()) } func backupIncrementalMetadata() {