{"record":{"id":"3094acf5a7658822","repo":"apache/shardingsphere","slug":"projections-not-in-simple-select-table-subquery","errorCode":null,"errorMessage":"Projections not in simple select, table subquery, join subquery, predicate subquery and insert select subquery are not supported in encrypt feature.","messagePattern":"Projections not in simple select, table subquery, join subquery, predicate subquery and insert select subquery are not supported in encrypt feature\\.","errorType":"exception","errorClass":"UnsupportedSQLOperationException","httpStatus":null,"severity":"error","filePath":"features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/projection/EncryptProjectionTokenGenerator.java","lineNumber":272,"sourceCode":"    }\n    \n    private Collection<Projection> generateProjections(final EncryptColumn encryptColumn, final ColumnProjection columnProjection, final SubqueryType subqueryType) {\n        if (null == subqueryType || SubqueryType.PROJECTION == subqueryType) {\n            return Collections.singleton(generateProjection(encryptColumn, columnProjection));\n        }\n        if (SubqueryType.VIEW_DEFINITION == subqueryType) {\n            return Collections.singleton(generateViewDefinitionProjection(encryptColumn, columnProjection));\n        }\n        if (SubqueryType.TABLE == subqueryType || SubqueryType.JOIN == subqueryType || SubqueryType.WITH == subqueryType) {\n            return generateProjectionsInTableSegmentSubquery(encryptColumn, columnProjection);\n        }\n        if (SubqueryType.PREDICATE == subqueryType) {\n            return Collections.singleton(generateProjectionInPredicateSubquery(encryptColumn, columnProjection));\n        }\n        if (SubqueryType.INSERT_SELECT == subqueryType) {\n            return generateProjectionsInInsertSelectSubquery(encryptColumn, columnProjection);\n        }\n        throw new UnsupportedSQLOperationException(\n                \"Projections not in simple select, table subquery, join subquery, predicate subquery and insert select subquery are not supported in encrypt feature.\");\n    }\n    \n    private ColumnProjection generateProjection(final EncryptColumn encryptColumn, final ColumnProjection columnProjection) {\n        String encryptColumnName = getEncryptColumnName(columnProjection, encryptColumn);\n        QuoteCharacter quoteCharacter = getQuoteCharacter(columnProjection);\n        IdentifierValue cipherColumnName = new IdentifierValue(encryptColumnName, quoteCharacter);\n        IdentifierValue cipherColumnAlias = columnProjection.getAlias().orElse(columnProjection.getName());\n        return new ColumnProjection(columnProjection.getOwner().orElse(null), cipherColumnName, cipherColumnAlias,\n                databaseType, columnProjection.getLeftParentheses().orElse(null), columnProjection.getRightParentheses().orElse(null));\n    }\n    \n    private ColumnProjection generateViewDefinitionProjection(final EncryptColumn encryptColumn, final ColumnProjection columnProjection) {\n        String encryptColumnName = getEncryptColumnName(columnProjection, encryptColumn);\n        QuoteCharacter quoteCharacter = getQuoteCharacter(columnProjection);\n        IdentifierValue cipherColumnName = new IdentifierValue(encryptColumnName, quoteCharacter);\n        return new ColumnProjection(columnProjection.getOwner().orElse(null), cipherColumnName, null,\n                databaseType, columnProjection.getLeftParentheses().orElse(null), columnProjection.getRightParentheses().orElse(null));","sourceCodeStart":254,"sourceCodeEnd":290,"githubUrl":"https://github.com/apache/shardingsphere/blob/e952770a215630a3659c75d64369168cd3e26b82/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/projection/EncryptProjectionTokenGenerator.java#L254-L290","documentation":"EncryptProjectionTokenGenerator routes subquery projection generation by SubqueryType (VIEW_DEFINITION, TABLE, JOIN, WITH, PREDICATE, INSERT_SELECT). A subquery whose type matches none of these falls through to UnsupportedSQLOperationException listing the supported kinds — i.e. the encrypt rewriter encountered a subquery shape it cannot rewrite projections for.","triggerScenarios":"An encrypt-ruled SELECT containing an encrypted column inside a subquery position not covered by the enumerated types — e.g. a scalar subquery in an expression, a subquery in UPDATE/DELETE ... SET, or an EXISTS/CTE shape classified as a different SubqueryType by the current parser version.","commonSituations":"Complex analytical SQL with nested scalar subqueries selecting encrypted columns; new SQL syntax after a parser upgrade that classifies subqueries into types the token generator has not caught up with; migrating dense reporting queries onto encrypted tables.","solutions":["Move the encrypted column out of the unsupported subquery position (hoist the projection into the main query)","Rewrite scalar subqueries as joins or simple projections that the supported types cover","Check release notes / upgrade ShardingSphere — subquery coverage in encrypt rewrite improves over versions","If the column need not be encrypted, exclude it from encrypt rules in this statement's table"],"exampleFix":"-- before\nSELECT name, (SELECT enc_col FROM t2 WHERE ...) FROM t1;\n-- after (hoist to supported simple select / join)\nSELECT t1.name, t2.enc_col FROM t1 JOIN t2 ON ...;","handlingStrategy":"try-catch","validationCode":"if (sqlHasScalarSubquerySelectingEncryptedColumn(sql, encryptRules)) { /* rewrite to join or hoist projection before sending */ }","typeGuard":null,"tryCatchPattern":"catch (UnsupportedSQLOperationException e) { if (e.getMessage().contains(\"Projections not in\")) { /* rewrite subquery shape and retry once */ } }","preventionTips":["Avoid scalar subqueries selecting encrypted columns","Prefer joins over nested subqueries on encrypted tables","Track encrypt subquery coverage in release notes when upgrading"],"tags":["encrypt","projection","subquery","unsupported-sql"],"backgroundTag":null,"analyzedSha":"e952770a215630a3659c75d64369168cd3e26b82","analyzedAt":"2026-08-14T13:54:53.392Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}