Cassandra 单机入门例子——有索引
入门例子:
http://wiki.apache.org/cassandra/GettingStarted
添加环境变量并source生效,使得可以在任意位置执行cassandra/bin安装目录下的命令
1
|
export CASSANDRA_HOME="/Users/zhengqh/Soft/apache-cassandra-2.0.16"
|
前台启动Cassandra进程, sudo cassandra -f
启动一个新的终端, 启动客户端查询: cqlsh
1
|
CREATE KEYSPACE mykeyspace
|
输出:
cqlsh:mykeyspace> SELECT * FROM users WHERE lname = 'smith'; user_id | fname | lname ---------+-------+------- 1745 | john | smith 1746 | john | smith (2 rows) cqlsh:mykeyspace> SELECT * FROM users; user_id | fname | lname ---------+-------+------- 1745 | john | smith 1744 | john | doe 1746 | john | smith (3 rows)
观察服务端的输出:
1
|
INFO 09:29:21,981 Create new Keyspace: mykeyspace, rep strategy:SimpleStrategy{}, strategy_options: {replication_factor=1}, durable_writes: true
|
然后看目录文件:
ls mykeyspace/users
结果:
mykeyspace-users-jb-1-CompressionInfo.db mykeyspace-users-jb-1-Data.db mykeyspace-users-jb-1-Filter.db mykeyspace-users-jb-1-Index.db mykeyspace-users-jb-1-Statistics.db mykeyspace-users-jb-1-Summary.db mykeyspace-users-jb-1-TOC.txt mykeyspace-users.users_lname_idx-jb-1-CompressionInfo.db mykeyspace-users.users_lname_idx-jb-1-Data.db mykeyspace-users.users_lname_idx-jb-1-Filter.db mykeyspace-users.users_lname_idx-jb-1-Index.db mykeyspace-users.users_lname_idx-jb-1-Statistics.db mykeyspace-users.users_lname_idx-jb-1-Summary.db mykeyspace-users.users_lname_idx-jb-1-TOC.txt
如果是针对没有建立索引的字段搜索则会提示:
cqlsh:mykeyspace> SELECT * FROM users WHERE fname = 'smith'; InvalidRequest: Error from server: code=2200 [Invalid query] message="Cannot execute this query as it might involve data filtering and thus may have unpredictab le performance. If you want to execute this query despite the performance unpredictability, use ALLOW FILTERING"
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步