From c92dc07979605df01356bee66c2a80f8931ee0be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=B6=A6=E6=B3=BD?= <17367971251@163.com> Date: Sun, 24 Nov 2024 09:15:40 +0000 Subject: [PATCH] =?UTF-8?q?update=20Oracle/or=5Fquery=5Ftable=5Fdate.go.?= =?UTF-8?q?=20=EF=BC=88cherry=20picked=20commit=20from=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Oracle/or_query_table_date.go | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/Oracle/or_query_table_date.go b/Oracle/or_query_table_date.go index af79b93..fbf5f7c 100644 --- a/Oracle/or_query_table_date.go +++ b/Oracle/or_query_table_date.go @@ -186,25 +186,28 @@ func (or *QueryTable) TmpTableColumnGroupDataDispos(db *sql.DB, where string, co */ func (or *QueryTable) TableRows(db *sql.DB, logThreadSeq int64) (uint64, error) { var ( - Event = "Q_I_S_tableRows" + tmpTableCount uint64 + Event = "Q_Index_Table_Count" ) - dispos := dataDispos.DBdataDispos{DBType: DBType, LogThreadSeq: logThreadSeq, Event: Event, DB: db} - vlog = fmt.Sprintf("(%d) [%s] Start querying the statistical information of table %s.%s in the %s database and get the number of rows in the table", logThreadSeq, Event, or.Schema, or.Table, DBType) + vlog = fmt.Sprintf("(%d) [%s] Start to query the total number of rows in the following table %s.%s of the %s database.", logThreadSeq, Event, or.Schema, or.Table, DBType) global.Wlog.Debug(vlog) - strsql = fmt.Sprintf("exec dbms_stats.gather_table_stats('%s','%s');", or.Schema, or.Table) - dispos.DBSQLforExec(strsql) - strsql = fmt.Sprintf("select num_rows as \"tableRows\" from dba_tables where owner='%s' and table_name='%s'", or.Schema, or.Table) + strsql = fmt.Sprintf("select count(1) as \"sum\" from \"%s\".\"%s\"", or.Schema, or.Table) + dispos := dataDispos.DBdataDispos{DBType: DBType, LogThreadSeq: logThreadSeq, Event: Event, DB: db} if dispos.SqlRows, err = dispos.DBSQLforExec(strsql); err != nil { return 0, err } - tableData, err := dispos.DataRowsAndColumnSliceDispos([]map[string]interface{}{}) - if err != nil { + if tableData, err := dispos.DataRowsAndColumnSliceDispos([]map[string]interface{}{}); err != nil { return 0, err + } else { + for _, i := range tableData { + d, _ := strconv.ParseUint(fmt.Sprintf("%s", i["sum"]), 10, 64) + tmpTableCount += d + } } - defer dispos.SqlRows.Close() - vlog = fmt.Sprintf("(%d) [%s] The number of rows in table %s.%s in the %s database has been obtained.", logThreadSeq, Event, or.Schema, or.Table, DBType) + vlog = fmt.Sprintf("(%d) [%s] The query of the total number of rows in the following table %s.%s of the %s database is completed.", logThreadSeq, Event, or.Schema, or.Table, DBType) global.Wlog.Debug(vlog) - return strconv.ParseUint(fmt.Sprintf("%s", tableData[0]["tableRows"]), 10, 64) + defer dispos.SqlRows.Close() + return tmpTableCount, nil } //处理无索引表查询select的order by列,防止原目标端查询的段不一致情况 -- Gitee