MyCATApache/Mycat-Server · error · ConfigException

table duplicated!

Error message

table ${tableName} duplicated!

What it means

Thrown by XMLSchemaLoader.loadTable when two tables resolve to the same logical name in the same schema. The tables map is keyed by table name; inserting a duplicate would silently overwrite config, so Mycat rejects the schema at load time.

Solutions

  1. Rename one of the duplicate tables in schema.xml
  2. Remove the redundant <table> declaration
  3. Check comma-separated name lists for names already defined elsewhere in the schema

Example fix

// before (schema.xml)
<table name="t1,t2" dataNode="dn1" />
<table name="t2" dataNode="dn2" />
// after
<table name="t1" dataNode="dn1" />
<table name="t2" dataNode="dn2" />
Defensive patterns

Strategy: validation

Validate before calling

// detect duplicate table names (including comma-expanded lists) before load
Set<String> seen = new HashSet<>();
for (Element t : schemaTables("schema.xml")) {
    for (String n : t.getAttribute("name").split(",")) {
        if (!seen.add(n.trim()))
            throw new IllegalStateException("Duplicate table: " + n);
    }
}

Try / catch

try {
    configLoader.load();
} catch (ConfigException e) {
    if (e.getMessage().contains("duplicated!")) {
        String name = e.getMessage().replace("table ", "").replace(" duplicated!", "");
        log.error("Table declared more than once in schema.xml: " + name, e);
    }
    throw e;
}

Prevention

When it happens

Trigger: A <table name="a,b"> with comma-separated names where one name is also declared by another <table> element; or the same table name declared twice within one <schema>.

Common situations: Comma-expanded table names colliding with an existing explicit <table> entry; merging schema.xml fragments that both define the same table; copy-paste duplication.

Understand the failure class

Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.

Related errors


AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11). Data as JSON: /api/errors/7951aaf2983ace42. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/io/mycat/config/loader/xml/XMLSchemaLoader.java:430

                        ruleRequired, null, false, null, null, subTables, fetchStoreNodeByJdbc);
                //因为需要等待TableConfig构造完毕才可以拿到dataNode节点数量,所以Rule构造延后到此处 @cjw
                if ((tableRuleConfig != null) && (tableRuleConfig.getRule().getRuleAlgorithm() instanceof TableRuleAware)) {
                    AbstractPartitionAlgorithm newRuleAlgorithm = tableRuleConfig.getRule().getRuleAlgorithm();
                    ((TableRuleAware)newRuleAlgorithm).setTableConfig(table);
                    newRuleAlgorithm.init();
                }
                checkDataNodeExists(table.getDataNodes());
                // 检查分片表分片规则配置是否合法
                if (table.getRule() != null) {
                    checkRuleSuitTable(table);
                }

                if (distTableDns) {
                    distributeDataNodes(table.getDataNodes());
                }
                //检查去重
                if (tables.containsKey(table.getName())) {
                    throw new ConfigException("table " + tableName + " duplicated!");
                }
                //放入map
                tables.put(table.getName(), table);
            }
            //只有tableName配置的是单个表(没有逗号)的时候才能有子表
            if (tableNames.length == 1) {
                TableConfig table = tables.get(tableNames[0]);
                // process child tables
                processChildTables(tables, table, dataNode, tableElement);
            }
        }
    }

    private String getNewRuleName(String schemaName, String tableName, String name) {
        return name + "_" + schemaName + "_" + tableName;
    }

    /**

View on GitHub (pinned to 65f8d8beb7)