Phixsura commented on issue #38693:
URL: 
https://github.com/apache/shardingsphere/issues/38693#issuecomment-4474235636

   @daoxincc 
   checked 5.5.3 source. there's no config switch for this, the rewriter just 
doesn't dedup on physical column name.
   
   root cause for the INSERT error is in 
`EncryptInsertDerivedColumnsTokenGenerator.getDerivedColumnNames` 
(`features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/insert/`):
   
   ```java
   encryptColumn.getAssistedQuery().ifPresent(optional -> 
result.add(optional.getName()));
   encryptColumn.getLikeQuery().ifPresent(optional -> 
result.add(optional.getName()));
   ```
   
   two independent `ifPresent` calls, no distinct. when both slots resolve to 
`assisted_val`, both get appended and the rewritten INSERT carries the column 
twice, so mysql trips on "specified twice".
   
   the matching values are appended by 
`EncryptInsertValuesTokenGenerator.encryptToken` with the same shape: two 
independent `if (...isPresent())` blocks that each bump `indexDelta`. so the 
column list and the values list are kept in sync only because both are 
non-deduped. any dedup fix has to touch both at once, otherwise columns and 
values go out of alignment.
   
   UPDATE goes through a different path 
(`EncryptUpdateAssignmentTokenGenerator` delegates to 
`EncryptAssignmentTokenGenerator` in `.../generator/assignment/`), and 
`generateParameterSQLToken` / `addAssistedQueryAssignment` / 
`addLikeAssignment` follow the same pattern. same behavior, different file.
   
   **so concretely:**
   
   * no engine-side workaround in 5.5.3. only schema-side option is giving the 
two slots distinct `name`s.
   * if you want to send a PR, `getDerivedColumnNames` is the smallest entry 
point, but a complete fix needs the values-list dedup in 
`EncryptInsertValuesTokenGenerator` and the assignment-side dedup in 
`EncryptAssignmentTokenGenerator` to match. otherwise UPDATE and 
INSERT-on-duplicate-key paths will still misbehave.
   * reviewers will probably ask for a concrete use case beyond "save a 
column". worth describing your actual scenario in this issue before opening a 
PR, otherwise it'll likely stall on motivation rather than on the patch itself.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to