Cassandra querying without full primary keyIndexing - Uniqueidentifier Foreign Key or Intermediary mapping...
Why didn't the 2019 Oscars have a host?
What's this assembly doing?
How do you funnel food off a cutting board?
Subsurf on a crown. How can I smooth some edges and keep others sharp?
What's after EXPSPACE?
How much light is too much?
Single-row INSERT...SELECT much slower than separate SELECT
Why did Luke use his left hand to shoot?
Why does 0.-5 evaluate to -5?
Not a Long-Winded Riddle
A fantasy book with seven white haired women on the cover
Are the positive and negative planes inner or outer planes in the Great Wheel cosmology model?
How do I prevent a homebrew Grappling Hook feature from trivializing Tomb of Annihilation?
Calculate of total length of edges in Voronoi diagram
What makes papers publishable in top-tier journals?
Non-Cancer terminal illness that can affect young (age 10-13) girls?
How to write cases in LaTeX?
How big is a framed opening for a door relative to the finished door opening width?
Concatenating two int[]
Will rerolling initiative each round stop meta-gaming about initiative?
How does Leonard in "Memento" remember reading and writing?
I have trouble understanding this fallacy: "If A, then B. Therefore if not-B, then not-A."
Prevent Nautilus / Nemo from creating .Trash-1000 folder in mounted devices
Is there a way to store 9th-level spells in a Glyph of Warding or similar method?
Cassandra querying without full primary key
Indexing - Uniqueidentifier Foreign Key or Intermediary mapping table?Postgresql table with one integer column, sorted index, with duplicate primary keyMySQL looking up more rows than needed (indexing issue)Performance of primary key IDs with gaps (but in sequential order)Cassandra row ordering best practiceSetup Cassandra DatabaseAdvantages/Disadvantages of using a multicolumn clustering indexQuerying Cassandra without a partition keyWhat is the formal definition of a Primary Index and Primary Key?Primary key and index column for Merge replication- Id vs GUID
As far as I understand there are no secondary indices with multiple columns, only single columns.
So how do I solve the index problem I'm having? This is my table:
CREATE TABLE IF NOT EXISTS logstv.messages (
timestamp timestamp,
channelid bigint,
userid bigint,
message text,
PRIMARY KEY ((channelid, timestamp), userid)
) WITH CLUSTERING ORDER BY (timestamp DESC);
But this is the error currently:
Missing CLUSTERING ORDER for column userid
I want these things:
SELECT WHERE with channelid, userid, timestamp with an order by timestamp and limit
SELECT WHERE with channelid, timestamp with an order by timestamp and limit
Is this possible?
The only option I currently see is setting timestamp
as the primary key and then sorting through the rest in my software, which seems very expensive. Or having 2 tables for my data which i want to very much avoid because the data will grow very fast and get big.
Example queries:
SELECT message, timestamp
FROM logstv.messages
WHERE userid = ?
AND channelid = ?
AND timestamp >= ?
AND timestamp <= ?
ORDER BY timestamp DESC
LIMIT 100;
SELECT message, timestamp
FROM logstv.messages
WHERE channelid = ?
AND timestamp >= ?
AND timestamp <= ?
ORDER BY timestamp DESC
LIMIT 100;
index cassandra
bumped to the homepage by Community♦ 3 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
As far as I understand there are no secondary indices with multiple columns, only single columns.
So how do I solve the index problem I'm having? This is my table:
CREATE TABLE IF NOT EXISTS logstv.messages (
timestamp timestamp,
channelid bigint,
userid bigint,
message text,
PRIMARY KEY ((channelid, timestamp), userid)
) WITH CLUSTERING ORDER BY (timestamp DESC);
But this is the error currently:
Missing CLUSTERING ORDER for column userid
I want these things:
SELECT WHERE with channelid, userid, timestamp with an order by timestamp and limit
SELECT WHERE with channelid, timestamp with an order by timestamp and limit
Is this possible?
The only option I currently see is setting timestamp
as the primary key and then sorting through the rest in my software, which seems very expensive. Or having 2 tables for my data which i want to very much avoid because the data will grow very fast and get big.
Example queries:
SELECT message, timestamp
FROM logstv.messages
WHERE userid = ?
AND channelid = ?
AND timestamp >= ?
AND timestamp <= ?
ORDER BY timestamp DESC
LIMIT 100;
SELECT message, timestamp
FROM logstv.messages
WHERE channelid = ?
AND timestamp >= ?
AND timestamp <= ?
ORDER BY timestamp DESC
LIMIT 100;
index cassandra
bumped to the homepage by Community♦ 3 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
As far as I understand there are no secondary indices with multiple columns, only single columns.
So how do I solve the index problem I'm having? This is my table:
CREATE TABLE IF NOT EXISTS logstv.messages (
timestamp timestamp,
channelid bigint,
userid bigint,
message text,
PRIMARY KEY ((channelid, timestamp), userid)
) WITH CLUSTERING ORDER BY (timestamp DESC);
But this is the error currently:
Missing CLUSTERING ORDER for column userid
I want these things:
SELECT WHERE with channelid, userid, timestamp with an order by timestamp and limit
SELECT WHERE with channelid, timestamp with an order by timestamp and limit
Is this possible?
The only option I currently see is setting timestamp
as the primary key and then sorting through the rest in my software, which seems very expensive. Or having 2 tables for my data which i want to very much avoid because the data will grow very fast and get big.
Example queries:
SELECT message, timestamp
FROM logstv.messages
WHERE userid = ?
AND channelid = ?
AND timestamp >= ?
AND timestamp <= ?
ORDER BY timestamp DESC
LIMIT 100;
SELECT message, timestamp
FROM logstv.messages
WHERE channelid = ?
AND timestamp >= ?
AND timestamp <= ?
ORDER BY timestamp DESC
LIMIT 100;
index cassandra
As far as I understand there are no secondary indices with multiple columns, only single columns.
So how do I solve the index problem I'm having? This is my table:
CREATE TABLE IF NOT EXISTS logstv.messages (
timestamp timestamp,
channelid bigint,
userid bigint,
message text,
PRIMARY KEY ((channelid, timestamp), userid)
) WITH CLUSTERING ORDER BY (timestamp DESC);
But this is the error currently:
Missing CLUSTERING ORDER for column userid
I want these things:
SELECT WHERE with channelid, userid, timestamp with an order by timestamp and limit
SELECT WHERE with channelid, timestamp with an order by timestamp and limit
Is this possible?
The only option I currently see is setting timestamp
as the primary key and then sorting through the rest in my software, which seems very expensive. Or having 2 tables for my data which i want to very much avoid because the data will grow very fast and get big.
Example queries:
SELECT message, timestamp
FROM logstv.messages
WHERE userid = ?
AND channelid = ?
AND timestamp >= ?
AND timestamp <= ?
ORDER BY timestamp DESC
LIMIT 100;
SELECT message, timestamp
FROM logstv.messages
WHERE channelid = ?
AND timestamp >= ?
AND timestamp <= ?
ORDER BY timestamp DESC
LIMIT 100;
index cassandra
index cassandra
edited Sep 24 '18 at 15:59
gempir
asked Sep 23 '18 at 14:40
gempirgempir
1064
1064
bumped to the homepage by Community♦ 3 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 3 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Yeah, It is possible with 'ALLOW FILTERING' option. BUT NOT ADVISABLE (well explained in this link). Schema design in Cassandra is majorly Query Specific (i.e) design your schema so that it is able to answer a query.
If you want to query on different attributes, go for individual schemas for each one.
Is it maybe possible without ALLOW FILTERING; but only supporting WHEREtimestamp + channelid
andtimestamp + userid + channelid
? Leaving out some queries?
– gempir
Sep 24 '18 at 14:19
@gempir as per your model in the question, you can query only based on channel.id + user.id /// or /// channel.id+user.id+timestamp and nothing more than that .
– Dinesh Kumar
Sep 24 '18 at 14:45
The schema is changeable. I just want to avoid storing messages twice in 2 tables
– gempir
Sep 24 '18 at 14:51
What kind of queries do you want to apply on logstv.messages?
– Dinesh Kumar
Sep 24 '18 at 14:58
2 kind something with channelid, timestamp and userid AND a query with just channelid and timestamp
– gempir
Sep 24 '18 at 15:09
|
show 8 more comments
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "182"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f218354%2fcassandra-querying-without-full-primary-key%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Yeah, It is possible with 'ALLOW FILTERING' option. BUT NOT ADVISABLE (well explained in this link). Schema design in Cassandra is majorly Query Specific (i.e) design your schema so that it is able to answer a query.
If you want to query on different attributes, go for individual schemas for each one.
Is it maybe possible without ALLOW FILTERING; but only supporting WHEREtimestamp + channelid
andtimestamp + userid + channelid
? Leaving out some queries?
– gempir
Sep 24 '18 at 14:19
@gempir as per your model in the question, you can query only based on channel.id + user.id /// or /// channel.id+user.id+timestamp and nothing more than that .
– Dinesh Kumar
Sep 24 '18 at 14:45
The schema is changeable. I just want to avoid storing messages twice in 2 tables
– gempir
Sep 24 '18 at 14:51
What kind of queries do you want to apply on logstv.messages?
– Dinesh Kumar
Sep 24 '18 at 14:58
2 kind something with channelid, timestamp and userid AND a query with just channelid and timestamp
– gempir
Sep 24 '18 at 15:09
|
show 8 more comments
Yeah, It is possible with 'ALLOW FILTERING' option. BUT NOT ADVISABLE (well explained in this link). Schema design in Cassandra is majorly Query Specific (i.e) design your schema so that it is able to answer a query.
If you want to query on different attributes, go for individual schemas for each one.
Is it maybe possible without ALLOW FILTERING; but only supporting WHEREtimestamp + channelid
andtimestamp + userid + channelid
? Leaving out some queries?
– gempir
Sep 24 '18 at 14:19
@gempir as per your model in the question, you can query only based on channel.id + user.id /// or /// channel.id+user.id+timestamp and nothing more than that .
– Dinesh Kumar
Sep 24 '18 at 14:45
The schema is changeable. I just want to avoid storing messages twice in 2 tables
– gempir
Sep 24 '18 at 14:51
What kind of queries do you want to apply on logstv.messages?
– Dinesh Kumar
Sep 24 '18 at 14:58
2 kind something with channelid, timestamp and userid AND a query with just channelid and timestamp
– gempir
Sep 24 '18 at 15:09
|
show 8 more comments
Yeah, It is possible with 'ALLOW FILTERING' option. BUT NOT ADVISABLE (well explained in this link). Schema design in Cassandra is majorly Query Specific (i.e) design your schema so that it is able to answer a query.
If you want to query on different attributes, go for individual schemas for each one.
Yeah, It is possible with 'ALLOW FILTERING' option. BUT NOT ADVISABLE (well explained in this link). Schema design in Cassandra is majorly Query Specific (i.e) design your schema so that it is able to answer a query.
If you want to query on different attributes, go for individual schemas for each one.
answered Sep 23 '18 at 19:55
Dinesh KumarDinesh Kumar
153113
153113
Is it maybe possible without ALLOW FILTERING; but only supporting WHEREtimestamp + channelid
andtimestamp + userid + channelid
? Leaving out some queries?
– gempir
Sep 24 '18 at 14:19
@gempir as per your model in the question, you can query only based on channel.id + user.id /// or /// channel.id+user.id+timestamp and nothing more than that .
– Dinesh Kumar
Sep 24 '18 at 14:45
The schema is changeable. I just want to avoid storing messages twice in 2 tables
– gempir
Sep 24 '18 at 14:51
What kind of queries do you want to apply on logstv.messages?
– Dinesh Kumar
Sep 24 '18 at 14:58
2 kind something with channelid, timestamp and userid AND a query with just channelid and timestamp
– gempir
Sep 24 '18 at 15:09
|
show 8 more comments
Is it maybe possible without ALLOW FILTERING; but only supporting WHEREtimestamp + channelid
andtimestamp + userid + channelid
? Leaving out some queries?
– gempir
Sep 24 '18 at 14:19
@gempir as per your model in the question, you can query only based on channel.id + user.id /// or /// channel.id+user.id+timestamp and nothing more than that .
– Dinesh Kumar
Sep 24 '18 at 14:45
The schema is changeable. I just want to avoid storing messages twice in 2 tables
– gempir
Sep 24 '18 at 14:51
What kind of queries do you want to apply on logstv.messages?
– Dinesh Kumar
Sep 24 '18 at 14:58
2 kind something with channelid, timestamp and userid AND a query with just channelid and timestamp
– gempir
Sep 24 '18 at 15:09
Is it maybe possible without ALLOW FILTERING; but only supporting WHERE
timestamp + channelid
and timestamp + userid + channelid
? Leaving out some queries?– gempir
Sep 24 '18 at 14:19
Is it maybe possible without ALLOW FILTERING; but only supporting WHERE
timestamp + channelid
and timestamp + userid + channelid
? Leaving out some queries?– gempir
Sep 24 '18 at 14:19
@gempir as per your model in the question, you can query only based on channel.id + user.id /// or /// channel.id+user.id+timestamp and nothing more than that .
– Dinesh Kumar
Sep 24 '18 at 14:45
@gempir as per your model in the question, you can query only based on channel.id + user.id /// or /// channel.id+user.id+timestamp and nothing more than that .
– Dinesh Kumar
Sep 24 '18 at 14:45
The schema is changeable. I just want to avoid storing messages twice in 2 tables
– gempir
Sep 24 '18 at 14:51
The schema is changeable. I just want to avoid storing messages twice in 2 tables
– gempir
Sep 24 '18 at 14:51
What kind of queries do you want to apply on logstv.messages?
– Dinesh Kumar
Sep 24 '18 at 14:58
What kind of queries do you want to apply on logstv.messages?
– Dinesh Kumar
Sep 24 '18 at 14:58
2 kind something with channelid, timestamp and userid AND a query with just channelid and timestamp
– gempir
Sep 24 '18 at 15:09
2 kind something with channelid, timestamp and userid AND a query with just channelid and timestamp
– gempir
Sep 24 '18 at 15:09
|
show 8 more comments
Thanks for contributing an answer to Database Administrators Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f218354%2fcassandra-querying-without-full-primary-key%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown