为什么我在 运行 查询时会收到此错误?

Why am I getting this error when I run the query?

尝试执行此查询时:

select race_name from sport_app.month_category_runner where race_type = 'URBAN RACE 10K' and club = 'CORNELLA ATLETIC';

我收到以下错误:

Cannot execute this query as it might involve data filtering and thus may have unpredictable performance. If you want to execute this query despite the performance unpredictability, use ALLOW FILTERING

这是一个练习,所以我不允许使用 ALLOW FILTERING。

所以我这样创建了两个索引:

create index raceTypeIndex ON sport_app.month_category_runner(race_type);
create index clubIndex ON sport_app.month_category_runner(club);

但我一直收到同样的错误,我是不是遗漏了什么,还是有其他选择?

Table结构:

CREATE TABLE month_category_runner (month text,

                            category text,

                            runner_id text,

                            club text,

                            race_name text,

                            race_type text,

                            race_date timestamp,

                            total_runners int,

                            net_time time,

                            PRIMARY KEY (month, category, runner_id, race_name, net_time));

请注意,如果您添加“ALLOW FILTERING”,查询将 运行 在 Cassandra 集群的所有节点上,并且会对所有节点产生很大影响。

建议将分区添加为查询的条件,以允许仅在需要的节点上执行查询。

示例:

select race_name 来自 month_category_runner 其中月份 = 'may' 和俱乐部 = 'CORNELLA ATLETIC';

select race_name 来自 month_category_runner 其中月份 = 'may' 和 race_type = 'URBAN RACE 10K';

select race_name from month_category_runner where month = 'may' and race_type = 'URBAN RACE 10K' and club = 'CORNELLA ATLETIC' ALLOW过滤;

您的主键由 (month, category, runner_id, race_name, net_time) 组成,列 month 是分区,所以该列必须在您的查询中如我在示例中所示进行过滤。

尽管存在索引列,但您想使用不在主键中的两个列进行查询,您需要使用会对性能产生影响的 ALLOW FILTERING;

另一个选项是创建一个新的 table,其中主键包含这些列。