forked from docs/doc-exports
Reviewed-by: Hasko, Vladimir <vladimir.hasko@t-systems.com> Co-authored-by: Lu, Huayi <luhuayi@huawei.com> Co-committed-by: Lu, Huayi <luhuayi@huawei.com>
170 lines
35 KiB
HTML
170 lines
35 KiB
HTML
<a name="EN-US_TOPIC_0000001145710655"></a><a name="EN-US_TOPIC_0000001145710655"></a>
|
|
|
|
<h1 class="topictitle1">UNION, CASE, and Related Constructs</h1>
|
|
<div id="body8662426"><p id="EN-US_TOPIC_0000001145710655__en-us_topic_0059779260_p269514716590">SQL UNION constructs must match up possibly dissimilar types to become a single result set. Since all query results from a <strong id="EN-US_TOPIC_0000001145710655__b2085485204813">SELECT UNION</strong> statement must appear in a single set of columns, the types of the results of each <strong id="EN-US_TOPIC_0000001145710655__b985416528488">SELECT</strong> clause must be matched up and converted to a uniform set. Similarly, the result expressions of a <strong id="EN-US_TOPIC_0000001145710655__b119172437497">CASE</strong> construct must be converted to a common type so that the <strong id="EN-US_TOPIC_0000001145710655__b19179439498">CASE</strong> expression as a whole has a known output type. The same holds for <strong id="EN-US_TOPIC_0000001145710655__b10868164912498">ARRAY</strong> constructs, and for the <strong id="EN-US_TOPIC_0000001145710655__b1086874913498">GREATEST</strong> and <strong id="EN-US_TOPIC_0000001145710655__b16868949144919">LEAST</strong> functions.</p>
|
|
<div class="section" id="EN-US_TOPIC_0000001145710655__s5c81516e10974f338b4b7d772d38f497"><h4 class="sectiontitle">Type Resolution for UNION, CASE, and Related Constructs</h4><ul id="EN-US_TOPIC_0000001145710655__u7d71a8ec8a4e4cd49be14956f188a959"><li id="EN-US_TOPIC_0000001145710655__l57f75649247c4f549873fd156157b8cc">If all inputs are of the same type, and it is not unknown, resolve as that type.</li><li id="EN-US_TOPIC_0000001145710655__la0d1d70a218b4404b7271bcaf313075c">If all inputs are of type <strong id="EN-US_TOPIC_0000001145710655__b84235270692017">unknown</strong>, resolve as type <strong id="EN-US_TOPIC_0000001145710655__b84235270692024">text</strong> (the preferred type of the string category). Otherwise, <strong id="EN-US_TOPIC_0000001145710655__b84235270692044">unknown</strong> inputs are ignored.</li><li id="EN-US_TOPIC_0000001145710655__lce61619a8b6b4625b83cef42fce78007">If the non-unknown inputs are not all of the same type category, fail. (Type <strong id="EN-US_TOPIC_0000001145710655__b84235270610386">unknown</strong> is not included.)</li><li id="EN-US_TOPIC_0000001145710655__la1cbb755423441f29b266716414b9875">If the non-unknown inputs are all of the same type category, choose the first non-unknown input type which is a preferred type in that category, if there is one. (Exception: The UNION operation regards the type of the first branch as the selected type.)<div class="note" id="EN-US_TOPIC_0000001145710655__n48be18a738e1417baf129c38c36671e2"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="EN-US_TOPIC_0000001145710655__acd09fdbd7dbb48fd9c16e6fe33fe54cc"><strong id="EN-US_TOPIC_0000001145710655__b842352706171247">typcategory</strong> in the <strong id="EN-US_TOPIC_0000001145710655__b842352706171237">pg_type</strong> system catalog indicates the data type category. <strong id="EN-US_TOPIC_0000001145710655__b84235270617134">typispreferred</strong> indicates whether a type is preferred in <strong id="EN-US_TOPIC_0000001145710655__b842352706171348">typcategory</strong>.</p>
|
|
</div></div>
|
|
</li><li id="EN-US_TOPIC_0000001145710655__la520dfab50e441e4b8cd81def938de73">All the input is converted to the selected type. (The original length of a string is retained). Fail if there is not an implicit conversion from a given input to the selected type.</li><li id="EN-US_TOPIC_0000001145710655__li17401536195716">If the input contains the json, txid_snapshot, sys_refcursor, or geometry type, <strong id="EN-US_TOPIC_0000001145710655__b3356338519">UNION</strong> cannot be performed.</li></ul>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001145710655__s6c7bfb5b733c473bbdc05fb34f856021"><h4 class="sectiontitle">Type Resolution for CASE, COALESCE, IF, and IFNULL in TD-Compatible Mode</h4><ul id="EN-US_TOPIC_0000001145710655__uc41f3b659cfa40c59e8397fca7f459cf"><li id="EN-US_TOPIC_0000001145710655__l33cf764b60a04d6db5003c59bead82a8">If all inputs are of the same type, and it is not unknown, resolve as that type.</li><li id="EN-US_TOPIC_0000001145710655__l98abad52c35d4aab8c48a106aa53dcf8">If all inputs are of type <strong id="EN-US_TOPIC_0000001145710655__b71365099919436">unknown</strong>, resolve as type <strong id="EN-US_TOPIC_0000001145710655__b87930857019436">text</strong>.</li><li id="EN-US_TOPIC_0000001145710655__l923249e8d12840659a1c9ca94503359e">If inputs are of string type (including <strong id="EN-US_TOPIC_0000001145710655__b842352706192652">unknown</strong> which is resolved as type <strong id="EN-US_TOPIC_0000001145710655__b842352706192729">text</strong>) and digit type, resolve as the string type. If the inputs are not of the two types, fail.</li><li id="EN-US_TOPIC_0000001145710655__l0561594b643746ea9ff7b49265fe4f21">If the non-unknown inputs are all of the same type category, choose the input type which is a preferred type in that category, if there is one.</li><li id="EN-US_TOPIC_0000001145710655__lb761861c355247109ca3b81846417cde">Convert all inputs to the selected type. Fail if there is not an implicit conversion from a given input to the selected type.</li></ul>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001145710655__section1421264504414"><h4 class="sectiontitle">Type Resolution for CASE, COALESCE, IF, and IFNULL in MySQL-Compatible Mode</h4><ul id="EN-US_TOPIC_0000001145710655__ul219416462448"><li id="EN-US_TOPIC_0000001145710655__li41947466445">If all inputs are of the same type, and it is not unknown, resolve as that type.</li><li id="EN-US_TOPIC_0000001145710655__li1919414614446">If all inputs are of type <strong id="EN-US_TOPIC_0000001145710655__b1979168311">unknown</strong>, resolve as type <strong id="EN-US_TOPIC_0000001145710655__b1898010069">text</strong>.</li><li id="EN-US_TOPIC_0000001145710655__li998614192154">If some inputs are of type <strong id="EN-US_TOPIC_0000001145710655__b56046393912">unknown</strong> and the others are of a non-<strong id="EN-US_TOPIC_0000001145710655__b09617174224">unknown</strong> type, resolve as that non-<strong id="EN-US_TOPIC_0000001145710655__b059572202219">unknown</strong> type.</li><li id="EN-US_TOPIC_0000001145710655__li4277512162016">If the inputs are of different non-<strong id="EN-US_TOPIC_0000001145710655__b195101231112212">unknown</strong> types, treat type <strong id="EN-US_TOPIC_0000001145710655__b4438106143513">enum</strong> as type <strong id="EN-US_TOPIC_0000001145710655__b14396429153517">text</strong> for comparison.</li><li id="EN-US_TOPIC_0000001145710655__li19194204614416">If the non-<strong id="EN-US_TOPIC_0000001145710655__b1720813520223">unknown</strong> inputs are all of the same type, choose a preferred type, if there is one. If the inputs are of different types, resolve as type <strong id="EN-US_TOPIC_0000001145710655__b118295527412">text</strong>.</li><li id="EN-US_TOPIC_0000001145710655__li181941146154418">Convert all inputs to the selected type. Fail if there is not an implicit conversion from a given input to the selected type.</li></ul>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001145710655__s64d7c742a50c4e00b2291bb2117d754e"><h4 class="sectiontitle">Examples</h4><p id="EN-US_TOPIC_0000001145710655__a987902d9630d45b1b58f0d4dd02acdfe">Example 1: Use type resolution with unknown types in a union as the first example. Here, the unknown-type literal <strong id="EN-US_TOPIC_0000001145710655__b8423527069274">'b'</strong> will be resolved to type <strong id="EN-US_TOPIC_0000001145710655__b849015142115">text</strong>.</p>
|
|
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001145710655__s1512f3e03cdb4cc4b6bf521ea25f5a29"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span>
|
|
<span class="normal">2</span>
|
|
<span class="normal">3</span>
|
|
<span class="normal">4</span>
|
|
<span class="normal">5</span>
|
|
<span class="normal">6</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">SELECT</span><span class="w"> </span><span class="nb">text</span><span class="w"> </span><span class="s1">'a'</span><span class="w"> </span><span class="k">AS</span><span class="w"> </span><span class="ss">"text"</span><span class="w"> </span><span class="k">UNION</span><span class="w"> </span><span class="k">SELECT</span><span class="w"> </span><span class="s1">'b'</span><span class="p">;</span><span class="w"></span>
|
|
<span class="w"> </span><span class="nb">text</span><span class="w"></span>
|
|
<span class="c1">------</span>
|
|
<span class="w"> </span><span class="n">a</span><span class="w"></span>
|
|
<span class="w"> </span><span class="n">b</span><span class="w"></span>
|
|
<span class="p">(</span><span class="mi">2</span><span class="w"> </span><span class="k">rows</span><span class="p">)</span><span class="w"></span>
|
|
</pre></div></td></tr></table></div>
|
|
|
|
</div>
|
|
<p id="EN-US_TOPIC_0000001145710655__ad5df48e6c8ae4455830eaf089e388206">Example 2: Use type resolution in a simple union as the second example. The literal <strong id="EN-US_TOPIC_0000001145710655__b84235270692828">1.2</strong> is of type <strong id="EN-US_TOPIC_0000001145710655__b84235270692840">numeric</strong>, and the <strong id="EN-US_TOPIC_0000001145710655__b84235270692845">integer</strong> value <strong id="EN-US_TOPIC_0000001145710655__b84235270692851">1</strong> can be cast implicitly to <strong id="EN-US_TOPIC_0000001145710655__b84235270692857">numeric</strong>, so that type is used.</p>
|
|
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001145710655__sa5d4159da4114e189cc601710930416a"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span>
|
|
<span class="normal">2</span>
|
|
<span class="normal">3</span>
|
|
<span class="normal">4</span>
|
|
<span class="normal">5</span>
|
|
<span class="normal">6</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">SELECT</span><span class="w"> </span><span class="mi">1</span><span class="p">.</span><span class="mi">2</span><span class="w"> </span><span class="k">AS</span><span class="w"> </span><span class="ss">"numeric"</span><span class="w"> </span><span class="k">UNION</span><span class="w"> </span><span class="k">SELECT</span><span class="w"> </span><span class="mi">1</span><span class="p">;</span><span class="w"></span>
|
|
<span class="w"> </span><span class="nb">numeric</span><span class="w"></span>
|
|
<span class="c1">---------</span>
|
|
<span class="w"> </span><span class="mi">1</span><span class="w"></span>
|
|
<span class="w"> </span><span class="mi">1</span><span class="p">.</span><span class="mi">2</span><span class="w"></span>
|
|
<span class="p">(</span><span class="mi">2</span><span class="w"> </span><span class="k">rows</span><span class="p">)</span><span class="w"></span>
|
|
</pre></div></td></tr></table></div>
|
|
|
|
</div>
|
|
<p id="EN-US_TOPIC_0000001145710655__a5b259cdb95a34ef58a4a66583ce09ea5">Example 3: Use type resolution in a transposed union as the third example. Here, since type <strong id="EN-US_TOPIC_0000001145710655__b6758340119">real</strong> cannot be implicitly cast to <strong id="EN-US_TOPIC_0000001145710655__b5710642015">integer</strong>, but <strong id="EN-US_TOPIC_0000001145710655__b15924194510120">integer</strong> can be implicitly cast to <strong id="EN-US_TOPIC_0000001145710655__b89196476111">real</strong>, the union result type is resolved as <strong id="EN-US_TOPIC_0000001145710655__b150511501918">real</strong>.</p>
|
|
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001145710655__s6bd7cbf9528b49368b7f1db40a75e970"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span>
|
|
<span class="normal">2</span>
|
|
<span class="normal">3</span>
|
|
<span class="normal">4</span>
|
|
<span class="normal">5</span>
|
|
<span class="normal">6</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">SELECT</span><span class="w"> </span><span class="mi">1</span><span class="w"> </span><span class="k">AS</span><span class="w"> </span><span class="ss">"real"</span><span class="w"> </span><span class="k">UNION</span><span class="w"> </span><span class="k">SELECT</span><span class="w"> </span><span class="k">CAST</span><span class="p">(</span><span class="s1">'2.2'</span><span class="w"> </span><span class="k">AS</span><span class="w"> </span><span class="nb">REAL</span><span class="p">);</span><span class="w"></span>
|
|
<span class="w"> </span><span class="nb">real</span><span class="w"></span>
|
|
<span class="c1">------</span>
|
|
<span class="w"> </span><span class="mi">1</span><span class="w"></span>
|
|
<span class="w"> </span><span class="mi">2</span><span class="p">.</span><span class="mi">2</span><span class="w"></span>
|
|
<span class="p">(</span><span class="mi">2</span><span class="w"> </span><span class="k">rows</span><span class="p">)</span><span class="w"></span>
|
|
</pre></div></td></tr></table></div>
|
|
|
|
</div>
|
|
<p id="EN-US_TOPIC_0000001145710655__p6335859183416">Example 4: Use type resolution in the <strong id="EN-US_TOPIC_0000001145710655__b0426144292512">COALESCE</strong> function with input values of types <strong id="EN-US_TOPIC_0000001145710655__b129251415112618">int</strong> and <strong id="EN-US_TOPIC_0000001145710655__b59210594255">varchar</strong> as the fourth example. Type resolution fails in ORA-compatible mode. The types are resolved as type <strong id="EN-US_TOPIC_0000001145710655__b1010416118296">varchar</strong> in TD-compatible mode, and as type <strong id="EN-US_TOPIC_0000001145710655__b248191320294">text</strong> in MySQL-compatible mode.</p>
|
|
<p id="EN-US_TOPIC_0000001145710655__p118171040144114">Create the <strong id="EN-US_TOPIC_0000001145710655__b1780324214549">ora_db</strong>, <strong id="EN-US_TOPIC_0000001145710655__b58041342185416">td_db</strong>, and <strong id="EN-US_TOPIC_0000001145710655__b38041422542">mysql_db</strong> databases by setting <strong id="EN-US_TOPIC_0000001145710655__b1080424265412">dbcompatibility</strong> to <strong id="EN-US_TOPIC_0000001145710655__b208041742165413">ORA</strong>, <strong id="EN-US_TOPIC_0000001145710655__b38054427543">TD</strong>, and <strong id="EN-US_TOPIC_0000001145710655__b2805154210544">MySQL</strong>, respectively.</p>
|
|
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001145710655__screen7345854215"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span>
|
|
<span class="normal">2</span>
|
|
<span class="normal">3</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">CREATE</span><span class="w"> </span><span class="k">DATABASE</span><span class="w"> </span><span class="n">ora_db</span><span class="w"> </span><span class="n">dbcompatibility</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'ORA'</span><span class="p">;</span><span class="w"></span>
|
|
<span class="k">CREATE</span><span class="w"> </span><span class="k">DATABASE</span><span class="w"> </span><span class="n">td_db</span><span class="w"> </span><span class="n">dbcompatibility</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'TD'</span><span class="p">;</span><span class="w"></span>
|
|
<span class="k">CREATE</span><span class="w"> </span><span class="k">DATABASE</span><span class="w"> </span><span class="n">mysql_db</span><span class="w"> </span><span class="n">dbcompatibility</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'MySQL'</span><span class="p">;</span><span class="w"></span>
|
|
</pre></div></td></tr></table></div>
|
|
|
|
</div>
|
|
<ul id="EN-US_TOPIC_0000001145710655__ul9424133414441"><li id="EN-US_TOPIC_0000001145710655__li9424113415445">Switch to the <strong id="EN-US_TOPIC_0000001145710655__b4372845510">ora_db</strong> database.<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001145710655__screen8950145915423"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><span class="n">gaussdb</span><span class="o">=#</span><span class="w"> </span><span class="err">\</span><span class="k">c</span><span class="w"> </span><span class="n">ora_db</span><span class="w"></span>
|
|
</pre></div></td></tr></table></div>
|
|
|
|
</div>
|
|
<p id="EN-US_TOPIC_0000001145710655__p989292119421">Create table <strong id="EN-US_TOPIC_0000001145710655__b1774713482553">t1</strong>. Show the execution plan of a statement for querying the types <strong id="EN-US_TOPIC_0000001145710655__b4778193295518">int</strong> and <strong id="EN-US_TOPIC_0000001145710655__b777853216557">varchar</strong> of input parameters for <strong id="EN-US_TOPIC_0000001145710655__b1877963220551">COALESCE</strong>.</p>
|
|
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001145710655__screen141793814417"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span>
|
|
<span class="normal">2</span>
|
|
<span class="normal">3</span>
|
|
<span class="normal">4</span></pre></div></td><td class="code"><div><pre><span></span><span class="n">ora_db</span><span class="o">=#</span><span class="w"> </span><span class="k">CREATE</span><span class="w"> </span><span class="k">TABLE</span><span class="w"> </span><span class="n">t1</span><span class="p">(</span><span class="n">a</span><span class="w"> </span><span class="nb">int</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="w"> </span><span class="nb">varchar</span><span class="p">(</span><span class="mi">10</span><span class="p">));</span><span class="w"> </span>
|
|
<span class="n">ora_db</span><span class="o">=#</span><span class="w"> </span><span class="k">EXPLAIN</span><span class="w"> </span><span class="k">SELECT</span><span class="w"> </span><span class="k">coalesce</span><span class="p">(</span><span class="n">a</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">)</span><span class="w"> </span><span class="k">FROM</span><span class="w"> </span><span class="n">t1</span><span class="p">;</span><span class="w"></span>
|
|
<span class="n">ERROR</span><span class="p">:</span><span class="w"> </span><span class="k">COALESCE</span><span class="w"> </span><span class="n">types</span><span class="w"> </span><span class="nb">integer</span><span class="w"> </span><span class="k">and</span><span class="w"> </span><span class="nb">character</span><span class="w"> </span><span class="nb">varying</span><span class="w"> </span><span class="n">cannot</span><span class="w"> </span><span class="n">be</span><span class="w"> </span><span class="n">matched</span><span class="w"></span>
|
|
<span class="n">CONTEXT</span><span class="p">:</span><span class="w"> </span><span class="n">referenced</span><span class="w"> </span><span class="k">column</span><span class="p">:</span><span class="w"> </span><span class="k">coalesce</span><span class="w"></span>
|
|
</pre></div></td></tr></table></div>
|
|
|
|
</div>
|
|
</li><li id="EN-US_TOPIC_0000001145710655__li116850487442">Switch to the <strong id="EN-US_TOPIC_0000001145710655__b11931554135512">td_db</strong> database.<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001145710655__screen8972105518456"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><span class="n">ora_db</span><span class="o">=#</span><span class="w"> </span><span class="err">\</span><span class="k">c</span><span class="w"> </span><span class="n">td_db</span><span class="w"></span>
|
|
</pre></div></td></tr></table></div>
|
|
|
|
</div>
|
|
<p id="EN-US_TOPIC_0000001145710655__p1032215591451">Create table <strong id="EN-US_TOPIC_0000001145710655__b434435811553">t2</strong>. Show the execution plan of a statement for querying the types <strong id="EN-US_TOPIC_0000001145710655__b73441558175510">int</strong> and <strong id="EN-US_TOPIC_0000001145710655__b7344125865520">varchar</strong> of input parameters for <strong id="EN-US_TOPIC_0000001145710655__b6345185812555">COALESCE</strong>.</p>
|
|
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001145710655__screen196571634114615"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal"> 1</span>
|
|
<span class="normal"> 2</span>
|
|
<span class="normal"> 3</span>
|
|
<span class="normal"> 4</span>
|
|
<span class="normal"> 5</span>
|
|
<span class="normal"> 6</span>
|
|
<span class="normal"> 7</span>
|
|
<span class="normal"> 8</span>
|
|
<span class="normal"> 9</span>
|
|
<span class="normal">10</span>
|
|
<span class="normal">11</span>
|
|
<span class="normal">12</span>
|
|
<span class="normal">13</span>
|
|
<span class="normal">14</span>
|
|
<span class="normal">15</span></pre></div></td><td class="code"><div><pre><span></span><span class="n">td_db</span><span class="o">=#</span><span class="w"> </span><span class="k">CREATE</span><span class="w"> </span><span class="k">TABLE</span><span class="w"> </span><span class="n">t2</span><span class="p">(</span><span class="n">a</span><span class="w"> </span><span class="nb">int</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="w"> </span><span class="nb">varchar</span><span class="p">(</span><span class="mi">10</span><span class="p">));</span><span class="w"></span>
|
|
<span class="n">td_db</span><span class="o">=#</span><span class="w"> </span><span class="k">EXPLAIN</span><span class="w"> </span><span class="k">VERBOSE</span><span class="w"> </span><span class="k">select</span><span class="w"> </span><span class="k">coalesce</span><span class="p">(</span><span class="n">a</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">)</span><span class="w"> </span><span class="k">from</span><span class="w"> </span><span class="n">t2</span><span class="p">;</span><span class="w"></span>
|
|
<span class="w"> </span><span class="n">QUERY</span><span class="w"> </span><span class="n">PLAN</span><span class="w"></span>
|
|
<span class="c1">-----------------------------------------------------------------------------------------------</span>
|
|
<span class="w"> </span><span class="n">id</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">operation</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="n">E</span><span class="o">-</span><span class="k">rows</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="n">E</span><span class="o">-</span><span class="k">distinct</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="n">E</span><span class="o">-</span><span class="n">width</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="n">E</span><span class="o">-</span><span class="n">costs</span><span class="w"></span>
|
|
<span class="w"> </span><span class="c1">----+----------------------------------------------+--------+------------+---------+---------</span>
|
|
<span class="w"> </span><span class="mi">1</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="o">-></span><span class="w"> </span><span class="k">Data</span><span class="w"> </span><span class="n">Node</span><span class="w"> </span><span class="n">Scan</span><span class="w"> </span><span class="k">on</span><span class="w"> </span><span class="ss">"__REMOTE_FQS_QUERY__"</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="mi">0</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="mi">0</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="mi">0</span><span class="p">.</span><span class="mi">00</span><span class="w"></span>
|
|
|
|
<span class="w"> </span><span class="n">Targetlist</span><span class="w"> </span><span class="n">Information</span><span class="w"> </span><span class="p">(</span><span class="n">identified</span><span class="w"> </span><span class="k">by</span><span class="w"> </span><span class="n">plan</span><span class="w"> </span><span class="n">id</span><span class="p">)</span><span class="w"></span>
|
|
<span class="w"> </span><span class="c1">-------------------------------------------------------------------------------------------</span>
|
|
<span class="w"> </span><span class="mi">1</span><span class="w"> </span><span class="c1">--Data Node Scan on "__REMOTE_FQS_QUERY__"</span>
|
|
<span class="w"> </span><span class="k">Output</span><span class="p">:</span><span class="w"> </span><span class="p">(</span><span class="k">COALESCE</span><span class="p">((</span><span class="n">t2</span><span class="p">.</span><span class="n">a</span><span class="p">)::</span><span class="nb">character</span><span class="w"> </span><span class="nb">varying</span><span class="p">,</span><span class="w"> </span><span class="n">t2</span><span class="p">.</span><span class="n">b</span><span class="p">))</span><span class="w"></span>
|
|
<span class="w"> </span><span class="n">Node</span><span class="o">/</span><span class="n">s</span><span class="p">:</span><span class="w"> </span><span class="k">All</span><span class="w"> </span><span class="n">datanodes</span><span class="w"></span>
|
|
<span class="w"> </span><span class="n">Remote</span><span class="w"> </span><span class="n">query</span><span class="p">:</span><span class="w"> </span><span class="k">SELECT</span><span class="w"> </span><span class="k">COALESCE</span><span class="p">(</span><span class="n">a</span><span class="p">::</span><span class="nb">character</span><span class="w"> </span><span class="nb">varying</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">)</span><span class="w"> </span><span class="k">AS</span><span class="w"> </span><span class="ss">"coalesce"</span><span class="w"> </span><span class="k">FROM</span><span class="w"> </span><span class="k">public</span><span class="p">.</span><span class="n">t2</span><span class="w"></span>
|
|
<span class="p">(</span><span class="mi">10</span><span class="w"> </span><span class="k">rows</span><span class="p">)</span><span class="w"></span>
|
|
</pre></div></td></tr></table></div>
|
|
|
|
</div>
|
|
</li><li id="EN-US_TOPIC_0000001145710655__li18398134415463">Switch to the <strong id="EN-US_TOPIC_0000001145710655__b163941413105619">mysql_db</strong> database.<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001145710655__screen78311819499"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><span class="n">td_db</span><span class="o">=#</span><span class="w"> </span><span class="err">\</span><span class="k">c</span><span class="w"> </span><span class="n">mysql_db</span><span class="w"></span>
|
|
</pre></div></td></tr></table></div>
|
|
|
|
</div>
|
|
<p id="EN-US_TOPIC_0000001145710655__p20666812144913">Create table <strong id="EN-US_TOPIC_0000001145710655__b432451720567">t3</strong>. Show the execution plan of a statement for querying the types <strong id="EN-US_TOPIC_0000001145710655__b6324101720569">int</strong> and <strong id="EN-US_TOPIC_0000001145710655__b1532512172563">varchar</strong> of input parameters for <strong id="EN-US_TOPIC_0000001145710655__b43251717145611">COALESCE</strong>.</p>
|
|
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001145710655__screen1670155193519"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal"> 1</span>
|
|
<span class="normal"> 2</span>
|
|
<span class="normal"> 3</span>
|
|
<span class="normal"> 4</span>
|
|
<span class="normal"> 5</span>
|
|
<span class="normal"> 6</span>
|
|
<span class="normal"> 7</span>
|
|
<span class="normal"> 8</span>
|
|
<span class="normal"> 9</span>
|
|
<span class="normal">10</span>
|
|
<span class="normal">11</span>
|
|
<span class="normal">12</span>
|
|
<span class="normal">13</span>
|
|
<span class="normal">14</span>
|
|
<span class="normal">15</span></pre></div></td><td class="code"><div><pre><span></span><span class="n">mysql_db</span><span class="o">=#</span><span class="w"> </span><span class="k">CREATE</span><span class="w"> </span><span class="k">TABLE</span><span class="w"> </span><span class="n">t3</span><span class="p">(</span><span class="n">a</span><span class="w"> </span><span class="nb">int</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="w"> </span><span class="nb">varchar</span><span class="p">(</span><span class="mi">10</span><span class="p">));</span><span class="w"></span>
|
|
<span class="n">mysql_db</span><span class="o">=#</span><span class="w"> </span><span class="k">EXPLAIN</span><span class="w"> </span><span class="k">VERBOSE</span><span class="w"> </span><span class="k">select</span><span class="w"> </span><span class="k">coalesce</span><span class="p">(</span><span class="n">a</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">)</span><span class="w"> </span><span class="k">from</span><span class="w"> </span><span class="n">t3</span><span class="p">;</span><span class="w"></span>
|
|
<span class="w"> </span><span class="n">QUERY</span><span class="w"> </span><span class="n">PLAN</span><span class="w"></span>
|
|
<span class="c1">-----------------------------------------------------------------------------------------------</span>
|
|
<span class="w"> </span><span class="n">id</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">operation</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="n">E</span><span class="o">-</span><span class="k">rows</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="n">E</span><span class="o">-</span><span class="k">distinct</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="n">E</span><span class="o">-</span><span class="n">width</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="n">E</span><span class="o">-</span><span class="n">costs</span><span class="w"></span>
|
|
<span class="w"> </span><span class="c1">----+----------------------------------------------+--------+------------+---------+---------</span>
|
|
<span class="w"> </span><span class="mi">1</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="o">-></span><span class="w"> </span><span class="k">Data</span><span class="w"> </span><span class="n">Node</span><span class="w"> </span><span class="n">Scan</span><span class="w"> </span><span class="k">on</span><span class="w"> </span><span class="ss">"__REMOTE_FQS_QUERY__"</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="mi">0</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="mi">0</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="mi">0</span><span class="p">.</span><span class="mi">00</span><span class="w"></span>
|
|
|
|
<span class="w"> </span><span class="n">Targetlist</span><span class="w"> </span><span class="n">Information</span><span class="w"> </span><span class="p">(</span><span class="n">identified</span><span class="w"> </span><span class="k">by</span><span class="w"> </span><span class="n">plan</span><span class="w"> </span><span class="n">id</span><span class="p">)</span><span class="w"></span>
|
|
<span class="w"> </span><span class="c1">------------------------------------------------------------------------------------</span>
|
|
<span class="w"> </span><span class="mi">1</span><span class="w"> </span><span class="c1">--Data Node Scan on "__REMOTE_FQS_QUERY__"</span>
|
|
<span class="w"> </span><span class="k">Output</span><span class="p">:</span><span class="w"> </span><span class="p">(</span><span class="k">COALESCE</span><span class="p">((</span><span class="n">t3</span><span class="p">.</span><span class="n">a</span><span class="p">)::</span><span class="nb">text</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">t3</span><span class="p">.</span><span class="n">b</span><span class="p">)::</span><span class="nb">text</span><span class="p">))</span><span class="w"></span>
|
|
<span class="w"> </span><span class="n">Node</span><span class="o">/</span><span class="n">s</span><span class="p">:</span><span class="w"> </span><span class="k">All</span><span class="w"> </span><span class="n">datanodes</span><span class="w"></span>
|
|
<span class="w"> </span><span class="n">Remote</span><span class="w"> </span><span class="n">query</span><span class="p">:</span><span class="w"> </span><span class="k">SELECT</span><span class="w"> </span><span class="k">COALESCE</span><span class="p">(</span><span class="n">a</span><span class="p">::</span><span class="nb">text</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">::</span><span class="nb">text</span><span class="p">)</span><span class="w"> </span><span class="k">AS</span><span class="w"> </span><span class="ss">"coalesce"</span><span class="w"> </span><span class="k">FROM</span><span class="w"> </span><span class="k">public</span><span class="p">.</span><span class="n">t3</span><span class="w"></span>
|
|
<span class="p">(</span><span class="mi">10</span><span class="w"> </span><span class="k">rows</span><span class="p">)</span><span class="w"></span>
|
|
</pre></div></td></tr></table></div>
|
|
|
|
</div>
|
|
</li><li id="EN-US_TOPIC_0000001145710655__li15599353105112">Switch to the <strong id="EN-US_TOPIC_0000001145710655__b10971143110562"></strong><strong id="EN-US_TOPIC_0000001145710655__b209725318562"><span id="EN-US_TOPIC_0000001145710655__text19221236163811">gaussdb</span></strong> database.<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001145710655__screen5125101410502"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><span class="n">mysql_db</span><span class="o">=#</span><span class="w"> </span><span class="err">\</span><span class="k">c</span><span class="w"> </span><span class="n">gaussdb</span><span class="w"></span>
|
|
</pre></div></td></tr></table></div>
|
|
|
|
</div>
|
|
</li></ul>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="dws_06_0075.html">Type Conversion</a></div>
|
|
</div>
|
|
</div>
|
|
|