---
title: table_id 的含义-OceanBase数据库使用指南
description: 了解OceanBase数据库在实际应用中关于table_id 的含义相关的常见问题和使用技巧，帮助您快速解决table_id 的含义的难题。
---
切换语言

- 中文站 - 简体中文
- International - English
- 日本站 - 日本語

划线反馈

# table_id 的含义

更新时间：2026-05-19 09:51

适用版本： V2.1.x、V2.2.x、V3.1.x、V3.2.x 内容类型：TechNote  

在 OceanBase 数据库 V3.x 版本及之前，在 `__all_virtual_table` 虚拟视图中 `table_id` 和 `tenant_id` 存在关系，可以从`table_id` 中解析出 `tenant_id`。

- tenant_id：租户 ID。
 - table_id：表 ID。

## 适用版本

OceanBase 数据库 V2.x 和 V3.x 版本。

## table_id 介绍

table_id 里包含了租户 ID 即 tenant_id 和纯 table_id 即 pure table_id。table_id 共 64 位，其中，高 24 位是 tenant_id，低 40 位是 pure table_id。

即:

- table_id 右移 40 位（消除低位数据），左边自动补 0，右边移出位舍弃，即获取到 tenant_id。
 - table_id 左移 24 位（消除高位数据），再右移 24 位（补全高位数据为全 0），即只取 table_id (64 位)的后 40 位，得到 pure table_id。

### 获取 tenant_id

右移 40 位，左边自动补 0，右边移出位舍弃，即获取到租户 ID。

```shell
0000 0000000001 00000000000000000000 0000000000 0000110001 0111111010 ->
0000 0000000000 0000000000 0000000000 0000000000 0000000001 0000000000

```

```shell
mysql> select 1125899906893306 >> 40;

```

输出结果如下。

```shell
+------------------------+
| 1125899906893306 >> 40 |
+------------------------+
|                   1024 |
+------------------------+
1 row in set (0.00 sec)

```

### 获取 pure table_id

左移 24 位，再右移 24 位，即只取 table_id (64 位)的后 40 位，得到 pure table_id。

```shell
0000 0000000001 00000000000000000000 0000000000 0000110001 0111111010 ->
0000000000 0000000000 0000110001 0111111010 0000000000 0000000000 0000

0000000000 0000000000 0000110001 01111110100000000000 0000000000 0000->
0000 0000000000 0000000000 0000000000 0000000000 0000110001 0111111010

```

```shell
mysql> select (1125899906893306 << 24) >> 24;

```

输出结果如下。

```shell
+--------------------------------+
| (1125899906893306 << 24) >> 24 |
+--------------------------------+
|                          50682 |
+--------------------------------+
1 row in set (0.00 sec)

```

## 建议与推荐

同样的在 `__all_virtual_user` 虚拟表中，`user_id` 也存在这种关系。

```shell
obclient [oceanbase]> select tenant_id,user_id,user_name ,user_id >> 40 as t_id from __all_virtual_user;

```

输出结果如下。

```shell
+-----------+------------------+--------------------------------+------+
| tenant_id | user_id          | user_name                      | t_id |
+-----------+------------------+--------------------------------+------+
|         1 |    1099511627777 | root                           |    1 |
|         1 |    1099511627781 | ORAAUDITOR                     |    1 |
|         1 |    1099511628777 | __oceanbase_inner_standby_user |    1 |
|         1 |    1099511628778 | proxyro                        |    1 |
|         1 |    1099511628779 | ocp_monitor                    |    1 |
|         1 |    1099511628780 | oms_drc                        |    1 |
|      1001 | 1100611139403777 | root                           | 1001 |
|      1001 | 1100611139403781 | ORAAUDITOR                     | 1001 |
|      1002 | 1101710651031555 | SYS                            | 1002 |
|      1002 | 1101710651031556 | LBACSYS                        | 1002 |
|      1002 | 1101710651031557 | ORAAUDITOR                     | 1002 |
|      1002 | 1101710651031558 | CONNECT                        | 1002 |
|      1002 | 1101710651031559 | RESOURCE                       | 1002 |
|      1002 | 1101710651031560 | DBA                            | 1002 |
|      1002 | 1101710651031561 | PUBLIC                         | 1002 |
|      1002 | 1101710651032553 | OB_MV_DBA                      | 1002 |
|      1002 | 1101710651032554 | ORACLE_TEST333                 | 1002 |
|      1002 | 1101710651032555 | OB_TEST                        | 1002 |
+-----------+------------------+--------------------------------+------+

```

上一篇

[通过 alter table 修改分区规则时，遇到报错：Too many fields in 'list of partition fields' 的原因和解决方法](https://www.oceanbase.com/knowledge-base/oceanbase-database-1000000003285239)

下一篇

[OceanBase 数据库支持的 table_id 个数](https://www.oceanbase.com/knowledge-base/oceanbase-database-1000000000207731) ![有帮助](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*y6ocSqN8cqsAAAAAAAAAAAAAARQnAQ)![无帮助](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*BG9IQJyLHF8AAAAAAAAAAAAAARQnAQ)![反馈](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*eTWdQKCRKHwAAAAAAAAAAAAAARQnAQ)[AI](https://www.oceanbase.com/obi) 咨询热线
