{"record":{"id":"903fa16022c06201","repo":"vitessio/vitess","slug":"unsupported-distinct-clause","errorCode":null,"errorMessage":"unsupported distinct clause","messagePattern":"unsupported distinct clause","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vttablet/tabletmanager/vreplication/table_plan_builder.go","lineNumber":399,"sourceCode":"\t\tTablePlanBuilder:        tpb,\n\t\tPartialInserts:          make(map[string]*sqlparser.ParsedQuery, 0),\n\t\tPartialUpdates:          make(map[string]*sqlparser.ParsedQuery, 0),\n\t\tCollationEnv:            tpb.collationEnv,\n\t\tWorkflowConfig:          tpb.workflowConfig,\n\t}\n}\n\nfunc analyzeSelectFrom(query string, parser *sqlparser.Parser) (sel *sqlparser.Select, from string, err error) {\n\tstatement, err := parser.Parse(query)\n\tif err != nil {\n\t\treturn nil, \"\", err\n\t}\n\tsel, ok := statement.(*sqlparser.Select)\n\tif !ok {\n\t\treturn nil, \"\", errors.New(\"unsupported non-select statement\")\n\t}\n\tif sel.Distinct {\n\t\treturn nil, \"\", errors.New(\"unsupported distinct clause\")\n\t}\n\tif len(sel.From) == 0 {\n\t\treturn nil, \"\", errors.New(\"unsupported select from dual\")\n\t}\n\tif len(sel.From) > 1 {\n\t\treturn nil, \"\", errors.New(\"unsupported multi-table usage\")\n\t}\n\tnode, ok := sel.From[0].(*sqlparser.AliasedTableExpr)\n\tif !ok {\n\t\treturn nil, \"\", fmt.Errorf(\"unsupported from expression (%T)\", sel.From[0])\n\t}\n\tfromTable := sqlparser.GetTableName(node.Expr)\n\tif fromTable.IsEmpty() {\n\t\treturn nil, \"\", fmt.Errorf(\"unsupported from source (%T)\", node.Expr)\n\t}\n\treturn sel, fromTable.String(), nil\n}\n","sourceCodeStart":381,"sourceCodeEnd":417,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vttablet/tabletmanager/vreplication/table_plan_builder.go#L381-L417","documentation":"Filter rules for vreplication must be plain selects without a DISTINCT clause; distinct semantics cannot be preserved in a row-streaming replication plan, so buildTablePlan (via analyzeSelectFrom) rejects sel.Distinct.","triggerScenarios":"A filter rule like 'select distinct col from t' or 'select distinct * from t' used in MoveTables/Reshard/filter configuration.","commonSituations":"Users trying to deduplicate rows via the filter rule; SQL copied from reporting queries used as a vreplication filter.","solutions":["Remove the DISTINCT keyword from the filter rule select","If deduplication matters, handle it on the target/query side, not in the replication filter","Use 'select * from t where ...' for row filtering instead"],"exampleFix":"// before\n\"filter\": \"select distinct sku from t\"\n// after\n\"filter\": \"select * from t\"","handlingStrategy":"validation","validationCode":"sel := stmt.(*sqlparser.Select)\nif sel.Distinct {\n    return errors.New(\"DISTINCT not allowed in vreplication filter rules\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Strip DISTINCT from filter-rule templates","Move deduplication logic to query/application side","Add filter-rule SQL checks to CI"],"tags":["vreplication","filter","sql-parsing"],"backgroundTag":"invalid-filter-rule","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}