vitessio/vitess · error

cannot compile regexp %v for table: %v

Error message

cannot compile regexp %v for table: %v

What it means

NewTableFilter builds table filters for schema reloads (GetSchema). Entries starting with '/' are treated as regular expressions matched against table names; if one of those regexps fails to compile, NewTableFilter returns this error and the schema request fails.

Source

Thrown at go/vt/mysqlctl/tmutils/schema.go:75

// (tables), no denied tables (excludeTables) and optionally
// views (includeViews).
func NewTableFilter(tables, excludeTables []string, includeViews bool) (*TableFilter, error) {
	f := &TableFilter{
		includeViews: includeViews,
	}

	// Build a list of regexp to match table names against.
	// We only use regexps if the name starts and ends with '/'.
	// Otherwise the entry in the arrays is nil, and we use the original
	// table name.
	if len(tables) > 0 {
		f.filterTables = true
		for _, table := range tables {
			if strings.HasPrefix(table, "/") {
				table = strings.Trim(table, "/")
				re, err := regexp.Compile(table)
				if err != nil {
					return nil, fmt.Errorf("cannot compile regexp %v for table: %v", table, err)
				}

				f.tableREs = append(f.tableREs, re)
			} else {
				f.tableNames = append(f.tableNames, table)
			}
		}
	}

	if len(excludeTables) > 0 {
		f.filterExcludeTables = true
		for _, table := range excludeTables {
			if strings.HasPrefix(table, "/") {
				table = strings.Trim(table, "/")
				re, err := regexp.Compile(table)
				if err != nil {
					return nil, fmt.Errorf("cannot compile regexp %v for excludeTable: %v", table, err)
				}

View on GitHub (pinned to 01a25a7d17)

Solutions

  1. Fix the regexp syntax in the tables argument (validate it with regexp.MustCompile in a scratch test or a Go playground)
  2. Escape special regex characters in table names that contain ., (, ), [, etc.
  3. If the entry is meant to be a literal name, remove the leading '/' so it is treated as an exact table name

Example fix

// before
f, err := tmutils.NewTableFilter([]string{"/user[/"}, nil, false)
// after
f, err := tmutils.NewTableFilter([]string{"/^user_/"}, nil, false)
Defensive patterns

Strategy: validation

Validate before calling

func validateTableFilters(tables []string) error {
    for _, t := range tables {
        if strings.HasPrefix(t, "/") {
            if _, err := regexp.Compile(strings.Trim(t, "/")); err != nil {
                return fmt.Errorf("invalid table regexp %q: %v", t, err)
            }
        }
    }
    return nil
}

Type guard

func isRegexTableFilter(entry string) bool {
    return strings.HasPrefix(entry, "/")
}

Try / catch

f, err := tmutils.NewTableFilter(tables, excludeTables, includeViews)
if err != nil {
    return vterrors.Wrapf(err, "invalid table filter configuration")
}

Prevention

When it happens

Trigger: Passing a malformed regex in the tables list, e.g. tmutils.NewTableFilter([]string{"/user[/"}, ...) or any vtctldclient/vttablet GetSchema call with an invalid /regex/ table filter.

Common situations: Typo in a regex table filter (unbalanced brackets, dangling quantifier like 'orders+' miswritten as 'orders+['); shell escaping stripped or altered characters in the pattern; copying a glob pattern (e.g. 'tmp_*') into a regex position incorrectly.

Related errors


AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01). Data as JSON: /api/errors/c8e2645b7c8de003. Report an issue: GitHub.