MCPcopy Create free account
hub / github.com/Shopify/ghostferry / FingerprintQuery

Method FingerprintQuery

table_schema_cache.go:60–84  ·  view source on GitHub ↗

This query returns the MD5 hash for a row on this table. This query is valid for both the source and the target shard. Any compressed columns specified via CompressedColumnsForVerification are excluded in this checksum and the raw data is returned directly. Any columns specified in IgnoredColumnsF

(schemaName, tableName string, numRows int)

Source from the content-addressed store, hash-verified

58// This is to say that there should never be a case where the MD5 hash is
59// derived from an empty string.
60func (t *TableSchema) FingerprintQuery(schemaName, tableName string, numRows int) string {
61 var forceIndex string
62
63 columnsToSelect := make([]string, 2+len(t.CompressedColumnsForVerification))
64 columnsToSelect[0] = QuoteField(t.GetPaginationColumn().Name)
65 columnsToSelect[1] = t.RowMd5Query()
66 i := 2
67 for columnName, _ := range t.CompressedColumnsForVerification {
68 columnsToSelect[i] = QuoteField(columnName)
69 i += 1
70 }
71
72 if t.ForcedIndexForVerification != "" {
73 forceIndex = fmt.Sprintf(" FORCE INDEX (%s)", t.ForcedIndexForVerification)
74 }
75
76 return fmt.Sprintf(
77 "SELECT %s FROM %s%s WHERE %s IN (%s)",
78 strings.Join(columnsToSelect, ","),
79 QuotedTableNameFromString(schemaName, tableName),
80 forceIndex,
81 columnsToSelect[0],
82 strings.Repeat("?,", numRows-1)+"?",
83 )
84}
85
86func (t *TableSchema) RowMd5Query() string {
87 if t.rowMd5Query != "" {

Calls 4

GetPaginationColumnMethod · 0.95
RowMd5QueryMethod · 0.95
QuoteFieldFunction · 0.85