scql icon indicating copy to clipboard operation
scql copied to clipboard

合并/移除多余的 RunSQL 语句

Open Candicepan opened this issue 9 months ago • 0 comments

此 ISSUE 为 隐语开源共建计划(SecretFlow Open Source Contribution Plan,简称 SF OSCP)Phase 5 任务 ISSUE,欢迎社区开发者参与共建~

This ISSUE is one of the tasks of the SecretFlow Open Source Contribution Plan (referred to as SF OSCP) Phase 5. Welcome to join us in building it together!

任务介绍

  • 任务名称:合并/移除多余的 RunSQL 语句
  • 技术方向:SCQL
  • 任务难度:挑战🌟🌟🌟
  • 任务预估完成时间:7周
  • 任务 Reviewer:@FollyCoolly

详细要求

SCQL 中,为了将原始 SQL 语句转化成 SCQL engine 的执行图,大致有以下步骤

  • 将 SQL 转化为 LogicalPlan,并进行相关逻辑优化
  • 将 LogicalPlan 加上 CCL 等属性,得到 LogicalNode
  • 将 LogicalNode 翻译成 engine 的 operators。

其中第三步由 Translator(见translator.go) 完成。Translator 在翻译的过程中,如果发现当前 LogicalNode(以及其子节点) 对应的执行图只包含单个参与方的数据,那么会将当前 LogicalNode 及其子节点翻译成一个 RunSQL operator。

func (t *translator) translateInternal(ln logicalNode) error {
	if dataSourceParties := ln.DataSourceParty(); len(dataSourceParties) == 1 {
		return t.buildRunSQL(ln, dataSourceParties[0])
	}
	for _, node := range ln.Children() {
		if err := t.translateInternal(node); err != nil {
			return err
		}
	}
	switch x := ln.(type) {
	case *ProjectionNode:
		return t.buildProjection(x)
	case *SelectionNode:
		// 以下省略各种 Node 对应的 buildXXX
	}
}

注意到,某个 RunSQL operator 的 SQL 可能对应一个 DataSourceNode(没有子节点),也可能对应其他种类的 LogicalNode(有子节点)。

有的时候,会出现单个参与方的 engine 执行图中包含多个 RunSQL operator,并且其中某个 RunSQL operator 的 result tensors 是另一个 RunSQL operator 的 result tensors 的子集的情况。此时可以合并这些 RunSQL operators,避免不必要的性能损耗。

例如,对于query“select ta.plain_int_0 from alice_tbl_0 as ta where ta.plain_int_0 开发完成后,关联该 ISSUE 并提交PR至 https://github.com/secretflow/scql

能力要求

  • 了解基本 git 操作,熟练使用 Go 语言
  • 熟悉 SCQL 的基本工作流程和代码结构
  • 熟悉 SCQL 的 Translator 和 GraphBuilder
  • 熟悉 sql 语句和 LogicalPlan 之间的转换

操作说明

Candicepan avatar Feb 28 '25 08:02 Candicepan