增加在SQL审核阶段自动识别并合并相同表的alter table语句的功能 #669
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
新增 check-merge参数,设置其为1后开启自动合并alter table语句功能(现在仅有命令行参数,后续将添加配置文件参数并将参数名修改为 alter-auto-merge)。在添加了check-merge参数后,goInc会检查用户提交的SQL,并将其中涉及相同表的alter table,create index,drop index语句统一合并为 alter table语句,然后返回SQL检查结果以及合并后新生成的SQL。
goInc校验的返回值增加了一个字段,显示对应的SQL是否为 (alter table|create index|drop index), 如果是的话,就会显示'alterTable'字样。对于合并后新生成的SQL,ErrorMessage字段显示"Merged"。以上两个字段可用于区分是原有SQL还是合并后的SQL
新增alterTableInfo结构体,记录每一个表被修改的信息,包括表名,所有alter语句的语法树,以及合并后的新SQL
在checkAlterTable方法中写入alterTableInfo,在提交阶段进行SQL的合并工作,通过合并语法树然后生成新的SQL
对于create index和drop index语句,使用convertCreateIndexToAddConstrain和convertDropIndexToDropIndex方法(已修改成convertCreateIndexToAlterTable和convertDropIndexToAlerTable)将其转换为alter table语句,然后进行合并。