{"record":{"id":"ebc41231ba288a1b","repo":"prestodb/presto","slug":"already-exists-ebc412","errorCode":"ALREADY_EXISTS","errorMessage":"Type %s already exists","messagePattern":"Type (.+?) already exists","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-function-namespace-managers/src/main/java/com/facebook/presto/functionNamespace/mysql/MySqlFunctionNamespaceManager.java","lineNumber":110,"sourceCode":"        functionNamespaceDao.createFunctionNamespacesTableIfNotExists();\n        functionNamespaceDao.createSqlFunctionsTableIfNotExists();\n        functionNamespaceDao.createUserDefinedTypesTableIfNotExists();\n    }\n\n    @Override\n    public Collection<SqlInvokedFunction> listFunctions(Optional<String> likePattern, Optional<String> escape)\n    {\n        return likePattern.map(pattern -> functionNamespaceDao.listFunctions(getCatalogName(), pattern, escape.orElse(\"\\\\\"))).orElse(functionNamespaceDao.listFunctions(getCatalogName()));\n    }\n\n    @Override\n    public void addUserDefinedType(UserDefinedType type)\n    {\n        jdbi.useTransaction(handle -> {\n            FunctionNamespaceDao transactionDao = handle.attach(functionNamespaceDaoClass);\n            QualifiedObjectName typeName = type.getUserDefinedTypeName();\n            if (functionNamespaceDao.typeExists(typeName.getCatalogName(), typeName.getSchemaName(), typeName.getObjectName())) {\n                throw new PrestoException(ALREADY_EXISTS, format(\"Type %s already exists\", typeName));\n            }\n            transactionDao.insertUserDefinedType(typeName.getCatalogName(), typeName.getSchemaName(), typeName.getObjectName(), type.getPhysicalTypeSignature().toString());\n        });\n    }\n\n    @Override\n    public UserDefinedType fetchUserDefinedTypeDirect(QualifiedObjectName typeName)\n    {\n        Optional<UserDefinedType> type = functionNamespaceDao.getUserDefinedType(typeName.getCatalogName(), typeName.getSchemaName(), typeName.getObjectName());\n        return type.orElseThrow(() -> new PrestoException(NOT_FOUND, format(\"Type %s not found\", typeName)));\n    }\n\n    @Override\n    protected Collection<SqlInvokedFunction> fetchFunctionsDirect(QualifiedObjectName functionName)\n    {\n        checkCatalog(functionName);\n        return functionNamespaceDao.getFunctions(\n                functionName.getCatalogName(),","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-function-namespace-managers/src/main/java/com/facebook/presto/functionNamespace/mysql/MySqlFunctionNamespaceManager.java#L92-L128","documentation":"MySqlFunctionNamespaceManager.addUserDefinedType inserts a UDT row into the MySQL-backed namespace. Within the insert transaction it first checks typeExists; if a row for the same catalog/schema/object name is present, it throws ALREADY_EXISTS to enforce unique type names.","triggerScenarios":"Calling addUserDefinedType(type) when functionNamespaceDao.typeExists already returns true for the type's qualified name (catalog, schema, object).","commonSituations":"Replaying UDT registration scripts; two workers racing to register the same type; re-registering types after a partial failed deployment left rows behind.","solutions":["Check existence before insert (or catch PrestoException ALREADY_EXISTS and treat as no-op).","Delete/rename the existing type row if the new definition should replace it.","Add idempotency to deployment scripts so duplicate registrations are skipped.","Serialize UDT registration across workers (lock or leader election) to avoid races."],"exampleFix":"// before\ndao.insertUserDefinedType(catalog, schema, object, signature);\n// after\nif (!dao.typeExists(catalog, schema, object)) {\n    dao.insertUserDefinedType(catalog, schema, object, signature);\n}","handlingStrategy":"try-catch","validationCode":"if (functionNamespaceDao.typeExists(typeName.getCatalogName(), typeName.getSchemaName(), typeName.getObjectName())) {\n    return; // already registered, skip\n}","typeGuard":null,"tryCatchPattern":"try {\n    manager.addUserDefinedType(type);\n} catch (PrestoException e) {\n    if (!isAlreadyExists(e)) { throw e; } // treat duplicate as success\n}","preventionTips":["Make UDT registration idempotent","Serialize registration across workers","Verify existing types before insert"],"tags":["udt","mysql","duplicate"],"backgroundTag":"already-exists-conflict","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}