æåŸ-2015th-GSoCã¯éåžžã«å€±æããããšãå€æããŸããã åèšã§8人ã®åŠçãããŸããããå€ãã¯å€ã®éäžã§ïŒäžéè©äŸ¡ã§ïŒå€±æãã3人ã¯ã«ã¡ã«ãŒã³ã®åã倧åŠã®ïŒãããŠæããã«åãã³ãŒã¹ã®ïŒåªç§ãªã¢ããªã±ãŒã·ã§ã³ã§ãããããå®å šã«ããšããèšèããã¯äœãããŸããã§ããããŸãã1ãæåã§ã³ã¡ã³ãã®1è¡ãä¿®æ£ããããããããŸããã ãããŠãäžæçã«å€±æããåŸã圌ãã¯ç§ãã¡ã®æ±ºå®ãGoogleã«äžèšŽããããšããé§ã®ãããªè åšãå«ãã¡ãŒã«ãéã£ãŠãããŸããã ããšãã°ãå€ãã®åŠçã倱æããŠèªåã®ã€ã¡ãŒãžãæãªãã®ã¯è¯ããããŸãããæ¥å¹ŽãGoogleã¯å ŽæãäžããŸããã
ããããGoogleã¯åŸããã圌ãã«äžããŸããã ãããŠä»å¹Žã¯ãããããå¯Ÿç §çã«ãéåžžã«æåããããšãå€æããŸããã
ä»å¹Žã54人ã®åŠçã䞻匵ãã10ã¹ããããå²ãåœãŠãããŸããã éå»1幎éã®æ²ããçµéšãèæ ®ããŠãåãå ¥ãããããã¹ãŠã®åŠçãç°ãªã倧åŠã®åºèº«ã§ããããšã確èªããŸããããããã³ã°ããå Žåã¯ãäºãã«ç¬ç«ããŠããŸãã ããã¯ãã€ãã®ããšã§ãã-äœäººãã®åŠçãäºåã«ç§ãã¡ã®ã¡ãŒãªã³ã°ãªã¹ãã«æžã蟌ã¿ãIRCã«ç»å Žãããããžã§ã¯ãã«ã€ããŠè°è«ããŸããã 2人ã®åŠçãå®éã®ãããã¿ã€ããäœæããŸããã ãã¡ããããã®ãããªã¢ã¯ãã£ããªãã®ã¯ãã¹ãŠåãå ¥ããããŸããã æ®ãã¯è¹å€ã«æ®ããã競äºã¯å€§ããã£ãã åãå ¥ãããã10人ã®åŠçããã次ã®ããšãå€æããŸããã
- 1ã€ã®ãããžã§ã¯ãã¯MHAåãã§ããã MariaDBã¯å æ¬çãªçµç¹ãšããŠæ©èœãããããžã§ã¯ãã¯MariaDB / MySQL / Perconaãšã³ã·ã¹ãã å ã®ä»»æã®ãã®ã«ãªããŸã
- 1ã€ã®ãããžã§ã¯ãã¯MaxScaleçšã§ãããã€ãŸãããµãŒããŒçšã§ããããŸããã§ããã äžèšåç §
- äžäººã®çåŸã¯äœãããã7æã«äžéããŸãã
- 3人ã«å¥åŠãªããšãèµ·ãã£ã-圌ãã¯ããŸãæ©èœããåé¡ã¯äºèŠãããªãã£ãã ãããŠçªç¶ã8ææ«ã«Googleã¯ããŒã¿ã«ççŸãèŠã€ãã£ããšæžããŠãããäžæ£è¡çºã®çãããããããã°ã©ã ããé€å€ãããŸããã ããã¯éåžžã«ãããšãå€æãã人ã ã¯å€ã®éãã£ãšåããŠããŸããã ããããè©Šã¿ãŸããããç¶æ³ã«åœ±é¿ãäžããããšã¯ã§ããŸããã§ããã
- 5人ã®åŠçãæåŸãŸã§è¡ãããããžã§ã¯ããå®äºããŸããã 50ïŒ ã¯ç§ãã¡ã«ãšã£ãŠå€§æåã§ãã ããã5ã€ã«ã€ããŠ-以äžã§ããã詳现ã«ã
ãããšã«ã»ã¡ãããŒãžã§ãïŒPADç §åãªã
ããã¥ã¡ã³ããŒã·ã§ã³ã«èšèŒãããŠããããã«ïŒå®éã«ã¯ç°¡æœã«ãè¡éã§ïŒãç°ãªãé·ãã®æååãæ¯èŒããå ŽåãMariaDBãµãŒããŒïŒããã³PerconaãµãŒããŒãšMySQLïŒã¯ãé·ããçãããªããŸã§ïŒã€ãŸããå®éã«ã¯è£å®ãããªããçãæååãã¹ããŒã¹ã§è£å®ããŸãããã ããçµæã¯è£è¶³ã®ããã«ãªããŸãïŒã 次ã®ããã«ãªããŸãã
MariaDB [test]> select "abcd" > "abc"; +----------------+ | "abcd" > "abc" | +----------------+ | 1 | +----------------+ 1 row in set (0.00 sec) MariaDB [test]> select "abc\t" > "abc"; +-----------------+ | "abc\t" > "abc" | +-----------------+ | 0 | +-----------------+ 1 row in set (0.00 sec)
2çªç®ã®å Žåã
'\t'
ã¹ããŒã¹ããå°ãããããé·ãè¡ã¯èŸæžçã«çããããçãã§ãã ããã¯ãã¹ãŠæšæºçã§ãã ããããããã§ã¯ãããŸããã SQLæšæºã§ã¯ãç §åã«ã¯ãã®ããããã£ããããPADSPACEãŸãã¯NOPADã«ãªããŸãã åè ã®å Žåãæ¯èŒãããšããããçãè¡ãã¹ããŒã¹ã«ãã£ãŠéæãããŸãããåŸè ã®å Žåãããã¯èµ·ãããŸããã ãããã£ãŠããããŸã§ã®ãã¹ãŠã®æ¯èŒã¯ããããPADSPACEã§ãããã®ããã«è¡ãããããšãããããŸããã ãããŠä»ããããšã«ã»ã¡ããŽã§ãŒãžã§ãã¯ç§ãã¡ã«ãããç §åãããŸããã å¹æã¯åžžã«é¡èã§ã¯ãããŸãããã次ã®ãšããã§ãã
MariaDB [test]> set collation_connection=utf8_general_nopad_ci; Query OK, 0 rows affected (0.00 sec) MariaDB [test]> select "abc\t" > "abc"; +-----------------+ | "abc\t" > "abc" | +-----------------+ | 1 | +-----------------+ 1 row in set (0.00 sec)
ãã®ãããžã§ã¯ãã¯å®å šã«å®äºããçŸåšMariaDB 10.2.2ã«ãããŸãã
Galina ShalyginaïŒããŒãžäžå¯èœãªãã¥ãŒãžã®æ¡ä»¶ããã·ã¥ããŠã³
ã¬ãªãã¯ç§ãã¡ã«ãšã£ãŠåããŠã§ã¯ãããŸããã 圌女ã¯MariaDBã®æãè€éãªãµãã·ã¹ãã ã®1ã€ã§ããã¯ãšãªãªããã£ãã€ã¶ãŒã«ç²ŸéããŠãããååž°CTEãšéååž°CTEã®
WITH
æŒç®åã®å®è£ ã®äœæè ã§ãã
ãã®GSoCã§ã¯ãGalinaã¯ã¡ã€ã³ã¯ãšãªãšããŒãžã§ããªããã¥ãŒãæé©åããããšãéžæããŸããã ãã¡ãããæè¯ã®æ¹æ³ã¯ãããŒãžã¡ãœããïŒãã¥ãŒããŒãžïŒã䜿çšããŠãã¥ãŒã§ã¯ãšãªãå®è¡ããããšã§ãããã®å Žåããã¥ãŒã¯ã¡ã€ã³ã¯ãšãªã®ãã¯ããšããŠçœ®æãããŸãã ããšãã°ã次ã®ãããªã¯ãšãªïŒ
CREATE VIEW v1 AS SELECT a1+b1 AS c1, d1 FROM t1 WHERE e1>5; SELECT x2 FROM v1, t2 WHERE c1=y2 AND d1=10;
以äžã«å€æã§ããŸãïŒ
SELECT x2 FROM t1, t2 WHERE a1+b1=y2 AND d1=10 AND e1>5 ;
ãããŠãããã§ãªããã£ãã€ã¶ãŒã¯äœ¿çšããããã¹ãŠã®ããŒãã«ããã¹ãŠã®æ¡ä»¶ã確èªããæé©ãªãã©ã³ãéžæã§ããŸãã ãã ãããã¹ãŠã®ãã¥ãŒããã®æ¹æ³ã§æé©åã§ããããã§ã¯ãããŸãããããšãã°ããã¥ãŒã§GROUP BY
ã䜿çšãããŠããå ŽåãããŒãžã¯å®è¡ã§ããŸããã ãã®ãããªå Žåããã¬ãŒã³ããŒã·ã§ã³ãå¥ã®ã¯ãšãªãšããŠå®è¡ããçµæãäžæããŒãã«ã«ä¿åããŠãããã¡ã€ã³ã¯ãšãªã§äœ¿çšããå¿ èŠããããŸãã ãã®çµæããªããã£ãã€ã¶ãŒã¯ãå šäœåããèªèãããäž¡æ¹ã®èŠæ±ãåå¥ã«èæ ®ããããšãäœåãªããããŸãã ã€ãŸããåã®äŸã§ã¯ãããŒãã«
t1
ãããã§ãããããšãã«æ¡ä»¶
d1=10
ã䜿çšã§ããŸããã
ããã§ãæ°ããæé©åãæå¹ã«ãªããŸãã ãã¥ãŒãã¡ã€ã³ã¯ãšãªã«çœ®ãæããããšãã§ããããªããã£ãã€ã¶ãŒãäžæããŒãã«ã䜿çšããŠåå¥ã«èªã¿åãããã«åŒ·å¶ãããå Žåããã®äžæããŒãã«ã«å ¥åãããšãã«ã¡ã€ã³ã¯ãšãªã®æ¡ä»¶ã䜿çšããŠãäœããã®æ¹æ³ã§ãã¥ãŒã«ããã·ã¥ããããã«ãªããŸãã ã€ãŸããäžèšã®äŸã§ã¯ããªããã£ãã€ã¶ãŒã¯ãã®ãããªã¯ãšãªã®çµæãäžæããŒãã«ã«ä¿åããŸãã
SELECT a1+b1 AS c1, d1 FROM t1 WHERE e1>5 AND d1=10;
ããã«ããããªã¯ãšã¹ãã®å®è¡ãæ¡éãã«é«éåã§ããŸãã
ãã®äœæ¥ãå®å šã«çµäºãã10.2.3ã§ãã§ã«å©çšå¯èœã§ã
Shubham BaraiãSachin SetiyaïŒä»»æã®é·ãã®UNIQUEå¶çŽ
ã¿ã¹ã¯ã¯ãä»»æã®é·ãã®äžææ§å¶çŽãå®è£ ããããšã§ããã éåžžãããŒãã«ã®äœææã«èª°ãã
UNIQUE(a,b,c)
æžã蟌ããšãMariaDBïŒPerconaãšMySQLã®äž¡æ¹ïŒããã£ãŒã«ãaãbãcã«ã€ã³ããã¯ã¹ãäœæããŸãã ãããã£ãŠãå¶éãååŸãããŸãããã£ãŒã«ãã®çµã¿åããã®äžææ§ã¯ããããã®ãã£ãŒã«ãã®åèšé·ãã€ã³ããã¯ã¹ããŒã®æ倧蚱容é·ãè¶ ããªãå Žåã«ã®ã¿ä¿èšŒãããŸãã ããããããã¯éè«ççã§ãïŒ ãã€ã³ããã¯ã¹ãã¯ãããŒã¿ãžã®ã¢ã¯ã»ã¹ãæé©åããæ¹æ³ã§ãããSQLæšæºã«ã¯ãŸã£ããå«ãŸããŠããŸããã ãŸããUNIQUEã¯ãSQLæšæºããçŽæ¥ã®ããŒã¿ã®è«ççãªå¶éã§ãããã¯ãšãªã¢ã¯ã»ã©ã¬ãŒã·ã§ã³ã®ç¹å®ã®å®è£ ã®ããã€ãã®å¶éã®ããã«ããªãèŠããã¹ããã¯å®å šã«ã¯äžæã§ãã ç§ãã¡ã®è§£æ±ºçã¯ãé ãããå¥ã®ãã£ãŒã«ããäœæããããšã§ããããŠãŒã¶ãŒã¯ããã衚瀺ããå¿ èŠã¯ãªããUNIQUEã®ç®çã®ããã·ã¥ãããã«æžã蟌ã¿ãŸãã ãŸãããã®ãã£ãŒã«ãã§ã¯ãéåžžã®ã€ã³ããã¯ã¹ããã§ã«äœæã§ããŸãã ãã®äžã«èšé²ãããšãã¯ã競åãæ¢ãå¿ èŠããããŸãã競åãããå Žåã¯ã競åããã¬ã³ãŒããåŒãåºããŠå€ãçŽæ¥æ¯èŒãããšãããã·ã¥ã¯çµå±äžèŽããå¯èœæ§ããããŸãã ããã«ãMyISAMã¯æ¢ã«ãããè¡ãæ¹æ³ãç¥ã£ãŠããããããè¡ã£ãŠããŸã-ããã
SELECT DISTINCT
ä»çµã¿ã§ãã ãããããŠãŒã¶ãŒããŒãã«ã®å Žåãããã¯å©çšã§ããŸããã§ããã ä¿®æ£ãããã£ããã®ã
ãã®ã¿ã¹ã¯ã§ã¯å°é£ãªç¶æ³ãçºçããŸããã GSoCã§æ°å¹ŽéæäŸããŠããŸãããã誰ãæãã§ããŸããã§ããã ãããŠä»å¹Žã2ã€ã®ã¢ããªã±ãŒã·ã§ã³ã圌女ã«å±ããŸããããã©ã¡ããããªãè³¢æã§ãã ãã®åŸã2人ã®çåŸãã¯ãŒãã³ã°ïŒïŒïŒãããã¿ã€ããäœæããŸãããããã¯ãGSoCã®ã¡ã³ã¿ãŒãšããŠ8幎éã§åããŠã®ããšã§ãã ãããŠåã³ãäž¡æ¹ïŒïŒïŒãšèšããŸããã圌ãã¯èšããããã¯ããŸãã«ãç°¡åã§ãInnoDBã§ããããããã ç§ã¯äž¡æ¹ãåããªããã°ãªããŸããã§ããã ãããããã®ãã¡ã®1ã€ãå°ãä¿®æ£ããŸããã
Shubhamã¯InnoDBã®ãžã£ã³ã°ã«ã«é£ã³èŸŒã¿ããã®ã€ã³ããã¯ã¹ããã°ããã©ã³ã¶ã¯ã·ã§ã³ããªã«ããªããã®ä»ã®éæ³ã«å¯ŸåŠãå§ããŸããã ãããŠãSachinã¯MyISAMå ã«ãã®æ©èœãæ¢ã«ååšããŠããããšãå¿ãããµããããŠããããã¿ã€ããæšãŠãã¢ãŒã¿ãŒã«äŸåããªãæ¹æ³ã§ãµãŒããŒã¬ãã«ã§ãã¹ãŠãå®è£ ãå§ããŸããã ãã®çµæãäž¡æ¹ãšãã¿ã¹ã¯ãæ£åžžã«å®äºããäœã¬ãã«ã®å®è£ ã¯ãããã«é«éã«ãªããé«ã¬ãã«ã®å®è£ ã¯ç°ãªããšã³ãžã³ã§åäœãããªããã£ãã€ã¶ãŒã¯ãããã®äžå¯èŠãã£ãŒã«ãã䜿çšããŠã¯ãšãªãæé©åããä»ã®èå³æ·±ãå©ç¹ããããããŸãã ç§ãã¡ã¯ãŸã äœã決ãããã決ããŠããŸãã-ãã¹ãŠããšãŠãããããã§ã... 10.2ã§ã¯ãããããããã«ãã©ãçããªãã§ãããã ãããã10.3ã«ãªããŸãã
ãµãã³ã»ã»ãã£ã€ïŒé ãæ±
ãããŠãããã¯åè¿°ã®ãã³ã§ãã äžå¯èŠãã£ãŒã«ããäœæããããïŒãŸããä»®æ³ã§ããããã®ããã·ã¥ããã£ã¹ã¯ã«æžã蟌ãããšã¯ã§ããŸããïŒãOracleã§ã¯äžå¯èŠåãšåŒã°ããDB2ã§ã¯æé»çã«é衚瀺åãè¿œå ããããšã«ããŸããã ã·ã³ãã«ãªå Žåã¯ããã£ãŒã«ããäœæãããšãã«ããé衚瀺ãã§ããããšã瀺ãããšãã§ããŸãã ãã®åŸã
SELECT *
ããã³
INSERT INTO table VALUE (...)
ã¯èªèãããŸããã æå®ãããå€ã衚瀺ããããããã«å¿ããŠæžã蟌ãã ãããªãã§ãã ããã ãããããã®ãã£ãŒã«ãã«ååãä»ããŠïŒããŒã å ã§ïŒèšåãããšãéåžžã®è¡šç€ºãã£ãŒã«ãã®ããã«åäœããŸãã ããã¯ãåäœäžã®ïŒããããã¯ããŒãºããœãŒã¹ã§ãïŒã¢ããªã±ãŒã·ã§ã³ãå£ããªãããã«ã¹ããŒã ãæ¡åŒµããããšãç®çãšããŠããŸããã é衚瀺ã®ãã£ãŒã«ããè¿œå ãããå€ãã¯ãšãªã§ã¯è¡šç€ºããããæ°ãããã£ãŒã«ãã§ã¯ååã§åŒã³åºãããããããã¹ãŠãæ©èœããŸãã
ç°ãªããäžå¯èŠæ§ã®ã¬ãã«ããè¿œå ããããšã§ããã®ã¢ã€ãã¢ãããããæ¡åŒµããŸããã OracleãšDB2ã®äž¡æ¹ã§ãæåã®ã¬ãã«ã¯äžèšã®ãšããã§ãã ãŸãããŸã ãŒãããããŸã-ãã¹ãŠãèŠãããããã¯é¢çœããªãã§ãã 第2ã¬ãã«-ãã£ãŒã«ãã¯
SELECT
ã§ã®ã¿ãååã§æ瀺çã«èšåãããŠããå Žåã«ã®ã¿è¡šç€ºãããŸãã ã€ãŸãã
INSERT
/
UPDATE
ã¯è¡šç€ºãããŸããããã®å€ã¯å€æŽã§ããŸããã ãŸãã
CREATE
/
ALTER
ã¯è¡šç€ºãããŸãã-äœæãŸãã¯åé€ã§ããŸããã èªåçã«äœæãããŸãã äŸã¯ãROWIDããã³ãã®ä»ã®ç䌌ãã£ãŒã«ãã§ãã 3çªç®ã®ã¬ãã«ã§ã¯ããã£ãŒã«ãã¯ã©ãã«ããŸã£ãã衚瀺ãããŸããã ããã¯ãããã·ã¥ã§é衚瀺ãã£ãŒã«ããäœæããããã«å¿ èŠãªãã®ã§ããã ãŸãã
INDEX(a+b)
ãªã©ã®æ©èœã€ã³ããã¯ã¹ã«ã䜿çšã§ããŸã-ãŸããäžå¯èŠã®ä»®æ³ãã£ãŒã«ããäœæããŠã€ã³ããã¯ã¹ãäœæããŸãã ãããŠãããªãã¯...äžè¬çã«ããã®ãã³ãç»å Žãããšããã¢ã€ãã¢ã¯ããã«æ¥ãŸããã
åã®ã¿ã¹ã¯ã®äžéšãšããŠãããã10.3ã®ã¿ã«åé¡ãããå¯èœæ§ãé«ã
Varun GuptaïŒSQLéçŽé¢æ°
ãŸããé·ãéèããããŠããã¢ã€ãã¢ã ããããå®éã«ã¯ãã®GSOCã®ã¿ãçå®ã§ããŸããã æšæºã§ã¯ã«ã¹ã¿ã SQLé¢æ°ã®äœææ¹æ³ãèŠå®ãããŠãããMariaDBã¯ãã¡ãããããè¡ãããšãã§ããŸãã
CREATE FUNCTION COUNT_X(x INT) RETURNS INT RETURN (SELECT COUNT(*) FROM data_table WHERE value=x);
ãããããããã¯æ®éã®æ©èœã§ãã ãã ããSQLã§éèšé¢æ°ãäœæããããšã¯ã§ããŸããã å°ãªããšãæšæºã«ã¯ãããŸããã OracleãPostgreSQLãããã³HSQLDBãªã©ã«ããããŸãã MariaDBã«ãªãããã£ãã ç§ãã¡ã¯é·ãéæ§æã«ã€ããŠèããŸãã-æšæºã¯ãªãã誰ããç¬èªã®æ¹æ³ãæã£ãŠããŸãã ä»ã®äººãšåæ§ã«æ¯èŒã ãã®çµæã圌ãã¯èªæ ¢ããªãããšã決ããä»ã®ã¿ããªãšåãããã«ãã€ãŸãèªåãã¡ã®ããæ¹ã§ãã£ãã ãã¡ãããç§ãã¡ã®ãªãã·ã§ã³ã¯ããèªç¶ã§ç°¡åã§ãã ãããããOracle / PostgreSQL / HSQLDBã§ãã®æ§æãçºæãã人ãã¡ã¯ã圌ãã®ãªãã·ã§ã³ãæé©ã ãšèããŠããŸãã
次ã®ããã«æ©èœããŸãã
CREATE AGGREGATE FUNCTION agg_and(x INT) RETURNS INT BEGIN DECLARE z INT DEFAULT 65535; DECLARE CONTINUE HANDLER FOR NOT FOUND RETURN z; LOOP FETCH GROUP NEXT ROW; SET z= (z&x); END LOOP; END
æ¯èŒã®ããã«ãèãã©ãããæé·ããããç解ããããã«ãè¡šã®åã®ãã¹ãŠã®å€ã®ANDãèšç®ããå®å šã«èšè¿°ãããæšæºã®ééèšé¢æ°ã次ã«ç€ºããŸãã
CREATE FUNCTION col_and() RETURNS INT BEGIN DECLARE x INT; DECLARE z INT DEFAULT 65535; DECLARE CONTINUE HANDLER FOR NOT FOUND RETURN z; DECLARE cur CURSOR FOR SELECT col FROM data_table; OPEN cur; LOOP FETCH cur INTO x; SET z= (z&x); END LOOP; END
ã€ãŸããããžãã¯ã¯åãã§ãã°ã«ãŒãã®ãã¹ãŠã®å€ãééããéèšé¢æ°ã«ç¹å¥ãªã«ãŒãœã«ãæž¡ãããŸãã
æ®å¿µãªãããããã10.2ã«è©²åœããå¯èœæ§ã¯äœãã§ãã ãããžã§ã¯ããã»ãŒå®äºããŠããŸããã
ä»å¹Žãäœããã®çç±ã§ãããšãã°4åã®3ãŸã§ã«å®äºãããããžã§ã¯ãã¯1ã€ããããŸããã§ããã ã ããæããŠãæ®å¿µã§äžäŸ¿ãæããã 圌ããæãã ããšã¯ãã¹ãŠè¡ãããŸããã ãããŠããã¯çŽ æŽãããããšã§ãïŒ
æ¥å¹Žã楜ãã¿ã«ããŠããŸã...