{"id":7482,"date":"2023-11-28T19:31:17","date_gmt":"2023-11-28T11:31:17","guid":{"rendered":"https:\/\/wx.kaifamiao.info\/?p=7482"},"modified":"2023-11-28T19:31:24","modified_gmt":"2023-11-28T11:31:24","slug":"mysql-yu-dao-guo-si-suo-wen-ti-ma-ni-shi-ru-he-jie","status":"publish","type":"post","link":"http:\/\/wx.kaifamiao.info\/index.php\/2023\/11\/28\/mysql-yu-dao-guo-si-suo-wen-ti-ma-ni-shi-ru-he-jie\/","title":{"rendered":"MySQL\u9047\u5230\u8fc7\u6b7b\u9501\u95ee\u9898\u5417\uff0c\u4f60\u662f\u5982\u4f55\u89e3\u51b3\u7684\uff1f"},"content":{"rendered":"<p>\u6211\u6392\u67e5\u6b7b\u9501\u7684\u4e00\u822c\u6b65\u9aa4\u662f\u9171\u7d2b\u7684\uff1a<br \/>\n1\u3001\t\u67e5\u770b\u6b7b\u9501\u65e5\u5fd7 show engine innodb status\uff1b<br \/>\n2\u3001\t\u627e\u51fa\u6b7b\u9501Sql<br \/>\n3\u3001\t\u5206\u6790sql\u52a0\u9501\u60c5\u51b5<br \/>\n4\u3001\t\u6a21\u62df\u6b7b\u9501\u6848\u53d1<br \/>\n5\u3001\t\u5206\u6790\u6b7b\u9501\u65e5\u5fd7<br \/>\n6\u3001\t\u5206\u6790\u6b7b\u9501\u7ed3\u679c<br \/>\nMySQL\u4e2din\u548cexists\u7684\u533a\u522b\uff1f<br \/>\n\u8fd9\u4e2a\uff0c\u8ddf\u4e00\u4e0bdemo\u6765\u770b\u66f4\u523a\u6fc0\u5427\uff0c\u554a\u54c8\u54c8<br \/>\n\u5047\u8bbe\u8868A\u8868\u793a\u67d0\u4f01\u4e1a\u7684\u5458\u5de5\u8868\uff0c\u8868B\u8868\u793a\u90e8\u95e8\u8868\uff0c\u67e5\u8be2\u6240\u6709\u90e8\u95e8\u7684\u6240\u6709\u5458\u5de5\uff0c\u5f88\u5bb9\u6613\u6709\u4ee5\u4e0b<br \/>\nSQL\uff1a<br \/>\nselect * from A where deptId in (select deptId from B)\uff1b<br \/>\n\u8fd9\u6837\u5199\u7b49\u4ef7\u4e8e\uff1a<br \/>\n\u5148\u67e5\u8be2\u90e8\u95e8\u8868B<br \/>\nselect deptld from B<br \/>\n\u518d\u7531\u90e8\u95e8deptId,\u67e5\u8be2A\u7684\u5458\u5de5<br \/>\nselect * from A where A.deptId = B.deptId<br \/>\n\u53ef\u4ee5\u62bd\u8c61\u6210\u8fd9\u6837\u7684\u4e00\u4e2a\u5faa\u73af\uff1a<br \/>\nList&lt;&gt; resultSet \uff1b<br \/>\nfor(int i=0\uff1bi&lt;B.length\uff1bi++) {<br \/>\nfor(int j=0\uff1bj&lt;A.length\uff1bj++) {<br \/>\nif (A[i].id=B[j].id) {<br \/>\nresultSet.add(A[i])\uff1b<br \/>\nbreak\uff1b<br \/>\n}<br \/>\n}<br \/>\n}<br \/>\n\u663e\u7136\uff0c\u9664\u4e86\u4f7f\u7528in,\u6211\u4eec\u4e5f\u53ef\u4ee5\u7528exists\u5b9e\u73b0\u4e00\u6837\u7684\u67e5\u8be2\u529f\u80fd\uff0c\u5982\u4e0b\uff1a<br \/>\nselect * from A where exists (select 1 from B where A.deptId = B.deptId)\uff1b<br \/>\n\u56e0\u4e3aexists\u67e5\u8be2\u7684\u7406\u89e3\u5c31\u662f\uff0c\u5148\u6267\u884c\u4e3b\u67e5\u8be2\uff0c\u83b7\u5f97\u6570\u636e\u540e\uff0c\u518d\u653e\u5230\u5b50\u67e5\u8be2\u4e2d\u505a\u6761\u4ef6\u9a8c\u8bc1\uff0c\u6839 \u636e\u9a8c\u8bc1\u7ed3\u679c(true\u6216\u8005false),\u6765\u51b3\u5b9a\u4e3b\u67e5\u8be2\u7684\u6570\u636e\u7ed3\u679c\u662f\u5426\u5f97\u4ee5\u4fdd\u7559\u3002<br \/>\n\u90a3\u4e48\uff0c\u8fd9\u6837\u5199\u5c31\u7b49\u4ef7\u4e8e\uff1a<br \/>\nselect * from A,\u5148\u4eceA\u8868\u505a\u5faa\u73af<br \/>\nselect * from B where A.deptld = B.deptld,\u518d\u4ece B \u8868\u505a\u5faa\u73af<br \/>\n\u540c\u7406\uff0c\u53ef\u4ee5\u62bd\u8c61\u6210\u8fd9\u6837\u4e00\u4e2a\u5faa\u73af\uff1a<br \/>\nListO resultSet \uff1b<br \/>\nfor(int i=0\uff1bi&lt;A.length\uff1bi++) {<br \/>\nfor (int j=0\uff1bj&lt;B.length\uff1bj++) {<br \/>\nif (A[i].deptId=B[j].deptId) {<br \/>\nresultSet.add(A[i])\uff1b<br \/>\nbreak\uff1b<br \/>\n}<br \/>\n}<br \/>\n}<br \/>\n\u6570\u636e\u5e93\u6700\u8d39\u52b2\u7684\u5c31\u662f\u8ddf\u7a0b\u5e8f\u94fe\u63a5\u91ca\u653e\u3002\u5047\u8bbe\u94fe\u63a5\u4e86\u4e24\u6b21\uff0c\u6bcf\u6b21\u505a\u4e0a\u767e\u4e07\u6b21\u7684\u6570\u636e\u96c6\u67e5\u8be2\uff0c\u67e5\u5b8c\u5c31\u8d70\uff0c\u8fd9\u6837\u5c31\u53ea\u505a\u4e86\u4e24\u6b21\uff1b\u76f8\u53cd\u5efa\u7acb\u4e86\u4e0a\u767e\u4e07\u6b21\u94fe\u63a5\uff0c\u7533\u8bf7\u94fe\u63a5\u91ca\u653e\u53cd\u590d\u91cd\u590d\uff0c\u8fd9\u6837\u7cfb\u7edf\u5c31\u53d7\u4e0d\u4e86\u4e86\u3002\u5373MySQL\u4f18\u5316\u539f\u5219\uff0c\u5c31\u662f\u5c0f\u8868\u9a71\u52a8\u5927\u8868\uff0c\u5c0f\u7684\u6570\u636e\u96c6\u9a71\u52a8\u5927\u7684\u6570\u636e\u96c6\uff0c\u4ece\u800c\u8ba9\u6027\u80fd\u66f4\u4f18\u3002<br \/>\n\u56e0\u6b64\uff0c\u6211\u4eec\u8981\u9009\u62e9\u6700\u5916\u5c42\u5faa\u73af\u5c0f\u7684\uff0c\u4e5f\u5c31\u662f\uff0c\u5982\u679cB\u7684\u6570\u636e\u91cf\u5c0f\u4e8eA,\u9002\u5408\u4f7f\u7528in,\u5982\u679cB\u7684\u6570\u636e\u91cf\u5927\u4e8eA,\u5373\u9002\u5408\u9009\u62e9exists ,\u8fd9\u5c31\u662fin\u548cexists\u7684\u533a\u522b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6211\u6392\u67e5\u6b7b\u9501\u7684\u4e00\u822c\u6b65\u9aa4\u662f\u9171\u7d2b\u7684\uff1a 1\u3001 \u67e5\u770b\u6b7b\u9501\u65e5\u5fd7 show engine innodb status\uff1b 2\u3001 [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[102],"tags":[],"class_list":["post-7482","post","type-post","status-publish","format-standard","hentry","category-db"],"_links":{"self":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/7482","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/comments?post=7482"}],"version-history":[{"count":1,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/7482\/revisions"}],"predecessor-version":[{"id":7483,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/7482\/revisions\/7483"}],"wp:attachment":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/media?parent=7482"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/categories?post=7482"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/tags?post=7482"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}