@@ -22,6 +22,13 @@ type FingerprintOption struct {
22
22
StartTime hlc.Timestamp
23
23
}
24
24
25
+ func (f FingerprintOption ) AOSTCmd () string {
26
+ if f .AOST .IsEmpty () {
27
+ return ""
28
+ }
29
+ return fmt .Sprintf ("AS OF SYSTEM TIME '%s'" , f .AOST .AsOfSystemTime ())
30
+ }
31
+
25
32
func AOST (aost hlc.Timestamp ) func (* FingerprintOption ) {
26
33
return func (opt * FingerprintOption ) {
27
34
opt .AOST = aost
@@ -69,10 +76,7 @@ func FingerprintTable(
69
76
return 0 , err
70
77
}
71
78
72
- aostCmd := ""
73
- if ! opts .AOST .IsEmpty () {
74
- aostCmd = fmt .Sprintf ("AS OF SYSTEM TIME '%s'" , opts .AOST .AsOfSystemTime ())
75
- }
79
+ aostCmd := opts .AOSTCmd ()
76
80
77
81
cmd := fmt .Sprintf (`SELECT * FROM crdb_internal.fingerprint(crdb_internal.table_span(%d),true) %s` , tableID , aostCmd )
78
82
@@ -115,12 +119,18 @@ func FingerprintTables(
115
119
func FingerprintDatabase (
116
120
ctx context.Context , db * gosql.DB , dbName string , optFuncs ... func (* FingerprintOption ),
117
121
) (map [string ]int64 , error ) {
122
+ opts , err := getOpts (optFuncs ... )
123
+ if err != nil {
124
+ return nil , err
125
+ }
126
+ aostCmd := opts .AOSTCmd ()
127
+
118
128
var databaseID int
119
- row := db .QueryRowContext (ctx , `SELECT id FROM system.namespace WHERE name = $1` , dbName )
129
+ row := db .QueryRowContext (ctx , fmt . Sprintf ( `SELECT id FROM system.namespace %s WHERE name = $1` , aostCmd ) , dbName )
120
130
if err := row .Scan (& databaseID ); err != nil {
121
131
return nil , errors .New ("could not get database descriptor id" )
122
132
}
123
- rows , err := db .QueryContext (ctx , `SELECT id, name FROM system.namespace where "parentID" = $1` , databaseID )
133
+ rows , err := db .QueryContext (ctx , fmt . Sprintf ( `SELECT id, name FROM system.namespace %s where "parentID" = $1` , aostCmd ) , databaseID )
124
134
if err != nil {
125
135
return nil , errors .New ("could not get database table name and tableIDs" )
126
136
}
@@ -158,9 +168,12 @@ func FingerprintDatabase(
158
168
func FingerprintAllDatabases (
159
169
ctx context.Context , db * gosql.DB , includeSystemDB bool , optFuncs ... func (* FingerprintOption ),
160
170
) (map [string ]map [string ]int64 , error ) {
161
-
171
+ opts , err := getOpts (optFuncs ... )
172
+ if err != nil {
173
+ return nil , err
174
+ }
162
175
dbNames := make ([]string , 0 )
163
- rows , err := db .QueryContext (ctx , `SELECT database_name FROM [SHOW DATABASES]` )
176
+ rows , err := db .QueryContext (ctx , fmt . Sprintf ( `select name from system.namespace %s where "parentID"=0` , opts . AOSTCmd ()) )
164
177
if err != nil {
165
178
return nil , errors .Wrap (err , "could not get database names" )
166
179
}
0 commit comments