{"record":{"id":"779ece07255e1364","repo":"bytebase/bytebase","slug":"cannot-access-user-and-system-tables-at-the-same-t","errorCode":null,"errorMessage":"cannot access user and system tables at the same time","messagePattern":"cannot access user and system tables at the same time","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"backend/plugin/parser/base/span.go","lineNumber":34,"sourceCode":"type QueryType int\n\nconst (\n\t// Type can not be recognized for now.\n\tQueryTypeUnknown QueryType = iota\n\t// The read-only select query.\n\tSelect\n\t// The explain query.\n\tExplain\n\t// The read-only select query for reading information schema and system objects.\n\tSelectInfoSchema\n\t// The DDL query that changes schema.\n\tDDL\n\t// The DML query that changes table data.\n\tDML\n)\n\nvar (\n\tMixUserSystemTablesError = errors.Errorf(\"cannot access user and system tables at the same time\")\n)\n\ntype SourceColumnSet map[ColumnResource]bool\n\n// MergeSourceColumnSet merges two source column maps, returns true if there is difference.\nfunc MergeSourceColumnSet(m, n SourceColumnSet) (SourceColumnSet, bool) {\n\tr := make(SourceColumnSet)\n\tfor k := range m {\n\t\tr[k] = true\n\t}\n\tfor k := range n {\n\t\tif _, ok := r[k]; !ok {\n\t\t\tr[k] = true\n\t\t}\n\t}\n\n\treturn r, len(r) != len(m)\n}","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/bytebase/bytebase/blob/1870550677fe08f0d2a78c07acd27541464eb945/backend/plugin/parser/base/span.go#L16-L52","documentation":"MixUserSystemTablesError is a sentinel error declared in base/span.go: a query span analysis found a statement that mixes references to user tables and system tables (e.g. joining a business table with information_schema or pg_catalog views). Query span extractors refuse to classify such mixed-access queries because lineage/source-column attribution across user and system catalogs is not meaningful.","triggerScenarios":"getQuerySpan/GetQuerySpan/getOmniQuerySpan (e.g. Doris and GoogleSQL extractors) run isMixedQuery/classifyAccess over the statement's accessed tables and detect both system and user tables in one query; the sentinel is returned as the query span error. Triggering SQL example: SELECT * FROM my_table, information_schema.tables WHERE ...","commonSituations":"Ad-hoc queries in the SQL editor joining catalog/metadata views with application tables; data-export statements mixing pg_catalog or information_schema with user tables; queries written against administrative dashboards.","solutions":["Split the query: run the user-table part and the system-catalog part as separate statements.","Remove or replace system-table references (e.g. hardcode metadata or fetch it via a separate query) so the statement touches only user tables.","Catch this sentinel (errors.Is(err, base.MixUserSystemTablesError)) and skip query-span/lineage features for such statements instead of failing."],"exampleFix":"// before\nrows, err := db.Query(\"SELECT u.name, t.table_name FROM users u JOIN information_schema.tables t ON t.table_schema = u.db\")\n// after\nrows, err := db.Query(\"SELECT u.name FROM users u\") // fetch catalog info in a separate query\nmetaRows, _ := db.Query(\"SELECT table_name FROM information_schema.tables WHERE table_schema = $1\", dbName)","handlingStrategy":"try-catch","validationCode":"// heuristic pre-check: reject queries referencing both user tables and catalog schemas\nif mentionsSystemSchema(sql) && mentionsUserTables(sql) {\n\treturn errors.New(\"query mixes user and system tables; split it\")\n}","typeGuard":"func isMixedTableError(err error) bool {\n\treturn errors.Is(err, base.MixUserSystemTablesError)\n}","tryCatchPattern":"span, err := extractor.GetQuerySpan(ctx, q)\nif errors.Is(err, base.MixUserSystemTablesError) {\n\t// skip lineage for mixed queries; not a hard failure\n\treturn nil, nil\n}","preventionTips":["Avoid joining user tables with information_schema/pg_catalog in lineage-analyzed queries.","Split catalog lookups into separate statements.","Compare against the sentinel with errors.Is rather than string matching."],"tags":["query-span","lineage","sql","system-tables"],"backgroundTag":"unsupported-operation","analyzedSha":"1870550677fe08f0d2a78c07acd27541464eb945","analyzedAt":"2026-09-06T21:16:13.665Z","contentChangedAt":"2026-09-06T21:16:13.665Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}