<HTML><BODY><blockquote style="font-family: Helvetica, Arial, Tahoma, Verdana, sans-serif;" data-mce-style="font-family: Helvetica, Arial, Tahoma, Verdana, sans-serif;"><br></blockquote>Branch:<br><a href="https://github.com/tarantool/tarantool/tree/bn/gh-3293-unique-opt">https://github.com/tarantool/tarantool/tree/bn/gh-3293-unique-opt</a> <br><br>Issue:<br><a href="https://github.com/tarantool/tarantool/issues/3293">https://github.com/tarantool/tarantool/issues/3293</a> <br><blockquote style="font-family: Helvetica; font-size: 12px; text-size-adjust: auto;" data-mce-style="font-family: Helvetica; font-size: 12px; text-size-adjust: auto;"><br class="Apple-interchange-newline">In some cases ON CONFLICT REPLACE/IGNORE can be optimized. If<br>following conditions are true:<br>1) Space has PRIMARY KEY index only.<br>2) There are no foreign keys to other spaces.<br>3) There are no delete triggers to be fired if conflict happens.<br>4) The errt or action is REPLACE or IGNORE.</blockquote><br style="font-family: Helvetica; font-size: 12px;" data-mce-style="font-family: Helvetica; font-size: 12px;"><span style="font-family: Helvetica; font-size: 12px; float: none; display: inline !important;" data-mce-style="font-family: Helvetica; font-size: 12px; float: none; display: inline !important;">errt: typo.</span><br><blockquote style="font-family: Helvetica, Arial, Tahoma, Verdana, sans-serif;" data-mce-style="font-family: Helvetica, Arial, Tahoma, Verdana, sans-serif;"><div><span style="font-family: Helvetica; font-size: 12px; float: none; display: inline !important;" data-mce-style="font-family: Helvetica; font-size: 12px; float: none; display: inline !important;"> </span></div></blockquote><br>Done.<br><br><blockquote style="font-family: Helvetica, Arial, Tahoma, Verdana, sans-serif;" data-mce-style="font-family: Helvetica, Arial, Tahoma, Verdana, sans-serif;"><div><blockquote style="font-family: Helvetica; font-size: 12px; text-size-adjust: auto;" data-mce-style="font-family: Helvetica; font-size: 12px; text-size-adjust: auto;">Then uniqueness can be ensured by Tarantool only, without VDBE<br>bytecode. This patch contains a small fix for that +</blockquote><br style="font-family: Helvetica; font-size: 12px;" data-mce-style="font-family: Helvetica; font-size: 12px;"><span style="font-family: Helvetica; font-size: 12px; float: none; display: inline !important;" data-mce-style="font-family: Helvetica; font-size: 12px; float: none; display: inline !important;">Replace ‘+’ with word. Don’t mention that it is ’small’ fix, let it be just fix.</span></div></blockquote><br>Done.<br><br><blockquote style="font-family: Helvetica, Arial, Tahoma, Verdana, sans-serif;" data-mce-style="font-family: Helvetica, Arial, Tahoma, Verdana, sans-serif;"><div><blockquote style="font-family: Helvetica; font-size: 12px; text-size-adjust: auto;" data-mce-style="font-family: Helvetica; font-size: 12px; text-size-adjust: auto;">related code was refactored a little bit and necessary comments</blockquote><br style="font-family: Helvetica; font-size: 12px;" data-mce-style="font-family: Helvetica; font-size: 12px;"><span style="font-family: Helvetica; font-size: 12px; float: none; display: inline !important;" data-mce-style="font-family: Helvetica; font-size: 12px; float: none; display: inline !important;">The same: don’t use ‘little bit’ — it sounds like you left smth</span><br style="font-family: Helvetica; font-size: 12px;" data-mce-style="font-family: Helvetica; font-size: 12px;"><span style="font-family: Helvetica; font-size: 12px; float: none; display: inline !important;" data-mce-style="font-family: Helvetica; font-size: 12px; float: none; display: inline !important;">in a shitty state consciously.</span></div></blockquote><br>Done.<br><br><blockquote style="font-family: Helvetica, Arial, Tahoma, Verdana, sans-serif;" data-mce-style="font-family: Helvetica, Arial, Tahoma, Verdana, sans-serif;"><div><blockquote style="font-family: Helvetica; font-size: 12px; text-size-adjust: auto;" data-mce-style="font-family: Helvetica; font-size: 12px; text-size-adjust: auto;">+/*<br>+<span class="Apple-converted-space_mailru_css_attribute_postfix"> </span>* ABORT and DEFAULT error actions can be handled<br>+<span class="Apple-converted-space_mailru_css_attribute_postfix"> </span>* by Tarantool only without emitting VDBE</blockquote><br style="font-family: Helvetica; font-size: 12px;" data-mce-style="font-family: Helvetica; font-size: 12px;"><span style="font-family: Helvetica; font-size: 12px; float: none; display: inline !important;" data-mce-style="font-family: Helvetica; font-size: 12px; float: none; display: inline !important;">Remove word ‘only’: it confuses little bit (IMHO).</span></div></blockquote>Done.<br><br><blockquote style="font-family: Helvetica, Arial, Tahoma, Verdana, sans-serif;" data-mce-style="font-family: Helvetica, Arial, Tahoma, Verdana, sans-serif;"><div><blockquote style="font-family: Helvetica; font-size: 12px; text-size-adjust: auto;" data-mce-style="font-family: Helvetica; font-size: 12px; text-size-adjust: auto;">+<br>+/*<br>+<span class="Apple-converted-space_mailru_css_attribute_postfix"> </span>* Find out what action to take in case there is<br>+<span class="Apple-converted-space_mailru_css_attribute_postfix"> </span>* a uniqueness conflict.<br>+<span class="Apple-converted-space_mailru_css_attribute_postfix"> </span>*/<br>+onError = pIdx->onError;<br>+</blockquote><br style="font-family: Helvetica; font-size: 12px;" data-mce-style="font-family: Helvetica; font-size: 12px;"><span style="font-family: Helvetica; font-size: 12px; float: none; display: inline !important;" data-mce-style="font-family: Helvetica; font-size: 12px; float: none; display: inline !important;">Nit-picking: don’t put too many empty lines.</span><br style="font-family: Helvetica; font-size: 12px;" data-mce-style="font-family: Helvetica; font-size: 12px;"><span style="font-family: Helvetica; font-size: 12px; float: none; display: inline !important;" data-mce-style="font-family: Helvetica; font-size: 12px; float: none; display: inline !important;">In this particular case, you outline very elementary statement.</span></div></blockquote><br><blockquote style="font-family: Helvetica, Arial, Tahoma, Verdana, sans-serif;" data-mce-style="font-family: Helvetica, Arial, Tahoma, Verdana, sans-serif;"><div><span style="font-family: Helvetica; font-size: 12px; float: none; display: inline !important;" data-mce-style="font-family: Helvetica; font-size: 12px; float: none; display: inline !important;"> </span></div></blockquote>Done.<br><br><blockquote style="font-family: Helvetica, Arial, Tahoma, Verdana, sans-serif;" data-mce-style="font-family: Helvetica, Arial, Tahoma, Verdana, sans-serif;"><div><blockquote style="font-family: Helvetica; font-size: 12px; text-size-adjust: auto;" data-mce-style="font-family: Helvetica; font-size: 12px; text-size-adjust: auto;">+/*<br>+<span class="Apple-converted-space_mailru_css_attribute_postfix"> </span>* override_error is an action which is directly<br>+<span class="Apple-converted-space_mailru_css_attribute_postfix"> </span>* specified by user in queries like<br>+<span class="Apple-converted-space_mailru_css_attribute_postfix"> </span>* INSERT OR <override_error> and therefore<br>+<span class="Apple-converted-space_mailru_css_attribute_postfix"> </span>* should have higher priority than indexes<br>+<span class="Apple-converted-space_mailru_css_attribute_postfix"> </span>* error actions.<br>+<span class="Apple-converted-space_mailru_css_attribute_postfix"> </span>*/</blockquote><br style="font-family: Helvetica; font-size: 12px;" data-mce-style="font-family: Helvetica; font-size: 12px;"><span style="font-family: Helvetica; font-size: 12px; float: none; display: inline !important;" data-mce-style="font-family: Helvetica; font-size: 12px; float: none; display: inline !important;">You put almost the same comment to on_error struct.</span><br style="font-family: Helvetica; font-size: 12px;" data-mce-style="font-family: Helvetica; font-size: 12px;"><span style="font-family: Helvetica; font-size: 12px; float: none; display: inline !important;" data-mce-style="font-family: Helvetica; font-size: 12px; float: none; display: inline !important;">Change it to more informative or remove.</span></div></blockquote><br>Done, this comment was removed.<br><br><blockquote style="font-family: Helvetica, Arial, Tahoma, Verdana, sans-serif;" data-mce-style="font-family: Helvetica, Arial, Tahoma, Verdana, sans-serif;"><div><blockquote style="font-family: Helvetica; font-size: 12px; text-size-adjust: auto;" data-mce-style="font-family: Helvetica; font-size: 12px; text-size-adjust: auto;">+int override_error = on_conflict->override_error;<br>+int optimized_error_action = on_conflict->optimized_on_conflict;</blockquote><br style="font-family: Helvetica; font-size: 12px;" data-mce-style="font-family: Helvetica; font-size: 12px;"><span style="font-family: Helvetica; font-size: 12px; float: none; display: inline !important;" data-mce-style="font-family: Helvetica; font-size: 12px; float: none; display: inline !important;">If you used enum type, you wouldn’t have to add assertion below.</span></div></blockquote><br>Done, all error actions are enums right now.<br><br><blockquote style="font-family: Helvetica, Arial, Tahoma, Verdana, sans-serif;" data-mce-style="font-family: Helvetica, Arial, Tahoma, Verdana, sans-serif;"><div><blockquote style="font-family: Helvetica; font-size: 12px; text-size-adjust: auto;" data-mce-style="font-family: Helvetica; font-size: 12px; text-size-adjust: auto;">+/*<br>+<span class="Apple-converted-space_mailru_css_attribute_postfix"> </span>* override_error represents error action in queries like<br>+<span class="Apple-converted-space_mailru_css_attribute_postfix"> </span>* INSERT/UPDATE OR REPLACE, INSERT/UPDATE OR IGNORE,<br>+<span class="Apple-converted-space_mailru_css_attribute_postfix"> </span>* which is strictly specified by user and therefore<br>+<span class="Apple-converted-space_mailru_css_attribute_postfix"> </span>* should have been used even when optimization is<br>+<span class="Apple-converted-space_mailru_css_attribute_postfix"> </span>* possible (uniqueness can be checked by Tarantool).<br>+<span class="Apple-converted-space_mailru_css_attribute_postfix"> </span>*/</blockquote><br style="font-family: Helvetica; font-size: 12px;" data-mce-style="font-family: Helvetica; font-size: 12px;"><span style="font-family: Helvetica; font-size: 12px; float: none; display: inline !important;" data-mce-style="font-family: Helvetica; font-size: 12px; float: none; display: inline !important;">This comment is almost copy of one from struct declaration.<span class="Apple-converted-space_mailru_css_attribute_postfix"> </span></span><br style="font-family: Helvetica; font-size: 12px;" data-mce-style="font-family: Helvetica; font-size: 12px;"><span style="font-family: Helvetica; font-size: 12px; float: none; display: inline !important;" data-mce-style="font-family: Helvetica; font-size: 12px; float: none; display: inline !important;">Remove or rephrase.</span></div></blockquote><br>Done, removed.<br><br><blockquote style="font-family: Helvetica, Arial, Tahoma, Verdana, sans-serif;" data-mce-style="font-family: Helvetica, Arial, Tahoma, Verdana, sans-serif;"><div><blockquote style="font-family: Helvetica; font-size: 12px; text-size-adjust: auto;" data-mce-style="font-family: Helvetica; font-size: 12px; text-size-adjust: auto;">+struct on_conflict {<br>+/**<br>+<span class="Apple-converted-space_mailru_css_attribute_postfix"> </span>* Represents an error action in queries like<br>+<span class="Apple-converted-space_mailru_css_attribute_postfix"> </span>* INSERT/UPDATE OR <override_error>, which<br>+<span class="Apple-converted-space_mailru_css_attribute_postfix"> </span>* overrides all space constraints error actions.<br>+<span class="Apple-converted-space_mailru_css_attribute_postfix"> </span>*/<br>+int override_error;</blockquote><br style="font-family: Helvetica; font-size: 12px;" data-mce-style="font-family: Helvetica; font-size: 12px;"><span style="font-family: Helvetica; font-size: 12px; float: none; display: inline !important;" data-mce-style="font-family: Helvetica; font-size: 12px; float: none; display: inline !important;">Why do you declare type of this field as int,</span><br style="font-family: Helvetica; font-size: 12px;" data-mce-style="font-family: Helvetica; font-size: 12px;"><span style="font-family: Helvetica; font-size: 12px; float: none; display: inline !important;" data-mce-style="font-family: Helvetica; font-size: 12px; float: none; display: inline !important;">when it can take values from on_conflict_action enum?</span></div></blockquote><br>Done.<br><br><blockquote style="font-family: Helvetica, Arial, Tahoma, Verdana, sans-serif;" data-mce-style="font-family: Helvetica, Arial, Tahoma, Verdana, sans-serif;"><div><blockquote style="font-family: Helvetica; font-size: 12px; text-size-adjust: auto;" data-mce-style="font-family: Helvetica; font-size: 12px; text-size-adjust: auto;">+<span class="Apple-converted-space_mailru_css_attribute_postfix"> </span>* the value is ON_CONFLICT_ACTION_NONE, otherwise it is<br>+<span class="Apple-converted-space_mailru_css_attribute_postfix"> </span>* ON_CONFLICT_ACTON_IGNORE or ON_CONFLICT_ACTION_REPLACE.<br>+<span class="Apple-converted-space_mailru_css_attribute_postfix"> </span>*/<br>+int optimized_on_conflict;</blockquote><br style="font-family: Helvetica; font-size: 12px;" data-mce-style="font-family: Helvetica; font-size: 12px;"><span style="font-family: Helvetica; font-size: 12px; float: none; display: inline !important;" data-mce-style="font-family: Helvetica; font-size: 12px; float: none; display: inline !important;">Your structure is already called ‘on_conflict’,</span><br style="font-family: Helvetica; font-size: 12px;" data-mce-style="font-family: Helvetica; font-size: 12px;"><span style="font-family: Helvetica; font-size: 12px; float: none; display: inline !important;" data-mce-style="font-family: Helvetica; font-size: 12px; float: none; display: inline !important;">so don’t repeat this phrase in field’s name.</span><br style="font-family: Helvetica; font-size: 12px;" data-mce-style="font-family: Helvetica; font-size: 12px;"><span style="font-family: Helvetica; font-size: 12px; float: none; display: inline !important;" data-mce-style="font-family: Helvetica; font-size: 12px; float: none; display: inline !important;">Also, the same as previous field: better declare it as enum.</span></div></blockquote><br>Done.<br><br><br><br><br><br><br>-- <br>Bulat Niatshin</BODY></HTML>