{"id":1494,"date":"2021-11-18T17:50:17","date_gmt":"2021-11-18T09:50:17","guid":{"rendered":"https:\/\/www.zeroheart.xyz\/wordpress\/?p=1494"},"modified":"2021-11-18T17:50:17","modified_gmt":"2021-11-18T09:50:17","slug":"%e6%89%b9%e9%87%8f%e6%9b%b4%e6%96%b0sql","status":"publish","type":"post","link":"https:\/\/www.zeroheart.xyz\/wordpress\/?p=1494","title":{"rendered":"\u6279\u91cf\u66f4\u65b0sql"},"content":{"rendered":"\n<pre class=\"wp-block-preformatted\">1.\u521b\u5efa\u4e34\u65f6\u8868\uff0c\u63d2\u5165\u76f8\u5173\u5b57\u6bb5\u4e4b\u540e\u66f4\u65b0\ncreate temporary table tmp(id int(4) primary key,dr varchar(50));\ninsert into tmp values  (0,'gone'), (1,'xx'),...(m,'yy');\nupdate test_tbl, tmp set test_tbl.dr=tmp.dr where test_tbl.id=tmp.id;<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">2.case \u8bed\u53e5\u66f4\u65b0\nUPDATE table\n    SET \n    a = CASE id \n        WHEN 1 THEN 3 \n        WHEN 2 THEN 4 \n        WHEN 3 THEN 5 \n    END, \n    b = CASE id \n        WHEN 1 THEN 'x'\n        WHEN 2 THEN 'y'\n        WHEN 3 THEN 'z'\n    END\nWHERE id IN (1,2,3)<\/pre>\n\n\n\n<p>\u5bf9\u4e8ehibenate\uff0c\u53ef\u4ee5\u5f00\u542f\u6279\u91cf\u5904\u7406<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">spring.jpa.properties.hibernate.order_inserts=true\nspring.jpa.properties.hibernate.order_updates=true spring.jpa.properties.hibernate.batch_versioned_data=true<\/pre>\n\n\n\n<p>\u5bf9\u4e8e\u7c7b\u578b\u4e00\u81f4\u7684\u5b9e\u4f53\uff0c\u4e5f\u53ef\u4ee5\u663e\u5f0f\u7684\u64cd\u4f5c\u6570\u636e<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@Transactional\n@Test\npublic void whenFlushingAfterBatch_ThenClearsMemory() {\n    for (int i = 0; i &lt; 10; i++) {\n        if (i > 0 &amp;&amp; i % BATCH_SIZE == 0) {\n            entityManager.flush();\n            entityManager.clear();\n        }\n        School school = createSchool(i);\n        entityManager.persist(school);\n    }\n}<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1.\u521b\u5efa\u4e34\u65f6\u8868\uff0c\u63d2\u5165\u76f8\u5173\u5b57\u6bb5\u4e4b\u540e\u66f4\u65b0 create temporary table tmp(id int(4) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,115],"tags":[],"_links":{"self":[{"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1494"}],"collection":[{"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1494"}],"version-history":[{"count":6,"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1494\/revisions"}],"predecessor-version":[{"id":1500,"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1494\/revisions\/1500"}],"wp:attachment":[{"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1494"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1494"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1494"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}