Query Time for Extremely Small Tables is Too Long

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: 超小表查询时间过长

| username: TiDBer_zoNUyIlF

Executing select type, id from base_question;
The total number of records in the base_question table is 36.
The type column is of type varchar(255) and the returned data length is around 10 characters.
The id column is of type bigint(20) and the maximum returned value is a 2-digit number.
In the TiDB dashboard’s slow SQL statistics, there are occasional instances where it takes 3 to 4 seconds, or even up to 10 seconds.
The normal execution time is also above 300ms.

| username: tidb菜鸟一只 | Original post link

Does this table frequently undergo insert, delete, and update operations?

| username: zhanggame1 | Original post link

show table xxx regions

| username: TiDBer_IU34EeRL | Original post link

Ask how to optimize if frequently updating small tables.

| username: 有猫万事足 | Original post link

To be direct, Redis. :joy:

| username: TiDBer_zoNUyIlF | Original post link

Not frequently changed, basically static.

| username: 有猫万事足 | Original post link

For small tables that are not frequently modified, just put them in the cache.

alter table {table_name} cache;
| username: TiDBer_zoNUyIlF | Original post link

The image is not visible. Please provide the text you need translated.

| username: tidb菜鸟一只 | Original post link

So it can be cached directly, as it needs to be accessed frequently, right?

| username: TiDBer_zoNUyIlF | Original post link

It’s not too frequent, just curious why queries on small tables also occasionally appear very slow.

| username: 人如其名 | Original post link

It’s meaningless to just talk about it. Post the execution information when it runs slowly, and share the slow queries and related information.

| username: redgame | Original post link

Following the suggestion above, cached it.

| username: tidb菜鸟一只 | Original post link

It shouldn’t be very slow if it’s not too frequent. You can post the SQL information from the dashboard page to see where it’s slow.

| username: zhanggame1 | Original post link

Sometimes, could slowness be related to locking issues?

| username: liuis | Original post link

Cache small tables directly?

| username: linnana | Original post link

Small tables that are frequently updated are probably not suitable for caching, right?