{"id":5349,"date":"2020-07-29T21:24:37","date_gmt":"2020-07-29T13:24:37","guid":{"rendered":"http:\/\/39.97.231.10\/?p=5349"},"modified":"2020-07-29T21:24:37","modified_gmt":"2020-07-29T13:24:37","slug":"mysql%e8%a1%8c%e6%9e%84%e9%80%a0%e5%99%a8%e8%a1%a8%e8%be%be%e5%bc%8f%e4%bc%98%e5%8c%96row-constructor-expression","status":"publish","type":"post","link":"http:\/\/www.weijing.co\/?p=5349","title":{"rendered":"MySQL\u884c\u6784\u9020\u5668\u8868\u8fbe\u5f0f\u4f18\u5316(Row Constructor Expression)"},"content":{"rendered":"<div class=\\\"blog_content\\\">\n<div class=\\\"blog_detail\\\">\n<div>\nmysql \u5b98\u65b9\u6587\u6863\u884c\u6784\u9020\u5668\u8868\u8fbe\u5f0f\u4f18\u5316(Row Constructor Expression Optimization)\u8fd9\u4e00\u8282\u91cc\u9762\uff0c\u5bf9\u884c\u6784\u9020\u8868\u8fbe\u5f0f\u53ca\u5176\u4f18\u5316\u8fdb\u884c\u4e86\u4ecb\u7ecd\uff0c\u56e0\u4e3a\u7528\u7684\u4e0d\u591a\uff0c\u4e5f\u6ca1\u592a\u5173\u6ce8\u8fc7\u3002\u4f46\u662f\u770b\u4e86\u51e0\u4e2a\u793a\u4f8b\uff0c\u53d1\u73b0\u6709\u4e00\u4e9b\u903b\u8f91\u8fd8\u662f\u4e0e\u9884\u60f3\u7684\u4e0d\u4e00\u6837\uff0c\u4e0b\u9762\u8be6\u7ec6\u4ecb\u7ecd\u3002<\/p>\n<h4>1. \u884c\u6784\u9020\u8868\u8fbe\u5f0f\u793a\u4f8b<\/h4>\n<p>SELECT * FROM t1 WHERE (column1,column2) = (1,1);<br \/>\n\u5176\u4e2d (column1,column2) \u4e0e (1,1)\u5c31\u662f\u884c\u6784\u9020\u8868\u8fbe\u5f0f\u3002<br \/>\n(column1,column2) = (1,1) \u8fd9\u4e2a\u8868\u8fbe\u5f0f\uff0c\u5728\u903b\u8f91\u4e0a\uff0c\u7b49\u540c\u4e8e\uff1a<br \/>\ncolumn1 = 1 AND column2 = 1<br \/>\n\u8fd9\u4e2a\u4e5f\u6bd4\u8f83\u597d\u7406\u89e3\uff0c\u4f46\u662f\uff0c\u5982\u679c\u628a<br \/>\n(column1,column2) &gt; (1,1) \u7406\u89e3\u4e3a column1 &gt; 1 AND column2 &gt; 1\uff0c\u90a3\u5c31\u9519\u4e86\u3002\u5b9e\u9645\u4e0a\u5e94\u8be5\u662f<br \/>\ncolumn1 &gt; 1 OR ((column1 = 1) AND (column2 &gt; 1))<br \/>\n\u5982\u679c\u4e0d\u76f8\u4fe1\u7684\u8bdd\uff0c\u770b\u4e0b\u9762\u8fd9\u4e2a\u6848\u4f8b\uff1a<\/p>\n<pre><code>mysql&gt; select * from t_test;\n+------+------+------+\n| c1   | c2   | c3   |\n+------+------+------+\n|    1 |    1 |    1 |\n|    1 |    1 |    0 |\n|    1 |    2 |    2 |\n|    1 |    2 |   -1 |\n+------+------+------+\n4 rows in set (0.00 sec)\nmysql&gt; select * from t_test where c1=1 AND (c2,c3) &gt; (1,1);\n+------+------+------+\n| c1   | c2   | c3   |\n+------+------+------+\n|    1 |    2 |    2 |\n|    1 |    2 |   -1 |\n+------+------+------+\n2 rows in set (0.00 sec)\nmysql&gt; select * from t_test where c1 = 1 AND (c2 &gt; 1 OR ((c2 = 1) AND (c3 &gt; 1)));\n+------+------+------+\n| c1   | c2   | c3   |\n+------+------+------+\n|    1 |    2 |    2 |\n|    1 |    2 |   -1 |\n+------+------+------+\n2 rows in set (0.00 sec)\n<\/code><\/pre>\n<p>(c2,c3) &gt; (1,1)\uff0c\u7ed3\u679c\u628ac3\u4e3a-1\u7684\u8bb0\u5f55\u4e5f\u67e5\u51fa\u6765\u4e86\uff0c\u662f\u4e0d\u662f\u4e0e\u671f\u671b\u6709\u70b9\u843d\u5dee\uff0c\u4f46\u4e8b\u5b9e\u5c31\u662f\u8fd9\u6837\u3002\u5b83\u7684\u903b\u8f91\u662f\u5148\u6bd4\u8f83\u5b57\u6bb5c2\uff0c\u5982\u679cc2 &gt; 1\uff0c\u76f4\u63a5\u8fd4\u56detrue\uff0c\u4e0d\u518d\u6bd4\u8f83c3\u3002\u5982\u679cc2=1\uff0c\u518d\u6bd4\u8f83\u5b57\u6bb5c3\u3002<\/p>\n<h4>2. \u884c\u6784\u9020\u8868\u8fbe\u5f0f\u4f18\u5316<\/h4>\n<p>\u5173\u4e8e\u884c\u6784\u9020\u8868\u8fbe\u5f0f\u7684\u4f18\u5316\uff0c\u4e3b\u8981\u8fd8\u662f\u8f6c\u6362\u6210\u591a\u4e2a\u5355\u72ec\u7684\u6761\u4ef6\u8868\u8fbe\u5f0f\uff0c\u7531 or and \u8fd9\u7c7b\u903b\u8f91\u8fd0\u7b97\u7b26\u8fde\u63a5\uff0c\u8fd9\u6837\u624d\u80fd\u6700\u5927\u53ef\u80fd\u7528\u4e0a\u7d22\u5f15\u3002\n<\/p><\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>mysql \u5b98\u65b9\u6587\u6863\u884c\u6784\u9020\u5668\u8868\u8fbe\u5f0f\u4f18\u5316(Row Constructor Expression Optimiza &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"http:\/\/www.weijing.co\/?p=5349\"> <span class=\"screen-reader-text\">MySQL\u884c\u6784\u9020\u5668\u8868\u8fbe\u5f0f\u4f18\u5316(Row Constructor Expression)<\/span> \u67e5\u770b\u5168\u6587 &raquo;<\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":""},"categories":[90,88],"tags":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"mailpoet_newsletter_max":false,"woocommerce_thumbnail":false,"woocommerce_single":false,"woocommerce_gallery_thumbnail":false,"shop_catalog":false,"shop_single":false,"shop_thumbnail":false},"uagb_author_info":{"display_name":"weijing","author_link":"http:\/\/www.weijing.co\/?author=4"},"uagb_comment_info":0,"uagb_excerpt":"mysql \u5b98\u65b9\u6587\u6863\u884c\u6784\u9020\u5668\u8868\u8fbe\u5f0f\u4f18\u5316(Row Constructor Expression Optimiza&hellip;","_links":{"self":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/5349"}],"collection":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5349"}],"version-history":[{"count":0,"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/5349\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5349"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5349"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5349"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}