Javaèªæ¸ä¼ã®å®¿é¡ãã
Javaèªæ¸ä¼ãåºç¤ããã®Servlet/JSP 第5çããèªãä¼ï¼ç¬¬3åï¼ã®å®¿é¡ã§ãintï¼32bitæ´æ°ï¼ãè¶ ããè¡ã®ãã¼ãã«ãä½æãã¦ãä¸æ°ã«intãè¶ ããè¡ã®æ´æ°ãããæã®æ»ãå¤ã調ã¹ã¦ã¿ãããã®åãçµã¿ã§ãã
H2ãã¼ã¿ãã¼ã¹ã¸ã®ãã¼ã¿ç»é²ã«è¦ããæé
primary keyãuniqueå±æ§ããªãåä¸ã«ã©ã ã®ãã¼ãã«ãå®ç¾©
CREATE TABLE bigdata ( id int );
åç´ insert
32bit符å·ä»æ´æ°å¤ã®æ大å¤ãããã21åãªã®ã§ã30åè¡ã®ã¬ã³ã¼ããç»é²ãã¾ãã ã¾ãã¯ãåç´ã« INSERT INTO bigdata(id) values (1); ã®ããã«ãã¼ã¿ãã¤ã³ãµã¼ãããã¯ã¨ãªã30ååå®è¡ãã¾ãã
- æ¹æ³1 èªåã³ããããæå¹ï¼ããã©ã«ãï¼
- æ¹æ³2 èªåã³ããããç¡å¹ã«ãã100ä¸è¡ãã¨ã«commit
æ¹æ³1ã¯ã100ä¸è¡ã®insertã«20ç§ãè¦ãã¾ããã30åè¡ã®insertã«æ¨å®17æéè¦ããè¦ç©ã§ããèªåã³ããããæå¹ã ã¨ãinsertãå®è¡ãããã¨ã«ã³ããããåãã®ã§é ãã ããã¨æ³å®ãã¦ãã¾ããã
æ¹æ³2ã§ãèªåã³ããããç¡å¹ã¨ãã¦ãä¸å®éæ¯ã«commitããã¦ã¿ã¾ããã ã¨ããããæ¹æ³2ã§ãã100ä¸è¡ã®insertã«20ç§ãè¦ããæ¹æ³1ã¨ã»ã¨ãã©å¦çæéãå¤ããã¾ããã
ãããinsert
次ã¯ããããç»é²ãå®æ½ãã¾ããè¤æ°ã®insertæããããåãã¦ããããããå®è¡ãã¾ãã100ãã1000åã®isertããããã«ã¾ã¨ãã¾ãã
PreparedStatement ps = conn.prepareStatement("insert into bigdata values(?)"); : for (int i = 0; i < 1000; i++) { ps.setInt(1, count); ps.addBatch(); } ps.executeBatch();
ãããç»é²ã®å ´åãèªåã³ãããã¯ãªãã¨ããæå¾ã«commitãã¾ãã*1
ãã¦ãæå¾ ãã¦ããç»é²é度ã§ããããªãã¨æ¹æ³3ã§ã100ä¸è¡ã®insertã«20ç§ãè¦ããæ¹æ³1ã2ã¨ã»ã¨ãã©åãã§ããã
ããã¾ã§ã®çµæãããH2 databaseã¯SQLã®ãªã¯ã¨ã¹ãã®ãªã¼ãã¼ããããèªåã³ãããã®ãªã¼ãã¼ããããã»ã¨ãã©ãªããã¯ã¨ãªã®å¦çæ°ãã»ã¼ãã®ã¾ã¾å¦çæéã«ãªã£ã¦ãããã®ã¨æ¨æ¸¬ãã¾ãã
ããã¨ãã¯ã¨ãªã®å¦çæ°ãæ¸ããã¦ç»é²è¡æ°ãå¢ãããã¨ãã§ããã°å¦çæéãç縮ã§ããã®ã§ã¯ã¨èãã¾ãã
è¤æ°è¡ã1ã¤ã®insertã§
ããã§ãinsertæã¯ãè¤æ°è¡ã®ãã¼ã¿ãç»é²ãããã¨ãã§ãã¾ãã
insert into bigdata(id) values (1), (3), (5), (7), (11), (13);
ãã®insertæã¯ã6è¡ã®ã¬ã³ã¼ããç»é²ãã¾ãã
- æ¹æ³4 èªåã³ããããç¡å¹ã«ãã¦ã10è¡ã®ãã¼ã¿ã1ã¤ã®insertæã§ç»é²ãã
100ä¸è¡ã®ç»é²ã2-3ç§ã¨ç縮ãããã¨ãã§ãã¾ããã
- æ¹æ³5 èªåã³ããããç¡å¹ã«ãã¦ã100è¡ã®ãã¼ã¿ã1ã¤ã®insertæã§ç»é²ãã
100ä¸è¡ã®ç»é²ã1ç§ã¨ããã«ç縮ãããã¨ãã§ãã¾ãããããã§ããã°ã30åè¡ã®ç»é²ã«50åã®è¦ç©ããã§ãã
å®è¡ç°å¢
å®è¡çµæ
*1:30åè¡ã¨ãªãã¨ããããã«å°åãã«commitããæ¹ãè¯ããã