From 2176f75eb6a32c81244ac06df23d7ffa3034e699 Mon Sep 17 00:00:00 2001 From: Ryan-Git Date: Mon, 29 Jun 2020 11:12:50 +0800 Subject: [PATCH] fix TiDB DEFAULT_GENERATED (#290) --- pkg/schema_store/utils.go | 5 ++++- pkg/sql_execution_engine/internal_txn_tagger.go | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/pkg/schema_store/utils.go b/pkg/schema_store/utils.go index a95e0705..8a4f10b0 100644 --- a/pkg/schema_store/utils.go +++ b/pkg/schema_store/utils.go @@ -178,7 +178,10 @@ func GetTableDefFromDB(db *sql.DB, dbName string, tableName string) (*Table, err } else { column.IsPrimaryKey = false } - if extra.Valid && strings.Contains(strings.ToUpper(extra.String), "GENERATED") { + + // TiDB describes certain column as `DEFAULT_GENERATED` + if extra.Valid && (strings.Contains(strings.ToUpper(extra.String), "VIRTUAL GENERATED") || + strings.Contains(strings.ToUpper(extra.String), "STORED GENERATED")) { column.IsGenerated = true } diff --git a/pkg/sql_execution_engine/internal_txn_tagger.go b/pkg/sql_execution_engine/internal_txn_tagger.go index 738ec4e1..589d68ca 100644 --- a/pkg/sql_execution_engine/internal_txn_tagger.go +++ b/pkg/sql_execution_engine/internal_txn_tagger.go @@ -20,6 +20,7 @@ import ( "database/sql" "github.com/juju/errors" + log "github.com/sirupsen/logrus" "github.com/moiot/gravity/pkg/utils" ) @@ -47,6 +48,9 @@ func ExecWithInternalTxnTag( } if !internalTxnTaggerCfg.TagInternalTxn { + if log.IsLevelEnabled(log.DebugLevel) { + log.Debugf("query: %v, args: %v", newQuery, args) + } _, err := db.Exec(newQuery, args...) return errors.Annotatef(err, "query: %v, args: %v", query, args) } @@ -64,6 +68,9 @@ func ExecWithInternalTxnTag( return errors.Trace(err) } + if log.IsLevelEnabled(log.DebugLevel) { + log.Debugf("query: %v, args: %v", newQuery, args) + } _, err = txn.Exec(query, args...) if err != nil { txn.Rollback()