StarRocks / starrocks

StarRocks, a Linux Foundation project, is a next-generation sub-second MPP OLAP database for full analytics scenarios, including multi-dimensional analytics, real-time analytics, and ad-hoc queries.
https://starrocks.io
Apache License 2.0
8.29k stars 1.68k forks source link

Missing collection of columns in join condition when enable column level access control #44149

Open gnehc-hc opened 2 months ago

gnehc-hc commented 2 months ago

Steps to reproduce the behavior (Required)

1, Table prepare

create table quickstart.test_table
(id int, name varchar(100), age int, hobby varchar(100))
ENGINE = olap
PROPERTIES(
    "replication_num" = "1"
);

create table quickstart.test_table2
(id int, subject varchar(100), score int)
ENGINE = olap
PROPERTIES(
    "replication_num" = "1"
);

2, Reproduce

select t1.*, t2.subject
from quickstart.test_table t1
join quickstart.test_table2  t2 on t1.id = t2.id
where t2.score = 100
;

Expected behavior (Required)

AnalyzerUtils#collectAllSelectTableColumns()

@Override
public Void visitQueryStatement(QueryStatement statement, ConnectContext context) {
    Map<TableName, Relation> allTablesRelations = AnalyzerUtils.collectAllTableAndViewRelations(statement);
    if (Config.authorization_enable_column_level_privilege) {
        try {
            checkSelectTableAction(context, allTablesRelations);
        } catch (ErrorReportException e) {
            Map<TableName, Set<String>> allTouchedColumns = AnalyzerUtils.collectAllSelectTableColumns(statement);
            checkCanSelectFromColumns(context, allTouchedColumns, allTablesRelations);
        }
    } else {
        checkSelectTableAction(context, allTablesRelations);
    }
    return null;
}

With Map<TableName, Set<String>> allTouchedColumns = AnalyzerUtils.collectAllSelectTableColumns(statement);, all the columns of quickstart.test_table t1 and id, subject, score of quickstart.test_table2 t2 should exist in allTouchedColumns

Real behavior (Required)

But there are only id of quickstart.test_table t1 and id, subject, score of quickstart.test_table2 t2 in allTouchedColumns

StarRocks version (Required)

main

gnehc-hc commented 2 months ago

I will fix this