Cassandra 顺序和聚类键
Cassandra order and clustering key
我有这个table:
CREATE TABLE custumer_events_service.events_by_websiteId_time(
"event_id" text,
"currentTime" timestamp,
"websiteId" varchar,
OTHER COLUMNS ...
PRIMARY KEY(event_id, websiteId, currentTime)
)
在这种情况下,当我执行此查询时,我会得到按 currentime
排序的 10000 行吗:
SELECT * FROM events_by_websiteid_time WHERE websiteid='xxxx' LIMIT 10000 ALLOW FILTERING;
还是我必须在最后添加 WITH CLUSTERING ORDER BY (currentTime DESC);
?
Cassandra 只能在分区内执行排序顺序。当您使用 ALLOW FILTERING
以避免必须提供您的分区键 (event_id
) 时,您的结果集将按每个 event_id
的散列标记值排序,然后按 websiteid
和 currentTime
.
要让结果按 currentTime
排序,您需要创建一个新查询 table 或更改现有 table。如果您决定创建一个新查询 table,它必须看起来像这样:
CREATE TABLE custumer_events_service.events_by_websiteId_time_eventid(
event_id text,
currentTime timestamp,
websiteId varchar,
OTHER COLUMNS ...
PRIMARY KEY (websiteid,currentTime,event_id))
WITH CLUSTERING ORDER BY (currentTime DESC, event_id ASC);
这将允许此查询:
SELECT * FROM events_by_websiteid_time_eventid WHERE websiteid='xxxx' LIMIT 10000;
...按您的预期工作。
我有这个table:
CREATE TABLE custumer_events_service.events_by_websiteId_time(
"event_id" text,
"currentTime" timestamp,
"websiteId" varchar,
OTHER COLUMNS ...
PRIMARY KEY(event_id, websiteId, currentTime)
)
在这种情况下,当我执行此查询时,我会得到按 currentime
排序的 10000 行吗:
SELECT * FROM events_by_websiteid_time WHERE websiteid='xxxx' LIMIT 10000 ALLOW FILTERING;
还是我必须在最后添加 WITH CLUSTERING ORDER BY (currentTime DESC);
?
Cassandra 只能在分区内执行排序顺序。当您使用 ALLOW FILTERING
以避免必须提供您的分区键 (event_id
) 时,您的结果集将按每个 event_id
的散列标记值排序,然后按 websiteid
和 currentTime
.
要让结果按 currentTime
排序,您需要创建一个新查询 table 或更改现有 table。如果您决定创建一个新查询 table,它必须看起来像这样:
CREATE TABLE custumer_events_service.events_by_websiteId_time_eventid(
event_id text,
currentTime timestamp,
websiteId varchar,
OTHER COLUMNS ...
PRIMARY KEY (websiteid,currentTime,event_id))
WITH CLUSTERING ORDER BY (currentTime DESC, event_id ASC);
这将允许此查询:
SELECT * FROM events_by_websiteid_time_eventid WHERE websiteid='xxxx' LIMIT 10000;
...按您的预期工作。