MCPcopy Create free account
hub / github.com/bytebase/bytebase / getMaterializedViewNames

Function getMaterializedViewNames

backend/plugin/db/starrocks/dump.go:357–398  ·  view source on GitHub ↗

getMaterializedViewNames returns the set of materialized-view names in the database. Doris and StarRocks expose them through different catalogs; the query is best-effort (an unsupported engine/version logs and yields an empty set). StarRocks sync rollups (REFRESH_TYPE='ROLLUP') are excluded — they a

(db *sql.DB, dbName string, dbType storepb.Engine)

Source from the content-addressed store, hash-verified

355// (REFRESH_TYPE='ROLLUP') are excluded — they are rollup indexes on the base table, not
356// standalone views.
357func getMaterializedViewNames(db *sql.DB, dbName string, dbType storepb.Engine) (map[string]bool, error) {
358 names := make(map[string]bool)
359
360 var query string
361 switch dbType {
362 case storepb.Engine_DORIS:
363 query = fmt.Sprintf(`SELECT Name FROM mv_infos("database"="%s")`, dbName)
364 case storepb.Engine_STARROCKS:
365 // IFNULL guards the bare-string scan below: database/sql errors on a NULL->string scan.
366 query = fmt.Sprintf(`SELECT TABLE_NAME, IFNULL(REFRESH_TYPE, '') FROM information_schema.materialized_views WHERE TABLE_SCHEMA = '%s'`, dbName)
367 default:
368 return names, nil
369 }
370
371 rows, err := db.Query(query)
372 if err != nil {
373 // The catalog may be unavailable on older engine versions; log and continue.
374 slog.Debug("failed to query materialized views, might not be supported", slog.String("error", err.Error()))
375 return names, nil
376 }
377 defer rows.Close()
378
379 for rows.Next() {
380 var name string
381 if dbType == storepb.Engine_STARROCKS {
382 var refreshType string
383 if err := rows.Scan(&name, &refreshType); err != nil {
384 return nil, err
385 }
386 if isSyncRollup(refreshType) {
387 continue
388 }
389 } else if err := rows.Scan(&name); err != nil {
390 return nil, err
391 }
392 names[name] = true
393 }
394 if err := rows.Err(); err != nil {
395 return nil, err
396 }
397 return names, nil
398}
399
400// markMaterializedViews re-tags rows that are actually materialized views so the dump
401// emits SHOW CREATE MATERIALIZED VIEW for them. Doris reports MVs as 'BASE TABLE' and

Callers 1

getTablesFunction · 0.85

Calls 8

isSyncRollupFunction · 0.85
DebugMethod · 0.80
ScanMethod · 0.80
QueryMethod · 0.65
StringMethod · 0.65
CloseMethod · 0.65
ErrorMethod · 0.45
NextMethod · 0.45

Tested by

no test coverage detected