<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                [TOC] # 關于表的索引 可以在表的一個或多個列上創建索引以加速表上的 SQL 語句執行速度。索引使用正確的話,可以減少物理 IO 或者邏輯 IO。 如果創建表時同時設置了主鍵,OceanBase 數據庫會默認創建一個唯一索引。以下面的 SQL 為例: ~~~ obclient> DROP TABLE IF EXISTS t1; Query OK, 0 rows affected (0.01 sec) obclient> CREATE TABLE t1(id bigint not null primary key, name varchar(50)); Query OK, 0 rows affected (0.05 sec) obclient> show indexes from t1\G *************************** 1. row *************************** Table: t1 Non_unique: 0 Key_name: PRIMARY Seq_in_index: 1 Column_name: id Collation: A Cardinality: NULL Sub_part: NULL Packed: NULL Null: Index_type: BTREE Comment: available Index_comment: Visible: YES 1 row in set (0.01 sec) ~~~ ## 新增索引 為表增加索引可以通過 CREATE INDEX 語句。OceanBase 能在普通表和分區表上創建索引,索引可以是本地索引或者全局索引。同時索引可以是唯一索引或者普通索引,如果是分區表的唯一索引,唯一索引必須包含表分區的拆分鍵。 創建索引的 SQL 語法格式如下: ~~~ CREATE [UNIQUE] INDEX index_name ON table_name ( column_list ) [LOCAL | GLOBAL] [ PARTITION BY column_list PARTITIONS N ] ; ~~~ MySQL 租戶里,索引名稱在表范圍內不能重復,查看索引可以通過命令 SHOW INDEXES 。 在 MySQL 租戶里,新增索引還有一種方法,SQL 語法格式如下: ~~~ ALTER TABLE table_name ADD|DROP INDEX|KEY index_name ( column_list ) ; ~~~ 可以一次增加多個索引,索引關鍵字用 INDEX 或 KEY 都可以。 * 示例:對分區表新增索引 ~~~ obclient> create table t3( id bigint not null primary KEY , name varchar(50) , gmt_create timestamp not null default current_timestamp ) partition by hash(id) partitions 8; Query OK, 0 rows affected (0.14 sec) obclient> alter table t3 add unique key t3_uk (name) local; ERROR 1503 (HY000): A UNIQUE INDEX must include all columns in the table's partitioning function obclient> alter table t3 add unique key t3_uk (name, id) LOCAL , add key t3_ind3(gmt_create) global; Query OK, 0 rows affected (18.03 sec) obclient> show indexes from t3; +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+-----------+---------------+---------+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Visible | +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+-----------+---------------+---------+ | t3 | 0 | PRIMARY | 1 | id | A | NULL | NULL | NULL | | BTREE | available | | YES | | t3 | 0 | t3_uk | 1 | name | A | NULL | NULL | NULL | YES | BTREE | available | | YES | | t3 | 0 | t3_uk | 2 | id | A | NULL | NULL | NULL | | BTREE | available | | YES | | t3 | 1 | t3_ind3 | 1 | gmt_create | A | NULL | NULL | NULL | | BTREE | available | | YES | +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+-----------+---------------+---------+ 4 rows in set (0.01 sec) ~~~ ## 刪除索引 刪除索引的語法格式如下: ~~~ ALTER TABLE table_name DROP key|index index_name ; ~~~ * 示例:刪除表的索引 ~~~ obclient> alter table t3 drop key t3_uk, drop key t3_ind3; Query OK, 0 rows affected (0.07 sec) ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看