forked from docs/doc-exports
Reviewed-by: Hasko, Vladimir <vladimir.hasko@t-systems.com> Reviewed-by: Pruthi, Vineet <vineet.pruthi@t-systems.com> Co-authored-by: Lu, Huayi <luhuayi@huawei.com> Co-committed-by: Lu, Huayi <luhuayi@huawei.com>
177 lines
15 KiB
HTML
177 lines
15 KiB
HTML
<a name="EN-US_TOPIC_0000001772536536"></a><a name="EN-US_TOPIC_0000001772536536"></a>
|
|
|
|
<h1 class="topictitle1">Unique Indexes</h1>
|
|
<div id="body8662426"><p id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_en-us_topic_0214164547_p330274862511">GaussDB(DWS) does not support the combination of unique indexes (constraints) and primary key constraints. DSC will perform adaptation based on GaussDB(DWS) features during migration.</p>
|
|
<div class="caution" id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_en-us_topic_0214164547_note49007161318"><span class="cautiontitle"><img src="public_sys-resources/caution_3.0-en-us.png"> </span><div class="cautionbody"><p id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_en-us_topic_0214164547_p790207191318">If MySQL unique indexes (constraints) and primary key constraints are used together during migration, OLAP distribution keys may become unavailable. Therefore, this scenario is not supported by DSC.</p>
|
|
</div></div>
|
|
<ol id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_en-us_topic_0214164547_ol12553123692615"><li id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_en-us_topic_0214164547_li15553183615265">For a unique inline index, if the primary key index and the unique index are the same column, DSC will remove the unique index during migration.<p id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_en-us_topic_0214164547_p135691921172717"><a name="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_en-us_topic_0214164547_li15553183615265"></a><a name="en-us_topic_0000001706224137_en-us_topic_0000001385792490_en-us_topic_0214164547_li15553183615265"></a><strong id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_en-us_topic_0214164547_b123631548192715">Input</strong></p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_en-us_topic_0214164547_screen182799185276">CREATE TABLE IF NOT EXISTS `public`.`runoob_dataType_test`
|
|
(
|
|
`id` INT PRIMARY KEY AUTO_INCREMENT,
|
|
`name` VARCHAR(128) NOT NULL,
|
|
UNIQUE (id ASC)
|
|
);</pre>
|
|
<p id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_en-us_topic_0214164547_p77858251279"><strong id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_en-us_topic_0214164547_b197144504277">Output</strong></p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_en-us_topic_0214164547_screen71919285272">CREATE TABLE IF NOT EXISTS "public"."runoob_datatype_test"
|
|
(
|
|
"id" SERIAL PRIMARY KEY,
|
|
"name" VARCHAR(128) NOT NULL
|
|
)
|
|
WITH ( ORIENTATION = ROW, COMPRESSION = NO )
|
|
NOCOMPRESS
|
|
DISTRIBUTE BY HASH ("id");</pre>
|
|
</li><li id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_en-us_topic_0214164547_li19672194516269">If there is a unique index created by <strong id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_b157186154032255">ALTER TABLE</strong>, DSC will create a normal index based on GaussDB(DWS) features.<p id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_en-us_topic_0214164547_p1287443289"><strong id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_en-us_topic_0214164547_b728710413284">Input</strong></p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_en-us_topic_0214164547_screen9287164132817">CREATE TABLE IF NOT EXISTS `public`.`runoob_alter_test`(
|
|
`dataType1` int,
|
|
`dataType2` FLOAT(10,2),
|
|
`dataType3` DOUBLE(20,8)
|
|
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
|
|
|
ALTER TABLE runoob_alter_test ADD UNIQUE idx_runoob_alter_test_datatype1(dataType1);
|
|
ALTER TABLE runoob_alter_test ADD UNIQUE INDEX idx_runoob_alter_test_datatype1(dataType2);
|
|
ALTER TABLE runoob_alter_test ADD UNIQUE KEY idx_runoob_alter_test_datatype1(dataType3);
|
|
|
|
CREATE TABLE IF NOT EXISTS `public`.`runoob_alter_test`(
|
|
`dataType1` int,
|
|
`dataType2` FLOAT(10,2),
|
|
`dataType3` DOUBLE(20,8),
|
|
`dataType4` TEXT NOT NULL,
|
|
`dataType5` YEAR NOT NULL DEFAULT '2018',
|
|
`dataType6` DATETIME NOT NULL DEFAULT '2018-10-12 15:27:33.999999'
|
|
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
|
|
|
ALTER TABLE runoob_alter_test ADD CONSTRAINT UNIQUE idx_runoob_alter_test_datatype1(dataType1);
|
|
ALTER TABLE runoob_alter_test ADD CONSTRAINT UNIQUE INDEX idx_runoob_alter_test_datatype2(dataType2);
|
|
ALTER TABLE runoob_alter_test ADD CONSTRAINT UNIQUE KEY idx_runoob_alter_test_datatype3(dataType3);
|
|
ALTER TABLE runoob_alter_test ADD CONSTRAINT constraint_dataType UNIQUE idx_runoob_alter_test_datatype4(dataType4);
|
|
ALTER TABLE runoob_alter_test ADD CONSTRAINT constraint_dataType UNIQUE INDEX idx_runoob_alter_test_datatype5(dataType5);
|
|
ALTER TABLE runoob_alter_test ADD CONSTRAINT constraint_dataType UNIQUE KEY idx_runoob_alter_test_datatype6(dataType6);</pre>
|
|
<p id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_en-us_topic_0214164547_p142870442811"><strong id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_en-us_topic_0214164547_b10288134162811">Output</strong></p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_en-us_topic_0214164547_screen19288648288">CREATE TABLE IF NOT EXISTS "public"."runoob_alter_test"
|
|
(
|
|
"datatype1" INTEGER,
|
|
"datatype2" REAL,
|
|
"datatype3" DOUBLE PRECISION
|
|
)
|
|
WITH ( ORIENTATION = ROW, COMPRESSION = NO )
|
|
NOCOMPRESS
|
|
DISTRIBUTE BY HASH ("datatype1");
|
|
|
|
CREATE INDEX "idx_runoob_alter_test_datatype1" ON "public"."runoob_alter_test" ("datatype1");
|
|
CREATE INDEX "idx_runoob_alter_test_datatype1" ON "public"."runoob_alter_test" ("datatype2");
|
|
CREATE INDEX "idx_runoob_alter_test_datatype1" ON "public"."runoob_alter_test" ("datatype3");
|
|
|
|
CREATE TABLE IF NOT EXISTS "public"."runoob_alter_test"
|
|
(
|
|
"datatype1" INTEGER,
|
|
"datatype2" REAL,
|
|
"datatype3" DOUBLE PRECISION,
|
|
"datatype4" TEXT NOT NULL,
|
|
"datatype5" SMALLINT NOT NULL DEFAULT '2018',
|
|
"datatype6" TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT '2018-10-12 15:27:33.999999'
|
|
)
|
|
WITH ( ORIENTATION = ROW, COMPRESSION = NO )
|
|
NOCOMPRESS
|
|
DISTRIBUTE BY HASH ("datatype1");
|
|
|
|
CREATE INDEX "idx_runoob_alter_test_datatype1" ON "public"."runoob_alter_test" ("datatype1");
|
|
CREATE INDEX "idx_runoob_alter_test_datatype2" ON "public"."runoob_alter_test" ("datatype2");
|
|
CREATE INDEX "idx_runoob_alter_test_datatype3" ON "public"."runoob_alter_test" ("datatype3");
|
|
CREATE INDEX "idx_runoob_alter_test_datatype4" ON "public"."runoob_alter_test" ("datatype4");
|
|
CREATE INDEX "idx_runoob_alter_test_datatype5" ON "public"."runoob_alter_test" ("datatype5");
|
|
CREATE INDEX "idx_runoob_alter_test_datatype6" ON "public"."runoob_alter_test" ("datatype6");</pre>
|
|
</li><li id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_li14995834193418">If there is a unique index created by <strong id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_b151652011232255">CREATE INDEX</strong>, DSC will create a normal index based on GaussDB(DWS) features.<p id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_p10237131217357"><strong id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_b11238191223514">Input</strong></p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_screen1023871253510">CREATE TABLE `public`.`test_index_table01` (
|
|
`TABLE01_ID` INT(11) NOT NULL,
|
|
`TABLE01_THEME` VARCHAR(100) NULL DEFAULT NULL,
|
|
`AUTHOR_NAME` CHAR(10) NULL DEFAULT NULL,
|
|
`AUTHOR_ID` INT(11) NULL DEFAULT NULL,
|
|
`CREATE_TIME` INT NULL DEFAULT NULL,
|
|
PRIMARY KEY(`TABLE01_ID`)
|
|
);
|
|
CREATE UNIQUE INDEX AUTHOR_INDEX ON `test_index_table01`(AUTHOR_ID);</pre>
|
|
<p id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_p18238412113514"><strong id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_b423801273512">Output</strong></p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_screen14238512173513">CREATE TABLE "public"."test_index_table01"
|
|
(
|
|
"table01_id" INTEGER NOT NULL,
|
|
"table01_theme" VARCHAR(400) DEFAULT NULL,
|
|
"author_name" CHAR(40) DEFAULT NULL,
|
|
"author_id" INTEGER DEFAULT NULL,
|
|
"create_time" INTEGER DEFAULT NULL,
|
|
PRIMARY KEY ("table01_id")
|
|
)
|
|
WITH ( ORIENTATION = ROW, COMPRESSION = NO )
|
|
NOCOMPRESS
|
|
DISTRIBUTE BY HASH ("table01_id");
|
|
CREATE INDEX "author_index" ON "public"."test_index_table01" ("author_id");</pre>
|
|
<p id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_p877205093418"></p>
|
|
</li><li id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_li19273353162415">If CREATE TABLE has multiple unique indexes, during migration, DSC will create all unique indexes as common indexes based on GaussDB(DWS) features.<p id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_p16461040142712"><a name="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_li19273353162415"></a><a name="en-us_topic_0000001706224137_en-us_topic_0000001385792490_li19273353162415"></a><strong id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_b196461940142714">Input</strong></p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_screen10646124012270">CREATE TABLE `public`.`test_index_table01` (
|
|
`TABLE01_ID` INT(11) NOT NULL,
|
|
`TABLE01_THEME` VARCHAR(100) NULL DEFAULT NULL,
|
|
`AUTHOR_NAME` CHAR(10) NULL DEFAULT NULL,
|
|
`AUTHOR_ID` INT(11) NULL DEFAULT NULL,
|
|
`CREATE_TIME` INT NULL DEFAULT NULL,
|
|
UNIQUE(`TABLE01_ID`),
|
|
UNIQUE(`AUTHOR_ID`)
|
|
);</pre>
|
|
<p id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_p1664613408276"><strong id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_b4646440122714">Output</strong></p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_screen136461406270">CREATE TABLE "public"."test_index_table01" (
|
|
"table01_id" INTEGER NOT NULL,
|
|
"table01_theme" VARCHAR(400) DEFAULT NULL,
|
|
"author_name" CHAR(40) DEFAULT NULL,
|
|
"author_id" INTEGER DEFAULT NULL,
|
|
"create_time" INTEGER DEFAULT NULL
|
|
) WITH (ORIENTATION = ROW, COMPRESSION = NO) NOCOMPRESS DISTRIBUTE BY HASH ("table01_id");
|
|
CREATE INDEX "idx_test_index_table01_table01_id" ON "public"."test_index_table01"("TABLE01_ID");
|
|
CREATE INDEX "idx_test_index_table01_author_id" ON "public"."test_index_table01"("AUTHOR_ID");</pre>
|
|
<p id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_p2015713962713"></p>
|
|
</li><li id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_li577711503277">If CREATE TABLE has a unique index but does not have a primary key index, DSC retains the unique index based on GaussDB (DWS) features during migration.<p id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_p893219516308"><a name="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_li577711503277"></a><a name="en-us_topic_0000001706224137_en-us_topic_0000001385792490_li577711503277"></a><strong id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_b9932125113020">Input</strong></p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_screen1493212543016">CREATE TABLE `public`.`test_index_table01` (
|
|
`TABLE01_ID` INT(11) NOT NULL,
|
|
`TABLE01_THEME` VARCHAR(100) NULL DEFAULT NULL,
|
|
`AUTHOR_NAME` CHAR(10) NULL DEFAULT NULL,
|
|
`AUTHOR_ID` INT(11) NULL DEFAULT NULL,
|
|
`CREATE_TIME` INT NULL DEFAULT NULL,
|
|
UNIQUE(`AUTHOR_ID`)
|
|
);</pre>
|
|
<p id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_p179321543014"><strong id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_b15932752302">Output</strong></p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_screen149326533013">CREATE TABLE "public"."test_index_table01" (
|
|
"table01_id" INTEGER NOT NULL,
|
|
"table01_theme" VARCHAR(400) DEFAULT NULL,
|
|
"author_name" CHAR(40) DEFAULT NULL,
|
|
"author_id" INTEGER DEFAULT NULL,
|
|
"create_time" INTEGER DEFAULT NULL,
|
|
UNIQUE ("author_id")
|
|
) WITH (ORIENTATION = ROW, COMPRESSION = NO) NOCOMPRESS DISTRIBUTE BY HASH ("author_id");</pre>
|
|
<p id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_p19932115143018"></p>
|
|
</li><li id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_li54496812315">If CREATE TABLE has a primary key index, DSC creates all unique indexes as common indexes based on GaussDB(DWS) features during migration.<p id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_p2341132311322"><a name="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_li54496812315"></a><a name="en-us_topic_0000001706224137_en-us_topic_0000001385792490_li54496812315"></a><strong id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_b18341123193216">Input</strong></p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_screen15341823123219">CREATE TABLE `public`.`test_index_table01` (
|
|
`TABLE01_ID` INT(11) NOT NULL,
|
|
`TABLE01_THEME` VARCHAR(100) NULL DEFAULT NULL,
|
|
`AUTHOR_NAME` CHAR(10) NULL DEFAULT NULL,
|
|
`AUTHOR_ID` INT(11) NULL DEFAULT NULL,
|
|
`CREATE_TIME` INT NULL DEFAULT NULL,
|
|
PRIMARY KEY(`TABLE01_ID`),
|
|
UNIQUE(`AUTHOR_ID`)
|
|
);</pre>
|
|
<p id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_p2342122310320"><strong id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_b1234272314321">Output</strong></p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_screen14342023123219">CREATE TABLE "public"."test_index_table01" (
|
|
"table01_id" INTEGER NOT NULL,
|
|
"table01_theme" VARCHAR(400) DEFAULT NULL,
|
|
"author_name" CHAR(40) DEFAULT NULL,
|
|
"author_id" INTEGER DEFAULT NULL,
|
|
"create_time" INTEGER DEFAULT NULL,
|
|
PRIMARY KEY ("table01_id")
|
|
) WITH (ORIENTATION = ROW, COMPRESSION = NO) NOCOMPRESS DISTRIBUTE BY HASH ("table01_id");
|
|
CREATE INDEX "idx_test_index_table01_author_id" ON "public"."test_index_table01"("AUTHOR_ID");</pre>
|
|
<p id="EN-US_TOPIC_0000001772536536__en-us_topic_0000001706224137_en-us_topic_0000001385792490_p1342223113214"></p>
|
|
</li></ol>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="dws_16_0166.html">Indexes</a></div>
|
|
</div>
|
|
</div>
|
|
|