What's the difference between creating a table and creating a columnfamily in Cassandra?

前端 未结 5 1458
情书的邮戳
情书的邮戳 2021-02-03 20:59

I need details from both performance and query aspects, I learnt from some site that only a key can be given when using a columnfamily, if so what would you suggest for

相关标签:
5条回答
  • 2021-02-03 21:16

    Column family are somewhat related to relational database's table, with a distribution differences and maybe even idealistic character.

    Imaging you have a user entity that might contain 15 column, in a relational db you might want to divide the columns into small-related-column-based struct that we all know as Table. In distributed db such as Cassandra you'll be able to concatenate all those tables entry into a single long row, so if you'll use profiler/ db manager you'll see a single table with 15 columns instead of 2/3 tables. Another interesting thing is that every column family is written to different nodes, maybe on different cluster and be recognized by the row key, meaning that you'll have a single key to all the columns family and won't need to maintain a PK or FK for every table and maintain the relationships between them with 1-1, 1-n, n-n relations. Easy!

    0 讨论(0)
  • 2021-02-03 21:19

    In cassandra there is no difference between table and columnfamily. they are one concept.

    0 讨论(0)
  • 2021-02-03 21:27

    Refer the document: https://cassandra.apache.org/doc/old/CQL-3.0.html

    It specifies that the LRM of the CQL supports TABLE keyword wherever COLUMNFAMILY is supported.

    This is a proof that TABLE and COLUMNFAMILY are synonyms.

    0 讨论(0)
  • 2021-02-03 21:28

    For Cassandra 3+ and cqlsh 5.0.1

    To verify, enter into a cqlsh prompt within keyspace (ksp):

    CREATE COLUMNFAMILY myTable (
         ...  id text,
         ...  name int
    );
    
    

    And type 'desc myTable'.
    You'll see:

    CREATE TABLE ksp.myTable (
          ...  id text,
          ...  name int
    );
    
    

    They are synonyms, and Cassandra uses table by default.

    0 讨论(0)
  • 2021-02-03 21:40

    To answer the original question you posed: a column family and a table are the same thing.

    • The name "column family" was used in the older Thrift API.
    • The name "table" is used in the newer CQL API.

    More info on the APIs can be found here: http://wiki.apache.org/cassandra/API

    If you need to use "group by,order by,count,sum,ifnull,concat ,joins and some times nested querys" as you state then you probably don't want to use Cassandra, since it doesn't support most of those.

    CQL supports COUNT, but only up to 10000. It supports ORDER BY, but only on clustering keys. The other things you mention are not supported at all.

    0 讨论(0)
提交回复
热议问题