ã»ãšãã©ã®éçºè ã¯ããã¹ãã»ãããšã¯äœãããã®é·æãšçæãç¥ã£ãŠããŸãã ä»æ¥ãç§ã¯ãã®ææ³ã®ä¿®æ£ã®å®è£ ãå ¬éããããšæããŸããããã¯ãå ã®ã¢ã«ãŽãªãºã ã®æ¬ ç¹ãéšåçã«è§£æ±ºããŸãããæ¬ ç¹ããããŸãã
å ã®ãã¹ããããã»ããã®é·æãšçæã¯äœã§ããïŒ
+ç°¡åãªãªã¯ãšã¹ãã§èŠªãšåããã°ããéžæ;
+ç°¡åãªãªã¯ãšã¹ãã§é£æ¥ããŒãããã°ããéžæã
+ç°¡åãªãªã¯ãšã¹ãã§ç©ºã®ããŒãããã°ããéžæã
+åŒã«åŸã£ãŠãããŒãå ã®ãã¹ãŠã®åã®æ°ãå³åº§ã«åãåããŸãã
+ 1ã€ã®ãµã€ã¯ã«ã§ååž°çã«ããªãŒãæ§ç¯ããªãå¯èœæ§ã
-æ¿å ¥ãšæŽæ°ãéåžžã«é ãã
æ¿å ¥/æŽæ°ãé ãçç±ã¯äœã§ããïŒ ããŒãã®å¢çã®å€ã¯ç¶ç¶çã«ç§»åãããããç¹ã«ããªãŒã®å é ã«æ¿å ¥ããå Žåã¯ãåŸç¶ã®ãã¹ãŠã®ããŒãã®å¢çãåèšç®ããå¿ èŠããããŸãã ããŒãã«ãååã«å€§ããå Žåããã®ããã»ã¹ã¯æ°åç§ãŸãã¯ããã«é·ããã©ãã°ã§ããŸãã ã¢ãã¡ãŒã·ã§ã³ã«ã€ããŠïŒ
å ¥ãåã®éé
ãã¹ããããã»ããã®èŠèŠçè¡šçŸãå«ãåçãæ€èšãããšãã«æãã€ããæåã®èãã¯ããã«ãŒãããŒããå®æ°ã®ãã£ãŒã«ãäžã®ã»ã°ã¡ã³ããšããŠæ³åãããšãå¢çç·ã移åã§ããŸãããã§ãã ã€ãŸããã«ãŒãããŒãã®å¢çã®å€ã0.0ããã³1.0ã§ãããšæ³åããå Žåãä»ã®ããŒãã移åããã«ä»»æã®å Žæã«ããŒããè¿œå ã§ããŸããã¿ãŒã²ããããŒãéã§å®æ°ãåãå¿ èŠããããŸãã ããããã³ã³ãã¥ãŒã¿ãŒã®å®æ°ã«ã¯éçãããããšãå®å šã«ç¥ã£ãŠãããããæŽæ°ãåªå ããŠãã®èããããã«æŸæ£ããŸããã
æŽæ°ã®å Žåãæ¬è³ªã¯åãã§ããã«ãŒãããŒãã®å¢çããŒãããINT_MAXã«ããã ãã§ãã 次ã«ãæ°ããããŒããæ¿å ¥ãããšãã«ãã¿ãŒã²ããããŒãéã«ç©ºããŠãã2ã€ã®å€ãååŸããä»ã«äœã觊ããªãã§ãã ããã æããã«ããã¹ãŠã®å¢çå€ãæãè¿ãèªç±ãªå€ã«ç§»åããŠãæ¿å ¥çšã®ã¹ããŒã¹ããã¯ãªã¢ãããå¿ èŠããããŸãã ãããããã®ãããªãç©ŽããèŠã€ããã®ã¯ã³ã¹ãã®ãããäœæ¥ã§ããããããã®å Žåã®çµæã¯ãåŸæ¥ã®ãã¹ããããã»ãããããããã«é ããªãå¯èœæ§ããããŸãã
å°ãã°ãŒã°ã«ã§ãç§ã¯èªè»¢è»ãçºæããŠããªãã£ãããšã«æ°ä»ããŸããããã®èãã¯é·ãéNested ItervalsãšåŒã°ããŠããŸããã ããããã»ãšãã©ã®ãªãœãŒã¹ã§ã¯ããã®ææ³ã¯ãäžæ¹ã¯æ²»ããããäžæ¹ã¯äžèªç±ã«ãªã£ãããšããåŠå®çãªæ¹æ³ã§æ€èšãããŠãããããç§ã¯æ°ã¥ããŠããŸããã ãããŠãããã¯æ ¹æ ã®ãªãããšã§ã¯ãããŸããããç§ã«ãšã£ãŠéåžžã«èå³æ·±ããã®ã«ãªããŸããããã®ã¢ã«ãŽãªãºã ãã©ã®ããã«åªããŠããããã©ã®ã¢ã«ãŽãªãºã ãæªãããã©ãããããããããã¹ããããã£ãã®ã§ãã
å®è£
ãã¹ããããééã®ã¢ã€ãã¢ãå®è£ ããYii2ã®åäœã®èšè¿°ãéå§ããŸããã æ¿å ¥ã¡ãœãããäœæãããšãã«æåã®åé¡ãçºçããŸãã
insertBefore()
ããã³
insertAfter()
é£æ¥ããŒããŸãã¯èŠªã®å¢çç·ãååŸãã
insertBefore()
ããã³
insertAfter()
ã§æå/æåŸã®ããŒãã®å¢çç·ãååŸããæ¹æ³ ãã¹ããããã»ããã§æãããªå Žåã¯ãçŸåšã®ããŒãã®å¢çã«+ + 1 / -1ã§ãããããããŒã¿ããŒã¹ãžã®è¿œå ã®ã¯ãšãªã¯äžåãããŸããã ãããããµã³ãã«ãé«éã§ããããšã¯è¯ãããšã§ãã
æ°ããããŒããæ¿å ¥ããã®ã«ååãªã¹ããŒã¹ããªãå Žåãå²ãåœãŠãããŠããªãã¹ããŒã¹ã®æ€çŽ¢ã®å®è£ ã«ããªãã®æéãè²»ããããŸããã ããããã®çµæãããŒã¹ã®ååã§ã¯ãªããçŸåšã®ã»ã°ã¡ã³ãããæãè¿ããç©Žãã«å°ããªéšåã®å¢çã移åããæ©äŒãåŸãŸããã
æ¢åã®ãã©ã³ããæ°ããå Žæã«ç§»åãããšãã«ã次ã®å€§ããªçåãçããŸããã ãã®æäœãåãããªãŒå ã§çºçããå Žåã2ã€ã®ãããã¯ã亀æããã ãã§ããã¹ãŠããã°ããå®è¡ã§ããŸãã
ããããå¥ã®ããªãŒãã移åãããšãå€ãã®ç§»åããŒããååšããå¯èœæ§ããããéåžžã®ã¢ã«ãŽãªãºã ã䜿çšããŠããããæ¿å ¥ããã®ã«æéããããããããããåé¡ã®è§£æ±ºãå°é£ã§ããããšãå€æããŸããã æåã¯ãäžè¬çã«ãã®æ©äŒãæŸæ£ããå®è£ ã®è€éãã«èµ·å ããããšãæã¿ãŸããã ããããå°ãåŸã«ãç§ã¯
optimize()
ã¡ãœããã®å¿ èŠæ§ã«æ°ä»ããŸããããã®ã¡ãœããã¯ãæ¢åã®ããŒãã®å¢çãããç¯å²ã«åçã«åæ£ããŸãã ãã®åŸã移åããããŒãã®ããŠã£ã³ããŠããæºåããŠãœãŒã¹ããªãŒãæé©åããããšã«ãããå¥ã®ããªãŒã®ããŒãã移åãããšããã¢ã€ãã¢ãçãŸããŸããã ããã¯ãã¹ãŠéåžžã«ãã£ããåäœããŸãïŒçŸæç¹ã§ã¯ããã®æ¹æ³ã¯MySQLã«å¯ŸããŠã®ã¿æé©åãããŠããŸãïŒããä»ã®ããªãŒãã移åããæäœã¯ã»ãšãã©å¿ èŠãªããåãããªãŒå ã§ã®ç§»åãããé »ç¹ã«å¿ èŠã§ããããšã«æ³šæããŠãã ããã
ãããããµã³ãã«ã®å®è£ ã¯éåžžã«ç°¡åã§ãã-芪ãšåãååŸããäž»ãªæ¹æ³ã¯ãåŸæ¥ã®ãã¹ããããã»ãããšåãã§ãã å/次ã®ãã€ããŒã®ãµã³ãã«ã§ã¯ããå°ãè€éã§ãã2ã€ã®ã¯ãšãªãå¿ èŠã§ãã芪ãååŸããå¶éã®ããç¯å²ã§çŽæ¥æ€çŽ¢ããŸãã ãã ãã空ã®
getLeaves()
ããŒããååŸãããšæ¬åœã«æªãç¶æ ã«ãªããŸãããããã¯ãããã©ãŒãã³ã¹ã«åœ±é¿ããå¯èœæ§ãããå·Šçµåã§è¡ãå¿ èŠãããããã§ãã
æ¿å ¥ã®æé©å
ããã©ãŒãã³ã¹ãã¹ãã®æåã®ã·ãªãŒãºãå®è¡ããåŸãçµæã¯æ§ããã«èšã£ãŠãå°è±¡çã§ã¯ãããŸããã§ããã åé¡ã¯ãæåã«ã»ã°ã¡ã³ãã3ã€ã®éšåã«åå²ããããšã§ãæ¿å ¥ãããããŒãã®å¢çã®éžæãæåã«å®çŸããããšã§ãã ãã®ãããæ°ããããŒãã®ã®ã£ããã¯æ¥éã«æžå°ããŠããŸããã 32ãããPHPã®ç¯å²ã¯[
appendTo()
]ïŒå€§ããæ°å€ã®æäœã¯æµ®åå°æ°ç¹ã«å€æãããïŒã§ããããã
appendTo()
ãä»ããŠã«ãŒãã«åèš19ããŒããæ¿å ¥ãããšã20çªç®ã®ããŒãã«ã¹ããŒã¹ãæ®ããŸããïŒ2147483647/3 ^ 19 =ã1.9ïŒã空ããŠããå ŽæãèŠã€ããŠç§»åããã«ã¯ãé ãæäœãå®è¡ããå¿ èŠããããŸãã ãã®ããããã¡ããæ©èœããŸããã ã¹ããŒã¹ã®å²ãåœãŠã«äœããã®æé©åãå¿ èŠã§ãã ããã«ã¯ãåäœã®ãªãã·ã§ã³ããã§ã«5ã€ãããŸãã
- æåã®äž»èŠãª
amountOptimize
ãã®ãã©ã¡ãŒã¿ãŒã¯ãæ¿å ¥å¯èœãªã»ã°ã¡ã³ãã®åå²ãèšç»ããããŒãã®æ°ã決å®ããŸãã ã€ãŸããå€ã20ã®å Žåã20åã®åããŒããæ¿å ¥ã§ããŸãããããã®åããŒãã¯ã芪ã®ç¯å²ãåçã«å æãããããã©ã®ããã«é²ããã瀺ããŸãã
é åãå€ãšããŠäœ¿çšã§ããŸããå€ã¯ã¬ãã«ããšã«ç°ãªããŸãã
-
noPrepend
ãnoAppend
ãnoInsert
ãããã®ãã©ã¡ãŒã¿ãŒã¯ãå¢çéã®ã¹ããŒã¹ã®äºçŽãããã³æåã®ããŒãã®äœçœ®ãæé©åããã®ã«åœ¹ç«ã¡ãŸããappendTo()
æäœïŒããšãã°ãã³ã¡ã³ãïŒã®ã¿ãappendTo()
å Žåã¯ãnoPrepend = true
ããã³noInsert = true
èšå®ããããšãã§ããŸããããã«ãããæ°ããããŒãã®ã¹ããŒã¹ãã¯ãªã¢ããå°é£ãªã±ãŒã¹ã®å¯èœæ§ãå€§å¹ ã«åæžã§ããŸãã ãããã®ãã©ã¡ãŒã¿ã®å¹æã¯ãåçã§ããæ確ã«ç€ºãããŠããŸãã
amountOptimize = 3
amountOptimize = 3
noPrepend = true
amountOptimize = 3
noAppend = true
amountOptimize = 3
noInsert = true
amountOptimize = 3
noInsert = true
noPrepend = true
amountOptimize = 3
noInsert = true
noAppend = true
noPrepend = true
ãnoPrepend = true
ããå Žåãããã¯prependTo()
ãæ¿å ¥ã§ããªãããšãæå³ãããã®ã§ã¯ãªãããšã«æ³šæããŠprependTo()
ããããã®æäœã®å€ãã¯ãã£ããå®è¡ãããå¯èœæ§ãéåžžã«é«ãã§ãã
- ãããŠãæåŸã®
reserveFactor
ãã©ã¡ãŒã¿ãŒã¯ãå¢çç·éã®ã®ã£ããã®ãµã€ãºã決å®ããŸãã ãŠããã£ã®å Žåãã®ã£ããã®ãµã€ãºã¯æ¿å ¥ãããããŒãã®ãµã€ãºãšçãããªããŸãã Behaviorã®äœ¿çšã·ããªãªã§å€æ°ã®insertBefore()
ããã³insertAfter()
æäœãæ³å®ãããŠããå Žåããã®ãã©ã¡ãŒã¿ãŒãå¢ããå¿ èŠããããŸãã
ããããã¹ãŠã®æäœã®åŸããã¹ãã¯ã¯ããã«ãããããããã®ã«ãªããŸããã
64ããã
BIGINTåã䜿çšããŠ
right
å±æ§ãä¿å
left
ã64ãããPHPã䜿çšããå Žåãããåºãç¯å²ã®åœ¢åŒã§èªç±ãªæé©åã䜿çšã§ããŸãã range = [0ã9223372036854775807]ãã©ã¡ãŒã¿ãŒãèšå®ããã ãã§ãã ããã«ãããæ°ããããŒãçšã®ã¹ããŒã¹ãäžè¶³ãããŸããªã±ãŒã¹ãçºçããŸãã
æ§èœè©Šéš
æ¯èŒã®ããã®åç §ãšããŠãæã人æ°ã®ããåäœãæ¡çšãããŸãããããã¯ãå°æ¬ãããAlexander KochetovïŒCreocoderïŒ creocoder / yii2-nested-setsããNested Setsãå®è£ ããŠããŸã ã ãŸãããœãŒãæ©èœãä¿æããªãããçµæãé£æ¥ãªã¹ããšæ¯èŒããããšãèå³æ·±ããã®ã§ããã ç§ã¯ããã«é©ããã©ã€ãã©ãªãèŠã€ããããªãã£ãã®ã§ããããåããèªåã§æžããŸãã ïŒãããŠãJOINãµããŒãããããŸãããããã¯ä»ã§ã¯ãããŸããïŒã
æåã®2ã€ã®ãã¹ãã¯éåžžã«ç·åçãªãã®ã§ããå®éã«ã¯èª°ããããªãŒãæºããããšã¯ã»ãšãã©ãããŸããããæåã®æ®µéã§ãã®æé ãå¿ èŠã§ããã 圌ãã¯åã«äžå®æ°ã®åäŸã§ã¬ãã«ãäžè²«ããŠæºãããŸãã
ãã¹ãçµæ1ããã³2
ãã§ã«æåã®ãã¹ãã§ãamountOptimizeãã©ã¡ãŒã¿ãŒã®äžé©åãªå€ãã©ãã»ã©æªã圱é¿ãäžãããã確èªã§ããŸãã 32ããããã¹ãã§è¿œå ã®ãªã¯ãšã¹ãã衚瀺ãããŸãããïŒ äžéšã®ããŒãã§ã¯ãã¹ã¯ãªããããå Žæãã¯ãªã¢ãããããã§ãã ããã«ããããããããã®å Žåã§ããããã¹ãŠãã¯ããã«éãéæãããŸããã ãšããã§ããã®ãã¹ãã§ã¯64ããããä¿åããããæªããç¶æ³ã¯1ã€ããããŸããã§ããã
DBã¯ãšãªå®è¡ã¡ã¢ãªæé ãã¹ã1. 12人ã®åäŸã«ã¬ãã«3ãæºããã ãã¹ããããã»ãã7696 6.961 ms 26.305 ms 135.8 MB Itervalsããã©ã«ãïŒé= 10ïŒ6377 2.850 ms 11.920 ms 87.3 MB Itervals x64ããã©ã«ãïŒé= 10ïŒ5813 1.992 ms 10.963 ms 78.7 MB å埩é= 24 5813 1,765ããªç§10,442ããªç§78.7 MB Itervalsã®é= 12 noPrepend noInsert 5813 1.750 ms 10.223 ms 78.7 MB é£æ¥ãªã¹ã5811 1,567ããªç§9,591ããªç§71.3 MB ãã¹ã2. 3人ã®åäŸã«ã¬ãã«6ãæºãããŸãã ãã¹ããããã»ãã4735 5.701 ms 19.784 ms 82.2 MB Itervalsã®ããã©ã«ãïŒé= 10ïŒ3644 1,275 ms 5,976 ms 48.9 MB Itervalsã®é= 3 noPrepend noInsert 3644 1.271 ms 5.993 ms 48.9 MB é£æ¥ãªã¹ã3642 982 ms 5.812 ms 44.5 MB
ãã§ã«æåã®ãã¹ãã§ãamountOptimizeãã©ã¡ãŒã¿ãŒã®äžé©åãªå€ãã©ãã»ã©æªã圱é¿ãäžãããã確èªã§ããŸãã 32ããããã¹ãã§è¿œå ã®ãªã¯ãšã¹ãã衚瀺ãããŸãããïŒ äžéšã®ããŒãã§ã¯ãã¹ã¯ãªããããå Žæãã¯ãªã¢ãããããã§ãã ããã«ããããããããã®å Žåã§ããããã¹ãŠãã¯ããã«éãéæãããŸããã ãšããã§ããã®ãã¹ãã§ã¯64ããããä¿åããããæªããç¶æ³ã¯1ã€ããããŸããã§ããã
ãã¹ã3ã5ã¯ã倧ããªããŒãã«ã®ããŸããŸãªå Žæã«20åã®ããŒããæ¿å ¥ããããšãæš¡å£ããŸãã
3-5ãã¹ãçµæ
ããŒã¿ããŒã¹ã®å é ã«æ¿å ¥ãããã¹ãã¯ãåŸæ¥ã®ãã¹ãã»ããã®åŒ±ç¹ãéåžžã«æ確ã«ç€ºããŠããŸã-ããŒã¿ããŒã¹ã®å é ã«æ¿å ¥ããã«ã¯ãããŒã¿ããŒã¹å šäœã®å¢çãæŽæ°ããå¿ èŠããããŸãã ãããã£ãŠãå£æ» çãªçµæã ããŒã¿ããŒã¹ã®æåŸã«æ¿å ¥ããçµæã®ã¿ãããã¹ããããItervalsãšç«¶åããŸãã ã¡ãªã¿ã«ã䞊ã¹æ¿ãã確å®ã«è¡ãã«ã¯
ãå®è¡ããå¿ èŠããããããé£æ¥ãªã¹ããäœéã§ããããšã«æ³šæããŠãã ããã
DBã¯ãšãªå®è¡ã¡ã¢ãªæé ãã¹ã3.å é ã«æ¿å ¥<4ïŒ ïŒ19657ãããã§20ïŒ ãã¹ããããã»ãã100 15,597 ms 16,636 ms 5.0 MB Itervals 82 21 ms 150 ms 4.7 MB é£æ¥ãªã¹ã100170ããªç§439ããªç§4.6 MB ãã¹ã4.äžå€®ã«æ¿å ¥> 46ïŒ <50ïŒ ïŒ19657ãããã§20ïŒ ãã¹ããããã»ãã100 8,200 ms 8,985 ms 5.0 MB Itervals 82269ããªç§593ããªç§4.7 MB é£æ¥ãªã¹ã100163 ms 454 ms 4.7 MB ãã¹ã5.æåŸã«æ¿å ¥> 96ïŒ ïŒ19657ãããã§20ïŒ ãã¹ããããã»ãã100 549 ms 911 ms 5.0 MB Itervals 83 46 ms 187 ms 4.7 MB é£æ¥ãªã¹ã106159 ms 435 ms 4.7 MB
ããŒã¿ããŒã¹ã®å é ã«æ¿å ¥ãããã¹ãã¯ãåŸæ¥ã®ãã¹ãã»ããã®åŒ±ç¹ãéåžžã«æ確ã«ç€ºããŠããŸã-ããŒã¿ããŒã¹ã®å é ã«æ¿å ¥ããã«ã¯ãããŒã¿ããŒã¹å šäœã®å¢çãæŽæ°ããå¿ èŠããããŸãã ãããã£ãŠãå£æ» çãªçµæã ããŒã¿ããŒã¹ã®æåŸã«æ¿å ¥ããçµæã®ã¿ãããã¹ããããItervalsãšç«¶åããŸãã ã¡ãªã¿ã«ã䞊ã¹æ¿ãã確å®ã«è¡ãã«ã¯
SELECT MAX(sort)
ãå®è¡ããå¿ èŠããããããé£æ¥ãªã¹ããäœéã§ããããšã«æ³šæããŠãã ããã
次ã®ãã¹ãã§ã¯ãããªãŒã®å é ãã20åã®ããŒããåé€ãããŸãã
ãã¹ãçµæ6
ããã§ã®ç¶æ³ã¯ãã¹ã3ã«äŒŒãŠããŸãããæªãç¶æ³ããåé€ãããšãããééãã§ãæªãç¶æ³ããçºçããªããªããšããäºå®ã«éããããã ãã§ãã
DBã¯ãšãªå®è¡ã¡ã¢ãªæé ãã¹ã6.æåããã®åé€<4ïŒ ïŒ19657ããŒãäž20ããŒãïŒ ãã¹ããããã»ãã100 16.554 ms 17.678 ms 4.8 MB Itervals 60164 ms 250 ms 4.2 MB é£æ¥ãªã¹ãparentJoin = 0 childrenJoin = 0 60 169 ms 257 ms 3.8 MB é£æ¥ãªã¹ãparentJoin = 3 childrenJoin = 3 60 87 ms 162 ms 3.8 MB
ããã§ã®ç¶æ³ã¯ãã¹ã3ã«äŒŒãŠããŸãããæªãç¶æ³ããåé€ãããšãããééãã§ãæªãç¶æ³ããçºçããªããªããšããäºå®ã«éããããã ãã§ãã
ãã¹ã7ã¯ãã³ã¡ã³ãã«Behaviorã䜿çšããããšãæš¡å£ããŠãããããéåžžã«æããã«ãªã£ãŠããŸãã ãµã€ã¯ã«ã§ã¯ãã©ã³ãã ã«éžæãããããŒãã«ã¬ãã«å¶éä»ãã§1000åã®ããŒããè¿œå ãããŸãã ãã¹ã8ãåæ§ã§ãããããã«å³ããæ¡ä»¶ããããŸããè¿œå ã ãã§ãªããä»ã®æäœãèš±å¯ãããŸãã
ãã¹ãçµæ7ããã³8
ç®ãåŒãã®ã¯ãééã䜿çšããŠæ¿å ¥ã®æé©åãã©ã¡ãŒã¿ãŒãæ£ããæ§æãããšãã®éèŠæ§ã§ãããã®äŸã§ã¯ãããã©ã«ãèšå®ãéåžžã«æ²ããçµæããããããããã§ãã ããããæé©åã«ããããã¹ãŠãéåžžã«è¿ éã«æ©èœããé£æ¥ãªã¹ãã«å¹æµããŸãã ãšããã§ã8åç®ã®ãã¹ãã§ã¯ããœãŒãã確å®ã«ããããã«ãå Žæã空ãããå¿ èŠãããããã圌ã¯ããªãé ããªããŸããã
DBã¯ãšãªå®è¡ã¡ã¢ãªæé ãã¹ã7. appendToïŒïŒãã©ã³ãã ããŒãã«ïŒ5ã¬ãã«ã1000ããŒãïŒ ãã¹ããããã»ãã5002 5.989 ms 17.406 ms 80.7 MB Itervalsã®ããã©ã«ãïŒé= 10ïŒ8497 23,301ããªç§41,060ããªç§120.7 MB Itervals x64ããã©ã«ãïŒé= 10ïŒ7092 11.330ããªç§23.618ããªç§97.5 MB Itervalsã®é= 200.25 noPrepend noInsert 4009 1.431 ms 6.490 ms 50.2 MB Itervals x64ã®é= 250.30 noPrepend noIns 4003 1.421 ms 6.615 ms 50.0 MB é£æ¥ãªã¹ã4001 1,062 ms 5,976 ms 46.1 MB ãã¹ã8.ã©ã³ãã ããŒãã§ã®ä»»ææäœïŒ5ã¬ãã«ã1000ããŒãïŒ ãã¹ããããã»ãã5002 9.383 ms 23.502 ms 80.7 MB Itervalsã®ããã©ã«ãïŒé= 10ïŒ7733 8.123ããªç§24.031ããªç§107.2 MB Itervals x64ããã©ã«ãïŒé= 10ïŒ5663 3,761 ms 14,084 ms 75.6 MB Itervalsé= 200.25äºçŽ= 2 4175 1,548ããªç§7,223ããªç§52.8 MB Itervals x64é= 250.30ãªã¶ãŒã= 2 4003 1.541 ms 6.753 ms 50.0 MB é£æ¥ãªã¹ã4395 4,394 ms 12,377 ms 53.4 MB
ç®ãåŒãã®ã¯ãééã䜿çšããŠæ¿å ¥ã®æé©åãã©ã¡ãŒã¿ãŒãæ£ããæ§æãããšãã®éèŠæ§ã§ãããã®äŸã§ã¯ãããã©ã«ãèšå®ãéåžžã«æ²ããçµæããããããããã§ãã ããããæé©åã«ããããã¹ãŠãéåžžã«è¿ éã«æ©èœããé£æ¥ãªã¹ãã«å¹æµããŸãã ãšããã§ã8åç®ã®ãã¹ãã§ã¯ããœãŒãã確å®ã«ããããã«ãå Žæã空ãããå¿ èŠãããããã圌ã¯ããªãé ããªããŸããã
ããªãŒå ã®ããŒãã移åããããã®æ¬¡ã®2ã€ã®ãã¹ãïŒ
ãã¹ãçµæ9ããã³10
ååãšããŠããã¹ããããã»ããã§ã¯ããã¹ããããééã§ã¯ããã®æäœã¯åæã«å®è¡ããå¿ èŠããããŸãããCreocoderã®ã³ãŒãã§ã¯ãããã¯æé©ã«æ©èœããŸãããããŒã¹ããæåŸãŸã§ç§»åããŠãããç®çã®ãããã¯ã移åããããŒã¹å šäœãåã³æ»ããŸãã ããããCreocoderã§ã¯ã深床å±æ§ã«ç¬Šå·ãªããã£ãŒã«ãã䜿çšã§ããŸãããŸããç§ã®åäœã§ã¯ã移åãããšäžæçã«è² ã«ãªããŸãã ãšã³ãããŒãšã³ãã®çµæã¯åçã§ãããé£æ¥ãªã¹ãã«ã¯å€§ããªå©ç¹ããããŸãã
DBã¯ãšãªå®è¡ã¡ã¢ãªæé ãã¹ã9.éå§æã®ããŒãã®ç§»å<4ïŒ ïŒ19657ããŒãã®ãã¡20ããŒãïŒ ãã¹ããããã»ãã200 24,312 ms 25,479 ms 6.3 MB Itervals 160180 ms 573 ms 6.0 MB é£æ¥ãªã¹ã111107 ms 318 ms 4.6 MB ãã¹ã10.ããŒããæåŸããæåã«ç§»åãã<4ïŒ > 96ïŒ ïŒ19657ããŒãã®ãã¡20ããŒãïŒ ãã¹ããããã»ãã200 16,999 ms 17,973 ms 6.3 MB Itervals 160 16,972ããªç§17,854ããªç§6.0 MB é£æ¥ãªã¹ã108 86 ms 325 ms 4.6 MB
ååãšããŠããã¹ããããã»ããã§ã¯ããã¹ããããééã§ã¯ããã®æäœã¯åæã«å®è¡ããå¿ èŠããããŸãããCreocoderã®ã³ãŒãã§ã¯ãããã¯æé©ã«æ©èœããŸãããããŒã¹ããæåŸãŸã§ç§»åããŠãããç®çã®ãããã¯ã移åããããŒã¹å šäœãåã³æ»ããŸãã ããããCreocoderã§ã¯ã深床å±æ§ã«ç¬Šå·ãªããã£ãŒã«ãã䜿çšã§ããŸãããŸããç§ã®åäœã§ã¯ã移åãããšäžæçã«è² ã«ãªããŸãã ãšã³ãããŒãšã³ãã®çµæã¯åçã§ãããé£æ¥ãªã¹ãã«ã¯å€§ããªå©ç¹ããããŸãã
BehaviorãæžããåŸãåäœã®ä»£ããã«Traitã䜿çšããå©ç¹ãç¥ããããšæããŸããã ããã§ãéçå±æ§ã䜿ã£ãŠTraitã«ç§»æ€ããŸããã Traitã䜿çšããããªã¢ã³ãã§ãããããªããµã³ããªã³ã°ãã¹ããå®è¡ãããŸããã ããããäžçŽç©ãç©ããã«äœ¿çšããçµæã¯ãç¹ã«ããããåå ã§ã³ãŒããã©ãã ãmoreããªãããèãããšãå°è±¡çã§ã¯ãããŸããã§ããã
ãã¹ãŠã®èŠçŽ ã®ç°¡åãªéžæ
Model::find()->all()
ïŒ
ãã¹ãçµæ11
ãã®ãã¹ãã¯ãäž»ã«ã¡ã¢ãªæ¶è²»ã®åäœãšæ¯èŒããããã«äœæãããŸããã ç¹æ§ã ãããŠãç§ãã¡ãèŠãããã«ãéãã¯ãããŸãããéèŠã§ã¯ãããŸããã
DBã¯ãšãªå®è¡ã¡ã¢ãªæé ãã¹ã11.ãã¹ãŠã®ããŒãã®éžæïŒ19657åïŒ ãã¹ããããã»ãã1 40 ms 1,108 ms 215.2 MB Itervals 1 42ããªç§1,247ããªç§225.3 MB Itervalsç¹æ§1 41ããªç§1,174ããªç§207.4 MB é£æ¥ãªã¹ã1 33 ms 890 ms 179.1 MB
ãã®ãã¹ãã¯ãäž»ã«ã¡ã¢ãªæ¶è²»ã®åäœãšæ¯èŒããããã«äœæãããŸããã ç¹æ§ã ãããŠãç§ãã¡ãèŠãããã«ãéãã¯ãããŸãããéèŠã§ã¯ãããŸããã
åå«ã®ãµã³ããªã³ã°ïŒ
ãã¹ãçµæ12
ãã¹ããããã»ãããšãã¹ããããééã§åãéžæããèŠæ±ã¯åãã§ããå¿ èŠããããŸãããCreocoderã®ã©ã€ãã©ãªã®å¥ã®æ¬ ç¹ãããã§æããã«ãªããŸãã-åå«ãæé©ã«éžæãããŠããŸããã åå«ã¯ãå·ŠãŸãã¯å³ã®å±æ§
ããããã«åŸã£ãŠã€ã³ããã¯ã¹ã䜿çšããŠå³åº§ã«éžæã§ããŸããã代ããã«ã€ã³ããã¯ã¹ã¯
ååã®ã¿äœ¿çšãããŸãã EXPLAINomãåæãããšãæåã®ãªãã·ã§ã³ãã¯ããã«æãŸããããšãæããã«ãªããŸãã é£æ¥ãªã¹ãã®çµæã¯å£ã£ãŠããŸãããé©ãããšã§ã¯ãããŸããã
DBã¯ãšãªå®è¡ã¡ã¢ãªæé ãã¹ã12.åãšåå«ã®éžæïŒ19657ããŒãã®ããªãŒã®äžå€®ã«ãã819ããŒãã®å ŽåïŒ ãã¹ããããã»ãã1641 6.397 ms 7.498 ms 24.9 MB Itervalsåäœ1641 579ããªç§1.657ããªç§25.0 MB Itervalsç¹æ§1641 615ããªç§1,590ããªç§24.3 MB é£æ¥ãªã¹ãparentJoin = 0 childrenJoin = 0 2562 720 ms 1.969 ms 36.9 MB é£æ¥ãªã¹ãparentJoin = 3 childrenJoin = 3 2461 704 ms 1.966 ms 35.3 MB
ãã¹ããããã»ãããšãã¹ããããééã§åãéžæããèŠæ±ã¯åãã§ããå¿ èŠããããŸãããCreocoderã®ã©ã€ãã©ãªã®å¥ã®æ¬ ç¹ãããã§æããã«ãªããŸãã-åå«ãæé©ã«éžæãããŠããŸããã åå«ã¯ãå·ŠãŸãã¯å³ã®å±æ§
`lft` > :leftValue && `lft` < :rightValue
ããããã«åŸã£ãŠã€ã³ããã¯ã¹ã䜿çšããŠå³åº§ã«éžæã§ããŸããã代ããã«ã€ã³ããã¯ã¹ã¯
`lft` > :leftValue && `rgt` < :rightValue
ååã®ã¿äœ¿çšãããŸãã EXPLAINomãåæãããšãæåã®ãªãã·ã§ã³ãã¯ããã«æãŸããããšãæããã«ãªããŸãã é£æ¥ãªã¹ãã®çµæã¯å£ã£ãŠããŸãããé©ãããšã§ã¯ãããŸããã
å ç¥ã®ãµã³ãã«ïŒ
ãã¹ãçµæ13
ããã§ã¯ããã¹ããããã»ãããšãã¹ããããééã¯åãåäœãããŸãããããªãé ãã§ãã ãã€ã³ãã¯ãéåžžã®ã€ã³ããã¯ã¹ãååšãããäžå¹žãªäžé£ã®ç¶æ³ãããããšã§ããããŒãã«ã®äžå€®ã®äž¡æ¹ã®ã€ã³ããã¯ã¹ã«ã¯å€ãã®èŠçŽ ããããŸãã åœç¶ã®ããšãªãããé£æ¥ãªã¹ãã¯ã¡ã¢ãªãç ç²ã«ããŸããããããé«éã«æ©èœããŸããïŒãã ããããã¯ãŸã åçŽãª3ã¬ãã«ã®ããªãŒã®åé¡ã§ãïŒã
DBã¯ãšãªå®è¡ã¡ã¢ãªæé ãã¹ã13.芪ã®éžæïŒ19657ããŒãã®ããªãŒã®äžå€®ã«ãã819ããŒãã®å ŽåïŒ ãã¹ããããã»ãã821 3.344 ms 4.069 ms 20.6 MB Itervals Behavior 821 3.292ããªç§4.147ããªç§22.0 MB Itervals Trait 821 3,310ããªç§4,080ããªç§21.1 MB é£æ¥ãªã¹ãparentJoin = 0 childrenJoin = 0 3180 948 ms 2.304 ms 51.2 MB é£æ¥ãªã¹ãparentJoin = 3 childrenJoin = 3 1641 486 ms 1.495 ms 30.8 MB
ããã§ã¯ããã¹ããããã»ãããšãã¹ããããééã¯åãåäœãããŸãããããªãé ãã§ãã ãã€ã³ãã¯ãéåžžã®ã€ã³ããã¯ã¹ãååšãããäžå¹žãªäžé£ã®ç¶æ³ãããããšã§ããããŒãã«ã®äžå€®ã®äž¡æ¹ã®ã€ã³ããã¯ã¹ã«ã¯å€ãã®èŠçŽ ããããŸãã åœç¶ã®ããšãªãããé£æ¥ãªã¹ãã¯ã¡ã¢ãªãç ç²ã«ããŸããããããé«éã«æ©èœããŸããïŒãã ããããã¯ãŸã åçŽãª3ã¬ãã«ã®ããªãŒã®åé¡ã§ãïŒã
é£æ¥ããŒãããã³ç©ºããŒãã®éžæïŒ
ãã¹ãçµæ14ããã³15
ããã§ã¯ãäºæ³ã©ããããã¹ããããééã®åŒ±ç¹ãèŠãããŸãã 圌ããèšãããã«ãã³ã¡ã³ãã¯ãããŸããã
DBã¯ãšãªå®è¡ã¡ã¢ãªæé ãã¹ã14.é£æ¥ããŒãã®éžæïŒ19657ããŒãã®ããªãŒã®äžå€®ã«ãã819ããŒãã®å ŽåïŒ ãã¹ããããã»ãã1641 520 ms 1.424 ms 24.3 MB Itervalsåäœ1641 19.681ããªç§21.326ããªç§27.5 MB Itervals Trait 1641 19.666ããªç§21.251ããªç§26.5 MB é£æ¥ãªã¹ãparentJoin = 0 childrenJoin = 0 1641 535 ms 1,442 ms 23.7 MB é£æ¥ãªã¹ãparentJoin = 3 childrenJoin = 3 1641 508 ms 1,421 ms 23.6 MB ãã¹ã15.空ã®ããŒãã®éžæïŒ19657ããŒãã®ããªãŒã®äžå€®ã«ãã819ããŒãã®å ŽåïŒ ãã¹ããããã»ãã821 3,215 ms 3,814 ms 18.8 MB Itervalsã®åäœ821 10,450ããªç§11,166ããªç§18.8 MB Itervals Trait 821 10.425ããªç§11.040ããªç§18.7 MB é£æ¥ãªã¹ãparentJoin = 0 childrenJoin = 0 1833 568 ms 1,743 ms 32.6 MB é£æ¥ãªã¹ãparentJoin = 3 childrenJoin = 3 1732 556 ms 1.891 ms 31.3 MB
ããã§ã¯ãäºæ³ã©ããããã¹ããããééã®åŒ±ç¹ãèŠãããŸãã 圌ããèšãããã«ãã³ã¡ã³ãã¯ãããŸããã
çµè«
å ¥ãåã®éé-çããæš©å©ããããŸãã å©ç¹ãšæ¬ ç¹ã®äž¡æ¹ããããŸãã
+ã¯ã€ãã¯æ¿å ¥ïŒæé©åãã©ã¡ãŒã¿ãŒã®é©åãªéžæã®å¯Ÿè±¡ïŒ;
+åå«ãæã€ããŒãã®è¿ éãªåé€ã
+ç¥å ãšåå«ã®ãµã³ãã«ã®ãã¹ãã»ãããšåãé床ã
+ãŸãã1ãµã€ã¯ã«ã§éååž°çã«ããªãŒãæ§ç¯ããå¯èœæ§ãæ®ã£ãŠããŸãã
-è¿é£ããŒãã®åä¿¡ãé ãã
-空ã®ããŒãã®åä¿¡ãé ãã
-ããŒãå ã®åå«ã®æ°ãå³åº§ã«èšç®ããæ¹æ³ã¯ãããŸããã
Yii2ã®å®è£
ãããã®æ¹æ³ã¯ãCreocoderã®åäœã§ææ¡ãããŠããæ¹æ³ãšã¯ãããã«ç°ãªãããšã«æ³šæããŠãã ããã æåã«ãã¡ãœããã®ååã
getParents() getDescendants()
ã«å€æŽããŸãããããã«ããããªã¬ãŒã·ã§ã³ãšåæ§ã«ãé¢é£ããããŒããžã®ã¢ã¯ã»ã¹ãå®è£ ã§ããŸããããã«ãããããŒã¿ããŒã¹ã«2次ã¯ãšãªãäœæã§ããŸããã
$node = Node::findOne(['name' => 'test']); $children = $node->children; // relation $children = $node->getChildren()->all(); // query
ããã«ãä¿åããYiiãã©ã¡ãŒã¿ãŒïŒ$ runValidationã$ attributeNamesïŒãããã·ã¥ããã代ããã«ã¢ã¯ã·ã§ã³ã®æ瀺ãšããŠã¡ãœãããå®è£ ã
->asArray()->
ïŒïŒ
$node = new Node(); $node->makeRoot()->save(false); $node->insertAfter($node2)->save();
GitHubã§ã®ãã¹ããããééã®å®è£ ã
GitHubã§ã®é£æ¥ãªã¹ãã®å®è£ ã