<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/">
    <channel>
        <title>Comparison of Implicit Type Conversion in MSSQL, Oracle, MySQL, and CUBRID</title>
        <link>http://www.cubrid.org/?mid=cubrid_implicit_type_conversion</link>
        <description>Comparison of Implicit Type Conversion in MSSQL, Oracle, MySQL, and CUBRID</description>
        <language>en</language>
        <pubDate>Thu, 11 Aug 2011 11:06:03 -0800</pubDate>
        <lastBuildDate>Tue, 16 Aug 2011 04:14:46 -0800</lastBuildDate>
        <generator>XpressEngine 1.4.4.1</generator>
                        										        <item>
            <title>Comparison of Implicit Type Conversion in MSSQL, Oracle, MySQL, and CUBRID</title>
            <dc:creator>admin</dc:creator>
            <link>http://www.cubrid.org/cubrid_implicit_type_conversion</link>
            <guid isPermaLink="true">http://www.cubrid.org/cubrid_implicit_type_conversion</guid>
                                    <description><![CDATA[<h1>Comparison of Implicit Type Conversion in MSSQL, Oracle, MySQL, and CUBRID</h1>

<div class="contents-table"></div>

<p><a href="/manual/840/en/Implicit%20Type%20Conversion" target="_self">Implicit type conversion</a>, also known as coercion means that even if a user performs operations on two values of different types, the database system will internally cast one of the values to the type of the other one to perform the operation. For a table of rules which illustrates what data types a particular data type may be converted to can be found in <a href="/manual/840/en/Rules" target="_self">Implicit Type Conversion Rules</a>.</p><p>In this article we will compare four database systems on how they perform implicit type conversion and whether their implementation affects the performance. They are MSSQL, Oracle, MySQL, and CUBRID 8.4.0.</p>

<h2>Overview</h2>

<p>The test has been performed over the "event" table which is a part of a&nbsp;<b>demodb</b>&nbsp;database which is created by default when you install CUBRID.</p>

<div editor_component="code_highlighter" code_type="Sql" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false" style="border: #666666 1px dotted; border-left: #22aaee 5px solid; padding: 5px; background: #FAFAFA url(modules/editor/components/code_highlighter/code.png) no-repeat top right;">
CREATE TABLE "event"(
    "code" int,
    "sports" char(50),
    "name" char(50),
    "gender" char(1),
    "players" int,
    CONSTRAINT pk_event_code PRIMARY KEY("code")
);
</div>

<p>The test assumes two cases:</p>

<ol><li>When the PK is of INT type;</li><li>When the PK is of CHAR type.</li></ol><div>Note that below the SQL is given in a general format, not specific to a particular DB.</div>

<h2>MSSQL</h2>

<p>First, we create an identical table in MSSQL and perform the test.</p><h3>INTEGER PRIMARY KEY</h3><p>Let's see how MSSQL performs if a table PK is of INT type which is a general case.</p>

<div editor_component="code_highlighter" code_type="Sql" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false" style="border: #666666 1px dotted; border-left: #22aaee 5px solid; padding: 5px; background: #FAFAFA url(modules/editor/components/code_highlighter/code.png) no-repeat top right;">
CREATE TABLE "event"(
    "code" int,
    "sports" char(50),
    "name" char(50),
    "gender" char(1),
    "players" int,
    CONSTRAINT pk_event_code PRIMARY KEY("code")
);
</div>

<h4>INTEGER in WHERE condition</h4><p>We will execute the following query with an INT value used in the WHERE clause.</p>

<div editor_component="code_highlighter" code_type="Sql" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false" style="border: #666666 1px dotted; border-left: #22aaee 5px solid; padding: 5px; background: #FAFAFA url(modules/editor/components/code_highlighter/code.png) no-repeat top right;">select * from event where code=20034</div>

<p>MSSQL successfully executes this query using&nbsp;index scan (indicated as <b>Clustered Index Seek</b>).</p>

<p><img src="http://www.cubrid.org/files/attach/images/49/700/203/mssql-pk-int-select-int.png" alt="mssql-pk-int-select-int.png" width="724" height="63" editor_component="image_link"/><br /></p>

<h4>CHAR in WHERE condition</h4>

<p>Now we will execute the same query but will pass CHAR value to <b>code</b>&nbsp;in the WHERE clause.</p>

<div editor_component="code_highlighter" code_type="Sql" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false" style="border: #666666 1px dotted; border-left: #22aaee 5px solid; padding: 5px; background: #FAFAFA url(modules/editor/components/code_highlighter/code.png) no-repeat top right;">select * from event where code='20034'</div>

<p>MSSQL again successfully executes this query using&nbsp;index scan&nbsp;(indicated as&nbsp;<b>Clustered Index Seek</b>). In this case implicit type conversion takes place.</p>

<p><img src="http://www.cubrid.org/files/attach/images/49/700/203/mssql-pk-int-select-char.png" alt="mssql-pk-int-select-char.png" width="629" height="56" editor_component="image_link"/><br /></p>

<h3>CHAR PRIMARY KEY</h3><p>Let's see how MSSQL performs if a table PK is of CHAR type.</p>

<div editor_component="code_highlighter" code_type="Sql" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false" style="border: #666666 1px dotted; border-left: #22aaee 5px solid; padding: 5px; background: #FAFAFA url(modules/editor/components/code_highlighter/code.png) no-repeat top right;">
CREATE TABLE "abcd" (
    "code" char(3),
    "name" char(40) NOT NULL,
    "continent" char(10),
    "capital" char(30),
    CONSTRAINT pk_nation_code PRIMARY KEY("code")
);
</div>

<h4>INTEGER in WHERE condition</h4><p>We will execute the following query with an INT value used in the WHERE clause.</p>

<div editor_component="code_highlighter" code_type="Sql" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false" style="border: #666666 1px dotted; border-left: #22aaee 5px solid; padding: 5px; background: #FAFAFA url(modules/editor/components/code_highlighter/code.png) no-repeat top right;">select * from abcd where code=20034</div>

<p>MSSQL successfully executes this query using&nbsp;index scan&nbsp;(indicated as&nbsp;<b>Clustered Index Seek</b>).&nbsp;In this case implicit type conversion takes place.</p>

<p><img src="http://www.cubrid.org/files/attach/images/49/700/203/mssql-pk-char-select-int.png" alt="mssql-pk-char-select-int.png" width="626" height="68" editor_component="image_link"/><br /></p>

<h4>CHAR in WHERE condition</h4>

<p>Now we will execute the same query but will pass CHAR value to <b>code</b>&nbsp;in the WHERE clause.</p>

<div editor_component="code_highlighter" code_type="Sql" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false" style="border: #666666 1px dotted; border-left: #22aaee 5px solid; padding: 5px; background: #FAFAFA url(modules/editor/components/code_highlighter/code.png) no-repeat top right;">select * from abcd where code='20034'</div>

<p>MSSQL again successfully executes this query using&nbsp;index scan&nbsp;(indicated as&nbsp;<b>Clustered Index Seek</b>).&nbsp;Implicit type conversion does not take place.</p>

<p><img src="http://www.cubrid.org/files/attach/images/49/700/203/mssql-pk-char-select-char.png" alt="mssql-pk-char-select-char.png" width="626" height="77" editor_component="image_link"/></p>

<p class="important">In other words, in both cases MSSQL implicitly converts the types, then performs index scanning.</p>

<h2>Oracle</h2>

<p>We will create an identical table for Oracle and perform the test.</p><h3>INTEGER PRIMARY KEY</h3><p>In this most common case the PK column is of INT type.</p>

<div editor_component="code_highlighter" code_type="Sql" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false" style="border: #666666 1px dotted; border-left: #22aaee 5px solid; padding: 5px; background: #FAFAFA url(modules/editor/components/code_highlighter/code.png) no-repeat top right;">
CREATE TABLE "event"(
    "code" int,
    "sports" char(50),
    "name" char(50),
    "gender" char(1),
    "players" int,
    CONSTRAINT pk_event_code PRIMARY KEY("code")
);
</div>

<h4>INTEGER in WHERE condition</h4><p>We will execute the following query with an INT value used in the WHERE clause.</p>

<div editor_component="code_highlighter" code_type="Sql" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false" style="border: #666666 1px dotted; border-left: #22aaee 5px solid; padding: 5px; background: #FAFAFA url(modules/editor/components/code_highlighter/code.png) no-repeat top right;">select * from event where code=20034</div>

<p>In this case Oracle will use index scan, too&nbsp;(indicated as&nbsp;<b>INDEX UNIQUE SCAN</b>).</p>

<div editor_component="code_highlighter" code_type="Bash" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false" style="border: #666666 1px dotted; border-left: #22aaee 5px solid; padding: 5px; background: #FAFAFA url(modules/editor/components/code_highlighter/code.png) no-repeat top right;">
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT            |             |     1 |    83 |     1   (0)|  00:00:01 |
|   1 |  TABLE ACCESS BY INDEX ROWID| AAA         |     1 |    83 |     1   (0)|  00:00:01 |
|*  2 |   INDEX UNIQUE SCAN         | SYS_C003834 |     1 |       |     1   (0)|  00:00:01 |
--------------------------------------------------------------------------------------------
</div>

<h4>CHAR in WHERE condition</h4>

<p>Now we will pass a CHAR value to <b>code</b>&nbsp;in the WHERE clause.</p>

<div editor_component="code_highlighter" code_type="Sql" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false" style="border: #666666 1px dotted; border-left: #22aaee 5px solid; padding: 5px; background: #FAFAFA url(modules/editor/components/code_highlighter/code.png) no-repeat top right;">select * from event where code='20034'</div>

<p>In this case, too, Oracle will use index scan&nbsp;(indicated as&nbsp;<b>INDEX UNIQUE SCAN</b>)&nbsp;for which implicit type conversion takes place.</p>

<div editor_component="code_highlighter" code_type="Bash" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false" style="border: #666666 1px dotted; border-left: #22aaee 5px solid; padding: 5px; background: #FAFAFA url(modules/editor/components/code_highlighter/code.png) no-repeat top right;">
PLAN_TABLE_OUTPUT
-------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT            |             |     1 |    83 |     1   (0)| 00:00:01 |
|   1 |  TABLE ACCESS BY INDEX ROWID| AAA         |     1 |    83 |     1   (0)| 00:00:01 |
|*  2 |   INDEX UNIQUE SCAN         | SYS_C003834 |     1 |       |     1   (0)| 00:00:01 |
-------------------------------------------------------------------------------------------
</div>

<h3>CHAR PRIMARY KEY</h3><p>Let's see how MSSQL performs if a table PK is of CHAR type.</p>

<div editor_component="code_highlighter" code_type="Sql" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false" style="border: #666666 1px dotted; border-left: #22aaee 5px solid; padding: 5px; background: #FAFAFA url(modules/editor/components/code_highlighter/code.png) no-repeat top right;">
CREATE TABLE "abcd" (
    "code" char(3),
    "name" char(40) NOT NULL,
    "continent" char(10),
    "capital" char(30),
    CONSTRAINT pk_nation_code PRIMARY KEY("code")
);
</div>

<h4>INTEGER in WHERE condition</h4><p>We will execute the following query with an INT value used in the WHERE clause.</p>

<div editor_component="code_highlighter" code_type="Sql" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false" style="border: #666666 1px dotted; border-left: #22aaee 5px solid; padding: 5px; background: #FAFAFA url(modules/editor/components/code_highlighter/code.png) no-repeat top right;">select * from abcd where code=20034</div>

<p>In this case implicit type conversion takes place. But as opposed to MSSQL, in this case Oracle will use <b>full scan</b>&nbsp;(indicated as <b>TABLE ACCESS FULL</b>) instead of index scan. According to Oracle manual, if condition is expressed using character type while the actual column type is numerical, then index scan is used. However,&nbsp;if condition is expressed using integer type while the actual column type is character, then full scan is used.</p>

<div editor_component="code_highlighter" code_type="Bash" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false" style="border: #666666 1px dotted; border-left: #22aaee 5px solid; padding: 5px; background: #FAFAFA url(modules/editor/components/code_highlighter/code.png) no-repeat top right;">
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------
Plan hash value: 271814976
--------------------------------------------------------------------------
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |      |     1 |    19 |     2   (0)| 00:00:01 |
|*  1 |  TABLE ACCESS FULL| ABCD |     1 |    19 |     2   (0)| 00:00:01 |
--------------------------------------------------------------------------
</div>

<h4>CHAR in WHERE condition</h4>

<p>Now we will execute the same query but will pass CHAR value to <b>code</b>&nbsp;in the WHERE clause.</p>

<div editor_component="code_highlighter" code_type="Sql" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false" style="border: #666666 1px dotted; border-left: #22aaee 5px solid; padding: 5px; background: #FAFAFA url(modules/editor/components/code_highlighter/code.png) no-repeat top right;">select * from abcd where code='20034'</div>

<p>Oracle executes this query using&nbsp;index scan&nbsp;(indicated as&nbsp;<b>INDEX UNIQUE SCAN</b>). Implicit type conversion does not take place.</p>

<div editor_component="code_highlighter" code_type="Bash" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false" style="border: #666666 1px dotted; border-left: #22aaee 5px solid; padding: 5px; background: #FAFAFA url(modules/editor/components/code_highlighter/code.png) no-repeat top right;">
PLAN_TABLE_OUTPUT
-------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT            |             |     1 |    19 |     1   (0)| 00:00:01 |
|   1 |  TABLE ACCESS BY INDEX ROWID| ABCD        |     1 |    19 |     1   (0)| 00:00:01 |
|*  2 |   INDEX UNIQUE SCAN         | SYS_C003835 |     1 |       |     1   (0)| 00:00:01 |
-------------------------------------------------------------------------------------------
</div>

<p>As a result we can confirm that Oracle does implicitly type conversion, however does not perform index scanning in both cases. If PK is defined as a character and integer is used to scan the records, Oracle will perform full table scan.</p>

<h2>MySQL</h2>

<p>For MySQL also we will create an identical table and perform the test.</p><h3>INTEGER PRIMARY KEY</h3><p>Let's see how MySQL performs if a table PK is of INT type which is a general case.</p>

<div editor_component="code_highlighter" code_type="Sql" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false" style="border: #666666 1px dotted; border-left: #22aaee 5px solid; padding: 5px; background: #FAFAFA url(modules/editor/components/code_highlighter/code.png) no-repeat top right;">
CREATE TABLE "event"(
    "code" int,
    "sports" char(50),
    "name" char(50),
    "gender" char(1),
    "players" int,
    CONSTRAINT pk_event_code PRIMARY KEY("code")
);
</div>

<h4>INTEGER in WHERE condition</h4><p>We will execute the following query with an INT value used in the WHERE clause.</p>

<div editor_component="code_highlighter" code_type="Sql" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false" style="border: #666666 1px dotted; border-left: #22aaee 5px solid; padding: 5px; background: #FAFAFA url(modules/editor/components/code_highlighter/code.png) no-repeat top right;">select * from event where code=20034</div>

<p>MySQL successfully executes this query using&nbsp;index scan (indicated as <b>PRIMARY</b>).</p>

<div editor_component="code_highlighter" code_type="Sql" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false" style="border: #666666 1px dotted; border-left: #22aaee 5px solid; padding: 5px; background: #FAFAFA url(modules/editor/components/code_highlighter/code.png) no-repeat top right;">
+----+-------------+-------+-------+---------------+---------+---------+-------+------+-------+
| id | select_type | table | type  | possible_keys | key     | key_len | ref   | rows | Extra |
+----+-------------+-------+-------+---------------+---------+---------+-------+------+-------+
|  1 | SIMPLE      | event | const | PRIMARY       | PRIMARY | 4       | const |    1 |       |
+----+-------------+-------+-------+---------------+---------+---------+-------+------+-------+
</div>

<h4>CHAR in WHERE condition</h4>

<p>Now we will execute the same query but will pass CHAR value to <b>code</b>&nbsp;in the WHERE clause.</p>

<div editor_component="code_highlighter" code_type="Sql" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false" style="border: #666666 1px dotted; border-left: #22aaee 5px solid; padding: 5px; background: #FAFAFA url(modules/editor/components/code_highlighter/code.png) no-repeat top right;">select * from event where code='20034'</div>

<p>MySQL again successfully executes this query using&nbsp;index scan&nbsp;(indicated as&nbsp;<b>PRIMARY</b>). In this case implicit type conversion takes place.</p>

<div editor_component="code_highlighter" code_type="Sql" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false" style="border: #666666 1px dotted; border-left: #22aaee 5px solid; padding: 5px; background: #FAFAFA url(modules/editor/components/code_highlighter/code.png) no-repeat top right;">
+----+-------------+-------+-------+---------------+---------+---------+-------+------+-------+
| id | select_type | table | type  | possible_keys | key     | key_len | ref   | rows | Extra |
+----+-------------+-------+-------+---------------+---------+---------+-------+------+-------+
|  1 | SIMPLE      | event | const | PRIMARY       | PRIMARY | 4       | const |    1 |       |
+----+-------------+-------+-------+---------------+---------+---------+-------+------+-------+
</div>

<h3>CHAR PRIMARY KEY</h3><p>Let's see how MySQL performs if a table PK is of CHAR type.</p>

<div editor_component="code_highlighter" code_type="Sql" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false" style="border: #666666 1px dotted; border-left: #22aaee 5px solid; padding: 5px; background: #FAFAFA url(modules/editor/components/code_highlighter/code.png) no-repeat top right;">
CREATE TABLE "abcd" (
    "code" char(3),
    "name" char(40) NOT NULL,
    "continent" char(10),
    "capital" char(30),
    CONSTRAINT pk_nation_code PRIMARY KEY("code")
);
</div>

<h4>INTEGER in WHERE condition</h4><p>We will execute the following query with an INT value used in the WHERE clause.</p>

<div editor_component="code_highlighter" code_type="Sql" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false" style="border: #666666 1px dotted; border-left: #22aaee 5px solid; padding: 5px; background: #FAFAFA url(modules/editor/components/code_highlighter/code.png) no-repeat top right;">select * from abcd where code=20034</div>

<p>Just like Oracle, MySQL performs implicit type conversion but runs the query through <b>full table scan</b>.&nbsp;Looking at the below query plan, we can confirm that if condition is expressed using integer type while the actual column type is character, then full scan is used.</p>

<div editor_component="code_highlighter" code_type="Sql" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false" style="border: #666666 1px dotted; border-left: #22aaee 5px solid; padding: 5px; background: #FAFAFA url(modules/editor/components/code_highlighter/code.png) no-repeat top right;">
+----+-------------+-------+------+---------------+------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key  | key_len | ref  | rows | Extra       |
+----+-------------+-------+------+---------------+------+---------+------+------+-------------+
|  1 | SIMPLE      | abcd  | ALL  | PRIMARY       | NULL | NULL    | NULL |  324 | Using where |
+----+-------------+-------+------+---------------+------+---------+------+------+-------------+
</div>

<h4>CHAR in WHERE condition</h4>

<p>Now we will execute the same query but will pass CHAR value to <b>code</b>&nbsp;in the WHERE clause.</p>

<div editor_component="code_highlighter" code_type="Sql" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false" style="border: #666666 1px dotted; border-left: #22aaee 5px solid; padding: 5px; background: #FAFAFA url(modules/editor/components/code_highlighter/code.png) no-repeat top right;">select * from abcd where code='20034'</div>

<p>MySQL again successfully executes this query using&nbsp;index scan&nbsp;(indicated as&nbsp;<b>PRIMARY</b>).&nbsp;Implicit type conversion does not take place.</p>

<div editor_component="code_highlighter" code_type="Sql" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false" style="border: #666666 1px dotted; border-left: #22aaee 5px solid; padding: 5px; background: #FAFAFA url(modules/editor/components/code_highlighter/code.png) no-repeat top right;">
+----+-------------+-------+-------+---------------+---------+---------+-------+------+-------+
| id | select_type | table | type  | possible_keys | key     | key_len | ref   | rows | Extra |
+----+-------------+-------+-------+---------------+---------+---------+-------+------+-------+
|  1 | SIMPLE      | abcd  | const | PRIMARY       | PRIMARY | 15      | const |    1 |       |
+----+-------------+-------+-------+---------------+---------+---------+-------+------+-------+
</div>

<p>As a result we can confirm that MySQL, like all these DBMSs, does implicitly type conversion, however, like Oracle, does not perform index scanning in both cases. If PK is defined as a character and integer is used to scan the records, Oracle will perform full table scan.</p>

<h2>CUBRID</h2>

<p>Now let's see at how CUBRID performs implicit type conversion and if index scan is used in all cases.</p><h3>INTEGER PRIMARY KEY</h3><p>Here is a table where PK is of INT type (general case).</p>

<div editor_component="code_highlighter" code_type="Sql" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false" style="border: #666666 1px dotted; border-left: #22aaee 5px solid; padding: 5px; background: #FAFAFA url(modules/editor/components/code_highlighter/code.png) no-repeat top right;">
CREATE TABLE "event"(
    "code" int,
    "sports" char(50),
    "name" char(50),
    "gender" char(1),
    "players" int,
    CONSTRAINT pk_event_code PRIMARY KEY("code")
);
</div>

<h4>INTEGER in WHERE condition</h4><p>We will execute the following query with an INT value used in the WHERE clause.</p>

<div editor_component="code_highlighter" code_type="Sql" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false" style="border: #666666 1px dotted; border-left: #22aaee 5px solid; padding: 5px; background: #FAFAFA url(modules/editor/components/code_highlighter/code.png) no-repeat top right;">select * from event where code=20034</div>

<p>CUBRID successfully executes this query using&nbsp;index scan (<span class="Apple-style-span" style="font-family: Arial, sans-serif; "><b>pk_event_code </b>primary key column is used)</span>.</p>

<div editor_component="code_highlighter" code_type="Sql" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false" style="border: #666666 1px dotted; border-left: #22aaee 5px solid; padding: 5px; background: #FAFAFA url(modules/editor/components/code_highlighter/code.png) no-repeat top right;">
iscan
    class: event node[0]
    index: pk_event_code term[0]
    cost:  fixed 0(0.0/0.0) var 0(0.0/0.0) card 1
</div>

<h4>CHAR in WHERE condition</h4>

<p>Now we will execute the same query but will pass CHAR value to <b>code</b>&nbsp;in the WHERE clause.</p>

<div editor_component="code_highlighter" code_type="Sql" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false" style="border: #666666 1px dotted; border-left: #22aaee 5px solid; padding: 5px; background: #FAFAFA url(modules/editor/components/code_highlighter/code.png) no-repeat top right;">select * from event where code='20034'</div>

<p>CUBRID again successfully executes this query using&nbsp;index scan&nbsp;(<span class="Apple-style-span" style="font-family: Arial, sans-serif; "><b>pk_event_code </b>primary key column is used).</span>&nbsp;Also implicit type conversion takes place.</p>

<div editor_component="code_highlighter" code_type="Sql" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false" style="border: #666666 1px dotted; border-left: #22aaee 5px solid; padding: 5px; background: #FAFAFA url(modules/editor/components/code_highlighter/code.png) no-repeat top right;">
iscan
    class: event node[0]
    index: pk_event_code term[0]
    cost:  fixed 0(0.0/0.0) var 0(0.0/0.0) card 1
</div>

<h3>CHAR PRIMARY KEY</h3><p>Let's see how MSSQL performs if a table PK is of CHAR type.</p>

<div editor_component="code_highlighter" code_type="Sql" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false" style="border: #666666 1px dotted; border-left: #22aaee 5px solid; padding: 5px; background: #FAFAFA url(modules/editor/components/code_highlighter/code.png) no-repeat top right;">
CREATE TABLE "abcd" (
    "code" char(3),
    "name" char(40) NOT NULL,
    "continent" char(10),
    "capital" char(30),
    CONSTRAINT pk_nation_code PRIMARY KEY("code")
);
</div>

<h4>INTEGER in WHERE condition</h4><p>We will execute the following query with an INT value used in the WHERE clause.</p>

<div editor_component="code_highlighter" code_type="Sql" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false" style="border: #666666 1px dotted; border-left: #22aaee 5px solid; padding: 5px; background: #FAFAFA url(modules/editor/components/code_highlighter/code.png) no-repeat top right;">select * from abcd where code=20034</div>

<p>In this case, CUBRID performs more like MSSQL, rather than Oracle or MySQL. By executing the above SQL we can confirm that CUBRID performs index scan&nbsp;(<span class="Apple-style-span" style="font-family: Arial, sans-serif; "><b>pk_abcd_code&nbsp;</b>primary key column is used)</span>&nbsp;even if the condition clause contains mismatching data types. It will automatically convert to a data type used by the primary key column.</p>

<div editor_component="code_highlighter" code_type="Sql" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false" style="border: #666666 1px dotted; border-left: #22aaee 5px solid; padding: 5px; background: #FAFAFA url(modules/editor/components/code_highlighter/code.png) no-repeat top right;">
iscan
    class: abcd node[0]
    index: pk_abcd_code term[0]
    cost:  fixed 0(0.0/0.0) var 0(0.0/0.0) card 1
</div>

<h4>CHAR in WHERE condition</h4>

<p>Now we will execute the same query but will pass CHAR value to <b>code</b>&nbsp;in the WHERE clause.</p>

<div editor_component="code_highlighter" code_type="Sql" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false" style="border: #666666 1px dotted; border-left: #22aaee 5px solid; padding: 5px; background: #FAFAFA url(modules/editor/components/code_highlighter/code.png) no-repeat top right;">select * from abcd where code='20034'</div>

<p>CUBRID again successfully executes this query using&nbsp;index scan&nbsp;(<span class="Apple-style-span" style="font-family: Arial, sans-serif; "><b>pk_abcd_code&nbsp;</b>primary key column is used)</span>.&nbsp;Implicit type conversion does not take place.</p>

<div editor_component="code_highlighter" code_type="Sql" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false" style="border: #666666 1px dotted; border-left: #22aaee 5px solid; padding: 5px; background: #FAFAFA url(modules/editor/components/code_highlighter/code.png) no-repeat top right;">
iscan
    class: abcd node[0]
    index: pk_abcd_code term[0]
    cost:  fixed 0(0.0/0.0) var 0(0.0/0.0) card 1
</div>

<p>In other words, like MSSQL, in both cases CUBRID implicitly converts the types, and performs index scanning.</p>

<h2>Conclusion</h2>

<p>Let's see in a concise table how these databases compare with each other based on the above test results. The check mark below means that that DBMS uses index scan rather than full table scan.</p>

<table class="blackcap rowbg">
<thead>
<tr>
	<td></td>
	<td>Oracle</td>
	<td>MSSQL</td>
	<td>MySQL</td>
	<td>CUBRID</td>
</tr>
</thead>
<tbody>
<tr>
	<td>If a column, defined as an INTEGER, is scanned using a CHARACTER value.</td>
	<td style="text-align:center"><img src="http://www.cubrid.org/files/attach/images/49/700/203/check.png" alt="check.png" width="16" height="15" editor_component="image_link"/>
<br /></td>
	<td style="text-align:center"><img src="http://www.cubrid.org/files/attach/images/49/700/203/check.png" alt="check.png" width="16" height="15" editor_component="image_link"/>
<br /></td>
	<td style="text-align:center"><img src="http://www.cubrid.org/files/attach/images/49/700/203/check.png" alt="check.png" width="16" height="15" editor_component="image_link"/>
<br /></td>
	<td style="text-align:center"><img src="http://www.cubrid.org/files/attach/images/49/700/203/check.png" alt="check.png" width="16" height="15" editor_component="image_link"/>
<br /></td>
</tr>
<tr>
	<td>If a column, defined as a CHARACTER, is scanned using a INTEGER value.</td>
	<td style="text-align:center"><img src="http://www.cubrid.org/files/attach/images/49/700/203/cross.png" alt="cross.png" width="15" height="15" editor_component="image_link"/>
<br /></td>
	<td style="text-align:center"><img src="http://www.cubrid.org/files/attach/images/49/700/203/check.png" alt="check.png" width="16" height="15" editor_component="image_link"/>
<br /></td>
	<td style="text-align:center"><img src="http://www.cubrid.org/files/attach/images/49/700/203/cross.png" alt="cross.png" width="15" height="15" editor_component="image_link"/>
<br /></td>
	<td style="text-align:center"><img src="http://www.cubrid.org/files/attach/images/49/700/203/check.png" alt="check.png" width="16" height="15" editor_component="image_link"/>
<br /></td>
</tr>
</tbody>
</table>

<h2>Additional Links</h2>

<p></p><ul><li><a href="http://sourceforge.net/apps/trac/cubrid/wiki/UserDocumentation/SqlExtension2/ImplicitTypeConversion" target="_self">Implicit Type Conversion Spec</a></li></ul><p></p>]]></description>
                        <pubDate>Thu, 11 Aug 2011 10:06:32 -0800</pubDate>
                        <category>MSSQL</category>
                        <category>Oracle</category>
                        <category>MySQL</category>
                        <category>data type</category>
                                </item>
            </channel>
</rss>
