2016-09-05 25 views
0

Iは4列のCassandraのテーブルはFooを持っては、分割キーはfoo_idあり、ここでBIGINT、日付日時、ref_id BIGINT、int型クエリ(クラスタリング・キー)

をfoo_id。クラスタリング・キーは、私は、次のCSQL

select foo_id from foo where 
foo_id IN (-9223372036854775808, 9223372036854775807) 
and date >= '2016-04-01 00:00:00+0000'; 

私が書いた

select min(foo_id) from foo where date >= '2016-04-01 00:00:00+0000' 

以下のSQLと等価であるCSQLクエリを作成したい日付DESC、ref_idとタイプ

ですが、この空の結果を返します。

は、その後、私は

select foo_id from foo where 
    token(foo_id) > -9223372036854775808 
    and token(foo_id) < 9223372036854775807 
    and date >= '2016-04-01 00:00:00+0000'; 

を試みたが、これは私がフィルタリングを認めて使用したくないエラー

Unable to execute CSQL Script on 'Cassandra'. Cannot execute this query 
as it might involve data filtering and thus may have unpredictable 
performance. If you want to execute this query despite performance 
unpredictability, use ALLOW FILTERING. 

になります。しかし、指定された日付の始めにfoo_idの最小値が必要です。

答えて

1

おそらくデータを非正規化し、その目的のために新しいテーブルを作成する必要があります。表では、「一日」ベースで照会できるようになる

SELECT * FROM foo_reverse WHERE year = 2016 AND month = 4 AND day = 1 LIMIT 1; 

:あなたのようなもので、そのテーブルを照会しますfoo_id最小を取得するには

CREATE TABLE foo_reverse (
    year int, 
    month int, 
    day int, 

    foo_id bigint, 
    date datetime, 
    ref_id bigint, 
    type int, 
    PRIMARY KEY ((year, month, day), foo_id) 
) 

:私のようなものを提案します。必要に応じてパーティションキーを変更することができます。適切な時間範囲を選択することによって、あなた(そして私)が作り出す潜在的なホットスポットに注意してください。

関連する問題