From 636479aa9b00193cbc26688da000698a14178974 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=E5=BB=BA=E8=AE=AE=20oracle=20=E8=BF=98=E6=98=AFselect=20cou?= =?UTF-8?q?nt=20=E6=9F=A5=E7=9C=8B=E8=A1=8C=E6=95=B0=EF=BC=8C=E7=94=9F?= =?UTF-8?q?=E4=BA=A7=E7=B3=BB=E7=BB=9F=E4=BD=BF=E7=94=A8=E6=94=B6=E9=9B=86?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E4=BF=A1=E6=81=AF=E6=96=B9=E5=BC=8F=E8=BF=98?= =?UTF-8?q?=E6=98=AF=E6=9C=89=E4=B8=80=E5=AE=9A=E8=B5=84=E6=BA=90=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E9=A3=8E=E9=99=A9=EF=BC=8C=E5=A6=82=E6=9E=9C=E4=B8=8D?= =?UTF-8?q?=E5=8A=A0=E5=B9=B6=E8=A1=8C=E6=97=B6=E9=97=B4=E4=BC=9A=E7=89=B9?= =?UTF-8?q?=E5=88=AB=E9=95=BF=E5=BD=B1=E5=93=8D=E5=AF=B9=E6=AF=94=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡润泽 <17367971251@163.com> --- 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