Cassandra querying without full primary keyIndexing - Uniqueidentifier Foreign Key or Intermediary mapping...

Will rerolling initiative each round stop meta-gaming about initiative?

Why is it that Bernie Sanders is always called a "socialist"?

What to do with threats of blacklisting?

What senses are available to a corpse subjected to a Speak with Dead spell?

Equivalent of "illegal" for violating civil law

A starship is travelling at 0.9c and collides with a small rock. Will it leave a clean hole through, or will more happen?

Taking headphones when quitting job

Is there a way to store 9th-level spells in a Glyph of Warding or similar method?

Is a creature that sees a Medusa's eyes automatically subjected to a saving throw?

Is there a file that always exists and a 'normal' user can't lstat it?

Not a Long-Winded Riddle

Is there a way to not have to poll the UART of an AVR?

How to write cases in LaTeX?

How to not let the Identify spell spoil everything?

Does the US government have any planning in place to ensure there's no shortages of food, fuel, steel and other commodities?

Custom shape shows unwanted extra line

Find the smallest value of the function

How is this property called for mod?

Midterm in Mathematics Courses

Stuck on a Geometry Puzzle

Converting very wide logos to square formats

Prevent Nautilus / Nemo from creating .Trash-1000 folder in mounted devices

Broad Strokes - missing letter riddle

Critique vs nitpicking



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













1















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;









share|improve this question
















bumped to the homepage by Community 12 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.




















    1















    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;









    share|improve this question
















    bumped to the homepage by Community 12 mins ago


    This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.


















      1












      1








      1








      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;









      share|improve this question
















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Sep 24 '18 at 15:59







      gempir

















      asked Sep 23 '18 at 14:40









      gempirgempir

      1064




      1064





      bumped to the homepage by Community 12 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 12 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
























          1 Answer
          1






          active

          oldest

          votes


















          0














          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.






          share|improve this answer
























          • 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













          • 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











          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
          });


          }
          });














          draft saved

          draft discarded


















          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









          0














          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.






          share|improve this answer
























          • 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













          • 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
















          0














          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.






          share|improve this answer
























          • 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













          • 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














          0












          0








          0







          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.






          share|improve this answer













          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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Sep 23 '18 at 19:55









          Dinesh KumarDinesh Kumar

          153113




          153113













          • 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













          • 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













          • @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


















          draft saved

          draft discarded




















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          Parapolítica Índice Antecedentes El escándalo Proceso judicial Consecuencias Véase...

          How to remove border from elements in the last row?Targeting flex items on the last rowHow to vertically wrap...

          Tecnologías entrañables Índice Antecedentes Desarrollo Tecnologías Entrañables en la...