Hi,
I'm testing MyRocks for our specific use case. Below is the table structure:
CREATE TABLE `usertable1` (
`id` varchar(50) COLLATE utf8_bin NOT NULL,
`partition_info` text COLLATE utf8_bin NOT NULL,
`chunk_id` bigint(20) NOT NULL,
`topic_partition` varchar(50) COLLATE utf8_bin NOT NULL,
`data` mediumtext COLLATE utf8_bin NOT NULL,
PRIMARY KEY (`id`) COMMENT 'rev:cf_1',
KEY `index1` (`partition_info`(255),`chunk_id`,`topic_partition`) COMMENT 'rev:cf_1'
) ENGINE=ROCKSDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='ttl_duration=604800;'
I have some doubts and little understanding about MyRocks, that wants to verify here:
1. Below, I'm using 'select *', So it is doing row scan. Here resulted rows are in reverse order, because the column family is defined as 'rev:cf_1'.
Do this ordering based on a particular column value or it is just following insertion order of rows?
mysql> explain select * from usertable1 limit 10;
+----+-------------+------------+------------+------+---------------+------+---------+------+-------+----------+-------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+-------------+------------+------------+------+---------------+------+---------+------+-------+----------+-------+
| 1 | SIMPLE | usertable1 | NULL | ALL | NULL | NULL | NULL | NULL | 20306 | 100.00 | NULL |
+----+-------------+------------+------------+------+---------------+------+---------+------+-------+----------+-------+
1 row in set, 1 warning (0.00 sec)
mysql> select max(id), min(id) from usertable1;
+---------------+---------------+
| max(id) | min(id) |
+---------------+---------------+
| 1623142509296 | 1623136749420 |
+---------------+---------------+
1 row in set (0.00 sec)
mysql> select * from usertable1 limit 10;
+---------------+------------------+----------------+-----------------+-------------+
| id | partition_info | chunk_id | topic_partition | data |
+---------------+------------------+----------------+-----------------+-------------+
| 1623142509296 | PartitionValue-1 | 20210608000000 | Topic-4 | USER_DATA-2 |
| 1623142509295 | PartitionValue-3 | 20210608000000 | Topic-4 | USER_DATA-0 |
| 1623142509294 | PartitionValue-3 | 20210608000000 | Topic-1 | USER_DATA-3 |
| 1623142509293 | PartitionValue-4 | 20210608000000 | Topic-1 | USER_DATA-3 |
| 1623142509292 | PartitionValue-0 | 20210608000000 | Topic-1 | USER_DATA-1 |
| 1623142509291 | PartitionValue-0 | 20210608000000 | Topic-0 | USER_DATA-4 |
| 1623142509290 | PartitionValue-0 | 20210608000000 | Topic-3 | USER_DATA-3 |
| 1623142509289 | PartitionValue-3 | 20210608000000 | Topic-1 | USER_DATA-2 |
| 1623142509288 | PartitionValue-0 | 20210608000000 | Topic-0 | USER_DATA-1 |
| 1623142509287 | PartitionValue-3 | 20210608000000 | Topic-4 | USER_DATA-1 |
+---------------+------------------+----------------+-----------------+-------------+
10 rows in set (0.00 sec)
2. Here, I'm projecting id column only. Why it is using index1?
And if I do not specify order by then how result follows ordering?
mysql> explain select id from usertable1 limit 10;
+----+-------------+------------+------------+-------+---------------+--------+---------+------+-------+----------+-------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+-------------+------------+------------+-------+---------------+--------+---------+------+-------+----------+-------------+
| 1 | SIMPLE | usertable1 | NULL | index | NULL | index1 | 927 | NULL | 20306 | 100.00 | Using index |
+----+-------------+------------+------------+-------+---------------+--------+---------+------+-------+----------+-------------+
1 row in set, 1 warning (0.00 sec)
mysql> select id from usertable1 limit 10;
+---------------+
| id |
+---------------+
| 1623136749949 |
| 1623136749950 |
| 1623136749969 |
| 1623136750002 |
| 1623136750044 |
| 1623136750091 |
| 1623136750162 |
| 1623136750170 |
| 1623136750217 |
| 1623136750226 |
+---------------+
10 rows in set (0.00 sec)
mysql> explain select id from usertable1 order by id asc limit 10;
+----+-------------+------------+------------+-------+---------------+---------+---------+------+------+----------+-------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+-------------+------------+------------+-------+---------------+---------+---------+------+------+----------+-------------+
| 1 | SIMPLE | usertable1 | NULL | index | NULL | PRIMARY | 152 | NULL | 10 | 100.00 | Using index |
+----+-------------+------------+------------+-------+---------------+---------+---------+------+------+----------+-------------+
1 row in set, 1 warning (0.00 sec)
mysql> select id from usertable1 order by id asc limit 10;
+---------------+
| id |
+---------------+
| 1623136749420 |
| 1623136749421 |
| 1623136749422 |
| 1623136749423 |
| 1623136749424 |
| 1623136749425 |
| 1623136749426 |
| 1623136749427 |
| 1623136749428 |
| 1623136749429 |
+---------------+
10 rows in set (0.00 sec)
3. Below, it use index1 to list rows. mysql> explain select topic_partition from usertable1 limit 10;
+----+-------------+------------+------------+-------+---------------+--------+---------+------+-------+----------+-------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+-------------+------------+------------+-------+---------------+--------+---------+------+-------+----------+-------------+
| 1 | SIMPLE | usertable1 | NULL | index | NULL | index1 | 927 | NULL | 20306 | 100.00 | Using index |
+----+-------------+------------+------------+-------+---------------+--------+---------+------+-------+----------+-------------+
1 row in set, 1 warning (0.00 sec)
mysql> select topic_partition from usertable1 limit 10;
+-----------------+
| topic_partition |
+-----------------+
| Topic-0 |
| Topic-0 |
| Topic-0 |
| Topic-0 |
| Topic-0 |
| Topic-0 |
| Topic-0 |
| Topic-0 |
| Topic-0 |
| Topic-0 |
+-----------------+
10 rows in set (0.00 sec)
4. Below, column partition_info is TEXT type. So this query is not using index. It do row scan. Will Indexing work on TEXT type columns? In what case it will work?mysql> explain select id, partition_info from usertable1 limit 10;
+----+-------------+------------+------------+------+---------------+------+---------+------+-------+----------+-------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+-------------+------------+------------+------+---------------+------+---------+------+-------+----------+-------+
| 1 | SIMPLE | usertable1 | NULL | ALL | NULL | NULL | NULL | NULL | 20306 | 100.00 | NULL |
+----+-------------+------------+------------+------+---------------+------+---------+------+-------+----------+-------+
1 row in set, 1 warning (0.00 sec)
mysql> select id, partition_info from usertable1 limit 10;
+---------------+------------------+
| id | partition_info |
+---------------+------------------+
| 1623142509296 | PartitionValue-1 |
| 1623142509295 | PartitionValue-3 |
| 1623142509294 | PartitionValue-3 |
| 1623142509293 | PartitionValue-4 |
| 1623142509292 | PartitionValue-0 |
| 1623142509291 | PartitionValue-0 |
| 1623142509290 | PartitionValue-0 |
| 1623142509289 | PartitionValue-3 |
| 1623142509288 | PartitionValue-0 |
| 1623142509287 | PartitionValue-3 |
+---------------+------------------+
10 rows in set (0.00 sec)
5. How many column families should I use if I'm going to create 10k tables?
Each active user may have 5 to 20 tables. Append type of data(insert only) with 7 days TTL. machine config: 1 TB SSD, 64 GB RAM.