-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: [lab3] support table alias in join clause #14
Conversation
- Assign each table an alias, either its name or specified in query - Ensure there is no ambiguity in referencing tables via aliases - Simplify some complex logic
- Also add a hint for setting table alias
进一步实现时发现当前代码对于 table alias 的处理会导致 self-join 时出错。在 目前的解决方法是,使用 table alias 而非 table name 作为单个查询中表的唯一标识符(即关系代数中关系的重命名)。例如,在 考虑到之前的 lab 中基本不涉及别名操作(只有单表操作),同时 SQL 分析时已经相对于后续逻辑较为透明地实现了 field 的解析,引入这些修改大概率不会 break 掉前面 lab 中已经实现的部分(实现合理的话)。如果查询中没有重复表,也没有使用 table alias,上述修改对程序行为理论上不会有影响。 为了实现上述修改,我在 cce8920 中修改了 修改之后,实现完本次 lab 可以支持这样的
之前的代码在 在 debug 过程中,还发现代码中一个清理操作错误导致的 segmentation fault,也在 d49b8aa 中修复。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
很优雅的代码!
目前代码不支持
JOIN
子句中使用表别名,涉及多表连接时不方便书写 SQL 语句。考虑扩充 SQL 解析的文法,在join_list
支持形如table_name table_alias
或table_name AS table_alias
的语法,同时重构文法中对表别名的处理方式,提升代码复用性。修改后,连接操作的 SQL 可以使用别名简化,例如
同时也更方便进行 self-join,例如