forked from docs/doc-exports
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>
33 lines
5.9 KiB
HTML
33 lines
5.9 KiB
HTML
<a name="EN-US_TOPIC_0000001188110532"></a><a name="EN-US_TOPIC_0000001188110532"></a>
|
|
|
|
<h1 class="topictitle1">EXECUTE DIRECT</h1>
|
|
<div id="body8662426"><div class="section" id="EN-US_TOPIC_0000001188110532__scb5938ca9b7c485ca021e0b798d0b9b6"><h4 class="sectiontitle">Function</h4><p id="EN-US_TOPIC_0000001188110532__a9c085daa06db4f36a477be962c5b7c06"><strong id="EN-US_TOPIC_0000001188110532__b585565489558_1">EXECUTE DIRECT</strong> executes an SQL statement on a specified node. Generally, the cluster automatically allocates an SQL statement to proper nodes. <strong id="EN-US_TOPIC_0000001188110532__b84235270683846">EXECUTE DIRECT</strong> is mainly used for database maintenance and testing.</p>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001188110532__s55bcbd7c04aa412cbb9a9f14d708b947"><h4 class="sectiontitle">Precautions</h4><ul id="EN-US_TOPIC_0000001188110532__ul79761746145217"><li id="EN-US_TOPIC_0000001188110532__li1745195132414">Only a system administrator can run the <strong id="EN-US_TOPIC_0000001188110532__b842352706114312">EXECUTE DIRECT</strong> statement.</li><li id="EN-US_TOPIC_0000001188110532__li16976124615220">To ensure data consistency across nodes, only the <strong id="EN-US_TOPIC_0000001188110532__b84235270683930">SELECT</strong> statement can be used. Transaction statements, DDL, and DML cannot be used.</li><li id="EN-US_TOPIC_0000001188110532__li156289576525">When the AVG aggregation calculation is performed on the specified DN using such statements, the result set is returned in array, for example, {4,2}. The result of sum is 4, and that of count is 2.</li><li id="EN-US_TOPIC_0000001188110532__li69601568438">CNs do not store user table data. Therefore, you do not need to specify a CN to perform SELECT queries on user tables. If the query statement contains a hidden remote call to start the transaction logic, the error message "Cannot send begin to other nodes as I'm not execute cn" is displayed.</li><li id="EN-US_TOPIC_0000001188110532__li360267184620"><strong id="EN-US_TOPIC_0000001188110532__b364819401695">EXECUTE DIRECT</strong> cannot be nested. If the inner SQL statement to be executed is also <strong id="EN-US_TOPIC_0000001188110532__b178035146163">EXECUTE DIRECT</strong>, run only the bottom-layer <strong id="EN-US_TOPIC_0000001188110532__b1672572812163">EXECUTE DIRECT</strong> statement.</li></ul>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001188110532__saea998a246df4d51a51fa2a854eab93a"><h4 class="sectiontitle">Syntax</h4><div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001188110532__s496d2f47f4ae48b0ad0f9afa1e18f594"><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="k">EXECUTE</span><span class="w"> </span><span class="n">DIRECT</span><span class="w"> </span><span class="k">ON</span><span class="w"> </span><span class="p">(</span><span class="w"> </span><span class="n">nodename</span><span class="w"> </span><span class="p">[,</span><span class="w"> </span><span class="p">...</span><span class="w"> </span><span class="p">]</span><span class="w"> </span><span class="p">)</span><span class="w"> </span><span class="n">query</span><span class="w"> </span><span class="p">;</span>
|
|
</pre></div></td></tr></table></div>
|
|
|
|
</div>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001188110532__sef734b80b4234f9696610d718960f24f"><h4 class="sectiontitle">Parameter Description</h4><ul id="EN-US_TOPIC_0000001188110532__u98f0aa2e2ba246af9d5fa4023afd0771"><li id="EN-US_TOPIC_0000001188110532__le566e2bbd36540f1bd475212a469d9c4"><strong id="EN-US_TOPIC_0000001188110532__a1329e0b5df29496c9db2d60c2775f640">nodename</strong><p id="EN-US_TOPIC_0000001188110532__a39709549c16b44e5ae7b75bc19293906">Specifies the node name.</p>
|
|
<p id="EN-US_TOPIC_0000001188110532__a9823c1f59d1746a190f8a4bb6988192e">Value range: An existing node.</p>
|
|
</li><li id="EN-US_TOPIC_0000001188110532__l8ceb2f6282784642b6cdc3ad5d015732"><strong id="EN-US_TOPIC_0000001188110532__a5623d031dcce49b6ba8a79c261ee385f">query</strong><p id="EN-US_TOPIC_0000001188110532__a075087218773492e82b18bd3b3ce7f68">Specifies the query SQL statement that you want to execute.</p>
|
|
</li></ul>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001188110532__section56661519161412"><h4 class="sectiontitle">Examples</h4><p id="EN-US_TOPIC_0000001188110532__p96305590452">Query records in table <strong id="EN-US_TOPIC_0000001188110532__b104877800233538"><span id="EN-US_TOPIC_0000001188110532__text129357620733538">tpcds.</span>customer_address</strong> on the dn_6001_6002 node:</p>
|
|
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001188110532__screen143205249466"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span>
|
|
<span class="normal">2</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">CREATE</span><span class="w"> </span><span class="k">TABLE</span><span class="w"> </span><span class="k">IF</span><span class="w"> </span><span class="k">NOT</span><span class="w"> </span><span class="k">EXISTS</span><span class="w"> </span><span class="n">customer_address</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="n">b</span><span class="w"> </span><span class="nb">int</span><span class="p">);</span>
|
|
<span class="k">EXECUTE</span><span class="w"> </span><span class="n">DIRECT</span><span class="w"> </span><span class="k">ON</span><span class="p">(</span><span class="n">dn_6001_6002</span><span class="p">)</span><span class="w"> </span><span class="s1">'select count(*) from customer_address'</span><span class="p">;</span>
|
|
</pre></div></td></tr></table></div>
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="dws_06_0242.html">DCL Syntax</a></div>
|
|
</div>
|
|
</div>
|
|
|