ããªãPostgreSQLã§ããïŒã PostgreSQLã®ã¹ããŒã¬ã³ã¯ããäžçã§æãå é²çãªãªãŒãã³ãœãŒã¹ããŒã¿ããŒã¹ãã§ãããšäž»åŒµããŠããŸãã Postgresããã®ãããªã¹ããŒãã¡ã³ããäœæããçç±ãããã€ã説æããŸãã
ãã®ã·ãªãŒãºã®æåã®éšåã§ã¯ãããŒã¿ã¹ãã¬ãŒãžãã€ãŸãã¢ãã«ãæ§é ãã¿ã€ãããµã€ãºå¶éã«ã€ããŠèª¬æããŸãã ãããŠã 第2éšã§ã¯ããµã³ããªã³ã°ãšããŒã¿æäœã«éç¹ã眮ããŸãã
ããŒã¿ã¢ãã«
PostgreSQLã¯åãªããªã¬ãŒã·ã§ãã«ã§ã¯ãªãããªããžã§ã¯ããªã¬ãŒã·ã§ãã«DBMSã§ãã ããã«ãããMySQLãMariaDBãFirebirdãªã©ã®ä»ã®ãªãŒãã³ãœãŒã¹SQLããŒã¿ããŒã¹ã«æ¯ã¹ãŠããã€ãã®å©ç¹ãåŸãããŸãã
ãªããžã§ã¯ããªã¬ãŒã·ã§ãã«ããŒã¿ããŒã¹ã®åºæ¬çãªç¹åŸŽã¯ãããŒã¿åãæ©èœãæäœããã¡ã€ã³ãã€ã³ããã¯ã¹ãªã©ã®ãŠãŒã¶ãŒãªããžã§ã¯ããšãã®åäœã®ãµããŒãã§ãã ããã«ãããPostgresã¯éåžžã«æè»ã§ä¿¡é Œæ§ãé«ããªããŸãã ãšããããè€éãªããŒã¿æ§é ãäœæãä¿åãååŸã§ããŸãã 以äžã®ããã€ãã®äŸã§ã¯ãæšæºã®RDBMSã§ãµããŒããããŠããªããã¹ããããè€åæ§é ã衚瀺ãããŸãã
æ§é ãšããŒã¿å
PostgresããµããŒãããããŒã¿åã®åºç¯ãªãªã¹ãããããŸãã æ°å€ãæµ®åå°æ°ç¹ãããã¹ããããŒã«å€ããã®ä»ã®äºæ³ãããããŒã¿åïŒããã³ãããã®å€ãã®ããªãšãŒã·ã§ã³ïŒã«å ããŠãPostgreSQLã¯uuidãmoneyãenumeratedãgeometricãbinaryåããããã¯ãŒã¯ã¢ãã¬ã¹ããããæååãããã¹ãæ€çŽ¢ãxmlãjsonã®ãµããŒããèªã£ãŠããŸããé åãè€åã¿ã€ããšç¯å²ãããã³ãªããžã§ã¯ããšãã°ã®å Žæãèå¥ããããã®ããã€ãã®å éšã¿ã€ãã MySQLãMariaDBãFirebirdã«ããããã®ããŒã¿åã®äžéšããããšèšã£ãŠãéèšã§ã¯ãããŸããããããããã¹ãŠããµããŒãããŠããã®ã¯Postgresã ãã§ãã
ãããã®ããã€ãã詳ããèŠãŠã¿ãŸãããïŒ
ãããã¯ãŒã¯ã¢ãã¬ã¹
PostgreSQLã¯ãããŸããŸãªã¿ã€ãã®ãããã¯ãŒã¯ã¢ãã¬ã¹çšã®ã¹ãã¬ãŒãžãæäŸããŸãã CIDRããŒã¿åïŒã¯ã©ã¹ã¬ã¹ã€ã³ã¿ãŒããããã¡ã€ã³ã«ãŒãã£ã³ã°ïŒã¯ãIPv4ããã³IPv6ãããã¯ãŒã¯ã¢ãã¬ã¹ã®èŠåã«åŸããŸãã 以äžã«äŸã瀺ããŸãã
- 192.168.100.128/25
- 10.1.2.3/32
- 2001ïŒ4f8ïŒ3ïŒbaïŒ2e0ïŒ81ffïŒfe22ïŒd1f1 / 128
- :: ffffïŒ1.2.3.0/128
ãŸãããµããããããªãã·ã§ã³ã§ããIPv4ããã³IPv6ãã¹ãã«äœ¿çšãããINETããŒã¿ã¿ã€ããããããã¯ãŒã¯ã¢ãã¬ã¹ã®æ ŒçŽã«äœ¿çšã§ããŸãã MACADDRããŒã¿ã¿ã€ãã¯ã08-00-2b-01-02-03ãªã©ã®æ©åšèå¥çšã®MACã¢ãã¬ã¹ãæ ŒçŽããããã«äœ¿çšã§ããŸãã
MySQLããã³MariaDBã«ã¯ããããã¯ãŒã¯ã¢ãã¬ã¹ãå€æããããã®INETé¢æ°ããããŸããããããã¯ãŒã¯ã¢ãã¬ã¹ã®å éšã¹ãã¬ãŒãžçšã®ããŒã¿åã¯æäŸããŸããã Firebirdã«ã¯ããããã¯ãŒã¯ã¢ãã¬ã¹ãä¿åããããã®ã¿ã€ãããããŸããã
å€æ¬¡å é å
Postgresã¯ãªããžã§ã¯ããªã¬ãŒã·ã§ãã«ããŒã¿ããŒã¹ã§ãããããã»ãšãã©ã®æ¢åã®ããŒã¿åã«å¯ŸããŠå€ã®é åãæ ŒçŽã§ããŸãã ããã¯ãåã®ããŒã¿åã®æå®ã«è§ãã£ããè¿œå ããããARRAYåŒã䜿çšããŠå®è¡ã§ããŸãã é åã®ãµã€ãºãæå®ã§ããŸãããããã¯ãªãã·ã§ã³ã§ãã äŒæ¥ã®ãã¯ããã¯ã¡ãã¥ãŒãèŠãŠãé åã®äœ¿çšæ¹æ³ã瀺ããŸãããã
-- , CREATE TABLE holiday_picnic ( holiday varchar(50) -- sandwich text[], -- side text[] [], -- dessert text ARRAY, -- beverage text ARRAY[4] -- 4- ); -- INSERT INTO holiday_picnic VALUES ('Labor Day', '{"roast beef","veggie","turkey"}', '{ {"potato salad","green salad","macaroni salad"}, {"chips","crackers"} }', '{"fruit cocktail","berry pie","ice cream"}', '{"soda","juice","beer","water"}' );
MySQLãMariaDBãããã³Firebirdã¯ãããè¡ããŸããã ãã®ãããªå€ã®é åãåŸæ¥ã®ãªã¬ãŒã·ã§ãã«ããŒã¿ããŒã¹ã«æ ŒçŽããã«ã¯ãåé¿çã䜿çšããŠãé åã®åå€ã«å¯Ÿå¿ããè¡ãæã€åå¥ã®ããŒãã«ãäœæããå¿ èŠããããŸãã
幟äœåŠçããŒã¿
ãã±ãŒã·ã§ã³ããŒã¿ã¯ãå€ãã®ã¢ããªã±ãŒã·ã§ã³ã«ãšã£ãŠæ¥éã«äž»èŠãªèŠä»¶ã«ãªãã€ã€ãããŸãã PostgreSQLã¯ãç¹ãç·ãåãå€è§åœ¢ãªã©ãå€ãã®å¹ŸäœããŒã¿åãé·ãéãµããŒãããŠããŸããã ãããã®ã¿ã€ãã®1ã€ã¯PATHã§ãããå€ãã®é£ç¶ãããã€ã³ãã§æ§æãããéããŠããïŒéå§ãã€ã³ããšçµäºãã€ã³ããæ¥ç¶ãããŠããªãïŒããéããŠããïŒéå§ãã€ã³ããšçµäºãã€ã³ããæ¥ç¶ãããŠããïŒããšãã§ããŸãã ãã€ãã³ã°ã³ãŒã¹ã®äŸãèŠãŠã¿ãŸãããã ãã®å Žåããã€ãã³ã°ãã¬ã€ã«ã¯ã«ãŒãã§ãããããå§ç¹ãšçµç¹ãæ¥ç¶ãããŠãããããç§ã®ãã¹ã¯éããããŸãã äžé£ã®åº§æšãå²ãæ¬åŒ§ã¯éãããã¹ã瀺ããè§æ¬åŒ§ã¯éãããã¹ã瀺ããŸãã
-- CREATE TABLE trails ( trail_name varchar(250), trail_path path ); -- , -- - INSERT INTO trails VALUES ('Dool Trail - Creeping Forest Trail Loop', ((37.172,-122.22261666667), (37.171616666667,-122.22385), (37.1735,-122.2236), (37.175416666667,-122.223), (37.1758,-122.22378333333), (37.179466666667,-122.22866666667), (37.18395,-122.22675), (37.180783333333,-122.22466666667), (37.176116666667,-122.2222), (37.1753,-122.22293333333), (37.173116666667,-122.22281666667)));
PostgreSQLçšã®PostGISæ¡åŒµæ©èœã¯ãè£å©çãªç©ºéã¿ã€ããé¢æ°ãæŒç®åãããã³ã€ã³ããã¯ã¹ã䜿çšããŠããžãªã¡ããªããŒã¿ã®æ¢åã®ããããã£ãæ¡åŒµããŸãã ãã±ãŒã·ã§ã³ã®ãµããŒããæäŸããã©ã¹ã¿ãŒãšãã¯ã¿ãŒã®äž¡æ¹ã®ããŒã¿ããµããŒãããŸãã ãŸããããŒã¿ã衚瀺ãã¬ã³ããªã³ã°ãããã³æäœããããã®å€ãã®ãµãŒãããŒãã£ã®å°ç空éããŒã«ïŒèäœæš©ããã³ãªãŒãã³ãœãŒã¹ïŒãšã®äºææ§ãæäŸããŸãã
MySQL 5.7.8ããã³MariaDBã§ã¯ãããŒãžã§ã³5.3.3以éãOpenGISå°çæ å ±æšæºããµããŒãããããã«ããŒã¿ã¿ã€ãæ¡åŒµãè¿œå ãããŠããŸãã ãã®ããŒãžã§ã³ã®MySQLããã³ä»¥éã®ããŒãžã§ã³ã®MariaDBã¯ãPostgresã®éåžžã®ãžãªããŒã¿ãšåæ§ã®ããŒã¿ã¿ã€ãã¹ãã¬ãŒãžãæäŸããŸãã ãã ããMySQLããã³MariaDBã§ã¯ãããŒã¿å€ãããŒãã«ã«æ¿å ¥ããåã«ãåçŽãªã³ãã³ãã䜿çšããŠæåã«å¹ŸäœåŠç圢åŒã«å€æããå¿ èŠããããŸãã Firebirdã¯çŸåšã幟äœããŒã¿åããµããŒãããŠããŸããã
JSONãµããŒã
PostgreSQLã®JSONãµããŒãã«ãããã¹ããŒããªãã®ããŒã¿ãSQLããŒã¿ããŒã¹ã«ä¿åããããšãã§ããŸãã ããã¯ãããŒã¿æ§é ã«ããçšåºŠã®æè»æ§ãå¿ èŠãªå Žåã«åœ¹ç«ã¡ãŸããããšãã°ãéçºããã»ã¹äžã«æ§é ãå€æŽãããŠããå ŽåããããŒã¿ãªããžã§ã¯ãã«å«ãŸãããã£ãŒã«ããäžæãªå Žåãªã©ã§ãã
JSONããŒã¿åã¯JSONæ€èšŒãæäŸããŸããããã«ãããPostgresã«çµã¿èŸŒãŸããç¹æ®ãªJSONæŒç®åãšé¢æ°ã䜿çšããŠãã¯ãšãªãå®è¡ããããŒã¿ãæäœã§ããŸãã JSONBã¿ã€ããå©çšå¯èœã§ã-ã¹ããŒã¹ãåé€ããããªããžã§ã¯ãã®äžŠã¹æ¿ããä¿æãããã代ããã«æé©ãªæ¹æ³ã§ä¿åãããéè€ããŒã®æåŸã®å€ã®ã¿ãä¿åãããJSON圢åŒã®ãã€ããªããªã¢ã³ãã§ãã JSONBã¯ãå解æãå¿ èŠãšããªãããããªããžã§ã¯ãã«å¿ èŠãªã¹ããŒã¹ãå°ãªããã€ã³ããã¯ã¹ä»ããšåŠçãé«éåã§ãããããéåžžã¯æšå¥šããã圢åŒã§ãã
MySQL 5.7.8ããã³MariaDB 10.0.1ã§ã¯ãçµã¿èŸŒã¿JSONãªããžã§ã¯ãã®ãµããŒããè¿œå ãããŸããã ãã ãããããã®ããŒã¿ããŒã¹ã§äœ¿çšã§ããJSONã®é¢æ°ãšæŒç®åã¯å€æ°ãããŸãããPostgreSQLã®JSONBã®ããã«ã€ã³ããã¯ã¹ä»ããããŠããŸããã Firebirdã¯ãŸã ãã¬ã³ãã«åå ããŠããããJSONãªããžã§ã¯ãã®ã¿ãããã¹ããšããŠãµããŒãããŠããŸãã
æ°ããã¿ã€ããäœæãã
PostgresããŒã¿åã®åºç¯ãªãªã¹ããèŠã€ãããªãããšãçªç¶çºçããå ŽåãCREATE TYPEã³ãã³ãã䜿çšããŠãè€åãåæãç¯å²ãããŒã¹ãªã©ã®æ°ããããŒã¿åãäœæã§ããŸãã æ°ããè€åã¿ã€ãã®ãªã¯ãšã¹ããäœæããã³éä¿¡ããäŸãèããŠã¿ãŸãããã
-- "wine" CREATE TYPE wine AS ( wine_vineyard varchar(50), wine_type varchar(50), wine_year int ); -- , "wine" CREATE TABLE pairings ( menu_entree varchar(50), wine_pairing wine ); -- ROW INSERT INTO pairings VALUES ('Lobster Tail',ROW('Stag''s Leap','Chardonnay', 2012)), ('Elk Medallions',ROW('Rombauer','Cabernet Sauvignon',2012)); /* ( , ) */ SELECT (wine_pairing).wine_vineyard, (wine_pairing).wine_type FROM pairings WHERE menu_entree = 'Elk Medallions';
ãããã¯ãªããžã§ã¯ããªã¬ãŒã·ã§ãã«ã§ã¯ãªããããMySQLãMariaDBãFirebirdã¯ãã®ãããªåŒ·åãªæ©èœãæäŸããŸããã
ããŒã¿ãµã€ãº
PostgreSQLã¯å€ãã®ããŒã¿ãåŠçã§ããŸãã çŸåšå ¬éãããŠããå¶éã¯ä»¥äžã®ãšããã§ãã
æ倧ããŒã¿ããŒã¹ãµã€ãº | ç¡å¶é |
æ倧ããŒãã«ãµã€ãº | 32 TB |
æ倧è¡ãµã€ãº | 1.6 TB |
æ倧ãã£ãŒã«ããµã€ãº | 1 GB |
ããŒãã«å ã®æ倧è¡æ° | ç¡å¶é |
ããŒãã«å ã®åã®æå€§æ° | åã®ã¿ã€ãã«å¿ããŠ250ã1600 |
ããŒãã«å ã®ã€ã³ããã¯ã¹ã®æå€§æ° | ç¡å¶é |
äœæäž[çŽ translãïŒå ã®èšäºã®äœè ãåããŠããçµç¹]ããŒã¿éã®å¢å ãå¿é ããå¿ èŠããªãããã«ãã€ã³ã¹ããŒã«ãèªåçã«ã¹ã±ãŒãªã³ã°ããŸãã ãã ããããŒã¿ããŒã¹ç®¡çè ãªã誰ã§ãç¥ã£ãŠããããã«ãç¡å¶éã®å¯èœæ§ã«æ³šæããå¿ èŠããããŸãã ããŒãã«ãäœæããŠã€ã³ããã¯ã¹ãè¿œå ãããšãã¯ãåžžèã䜿çšããããšããå§ãããŸãã
æ¯èŒãããšãMySQLãšMariaDBã¯è¡ãµã€ãºã65,535ãã€ãã«å¶éããããšã§æåã§ãã Firebirdã¯ãæ倧è¡ãµã€ãºãšããŠ64 KBãæäŸããŸãã éåžžãããŒã¿ã®éã¯ããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã®æ倧ãã¡ã€ã«ãµã€ãºã«ãã£ãŠå¶éãããŸãã PostgreSQLã¯å€ãã®å°ããªãã¡ã€ã«ã«è¡šåœ¢åŒã®ããŒã¿ãä¿åã§ããããããã®å¶éãåé¿ã§ããŸãã ãã ãããã¡ã€ã«ãå€ããããšããã©ãŒãã³ã¹ã«æªåœ±é¿ãäžããå¯èœæ§ãããããšã«æ³šæããŠãã ããã MySQLããã³MariaDBã¯ãããŒãã«å ã®å€æ°ã®åïŒããŒã¿åã«å¿ããŠ4.096ãŸã§ïŒããã³PostgreSQLããã倧ããåã ã®ããŒãã«ãµã€ãºããµããŒãããŸãããæ¢åã®Postgresã®å¶éãè¶ ããå¿ èŠãçããã®ã¯éåžžã«ãŸããªå Žåã®ã¿ã§ãã
ããŒã¿ã®å®å šæ§
Postgresã¯ANSI-SQLïŒ2008æšæºãžã®æºæ ã«åªããACIDèŠä»¶ïŒååæ§ãäžè²«æ§ãåé¢ãããã³ä¿¡é Œæ§ïŒãæºãããåç §ããã³ãã©ã³ã¶ã¯ã·ã§ã³ã®æŽåæ§ã§ç¥ãããŠããŸãã äž»ããŒãå€éšããŒã®å¶éãšã«ã¹ã±ãŒããäžæå¶çŽãNOT NULLå¶çŽãæ€èšŒå¶çŽãããã³ãã®ä»ã®ããŒã¿æŽåæ§æ©èœã«ãããæå¹ãªããŒã¿ã®ã¿ãä¿åãããŸãã
MySQLããã³MariaDBã¯ãInnoDB / XtraDBããŒãã«ãšã³ãžã³ã䜿çšããŠSQLæšæºãæºããããšã«ã³ãããããŠããŸãã çŸåšã§ã¯ãSQLã¢ãŒãã䜿çšããSTRICTãªãã·ã§ã³ãæäŸããã䜿çšããããŒã¿ã®æ€èšŒãèšå®ãããŸãã ããã«ããããããã䜿çšããã¢ãŒãã«å¿ããŠãæŽæ°äžã«èª€ã£ãããŒã¿ãåãæšãŠãããããŒã¿ãæ¿å ¥ãŸãã¯äœæãããå ŽåããããŸãã ãããã®ããŒã¿ããŒã¹ã¯çŸåšãCHECKå¶éããµããŒãããŠããŸããã ããã«ãå€éšããŒã®åç §æŽåæ§å¶éã«é¢ããŠå€ãã®æ©èœããããŸãã äžèšã«å ããŠãéžæããã¹ãã¬ãŒãžãšã³ãžã³ã«ãã£ãŠã¯ãããŒã¿ã®æŽåæ§ã倧ãã圱é¿ãåããå ŽåããããŸãã MySQLïŒããã³MariaDBã®ãã©ãŒã¯ïŒã¯ãé床ãšå¹çã®ããã«ãæŽåæ§ãšæšæºãžã®æºæ ã亀æããããšãç§å¯ã«ããŸããã
ãŸãšãããš
Postgresã«ã¯å€ãã®å¯èœæ§ããããŸãã ãªããžã§ã¯ããªã¬ãŒã·ã§ãã«ã¢ãã«ã䜿çšããŠäœæãããè€éãªæ§é ãšå¹ åºãçµã¿èŸŒã¿ããã³ãŠãŒã¶ãŒå®çŸ©ã®ããŒã¿åããµããŒãããŸãã ããŒã¿å®¹éã匷åããããŒã¿ã®æŽåæ§ã«å¯Ÿããæ¬æãæã£ãŠä¿¡é Œãç²åŸããŠããŸãã ãã®èšäºã§èª¬æããé«åºŠãªã¹ãã¬ãŒãžæ©èœã®ãã¹ãŠãå¿ èŠãªããã§ã¯ãããŸããããããŒãºãæ¥éã«æ¡å€§ããå¯èœæ§ãããããããã¹ãŠã®æ©èœãæå ã«çœ®ãããšã«ã¯æ確ãªå©ç¹ããããŸãã
PostgreSQLãããªãã®ããŒãºã«åããªãããã§ããå ŽåããŸãã¯è °ããæã€ããšã奜ãå ŽåãComposeã§æäŸããNoSQLããŒã¿ããŒã¹ã«æ³šæãæãããèšåããä»ã®SQLããŒã¿ããŒã¹ã«ã€ããŠèããå¿ èŠããããŸãã ããããã«ç¬èªã®å©ç¹ããããŸãã Composeã¯ãç¹å®ã®ã¿ã¹ã¯ã«é©åãªããŒã¿ããŒã¹ãéžæããããšãéåžžã«éèŠã§ãããšç¢ºä¿¡ããŠããŸã...æã«ã¯ãè€æ°ã®ããŒã¿ããŒã¹ãéžæããå¿ èŠãããããšãæå³ããŸãïŒ
ãã£ãšPostgresãå¿ èŠã§ããïŒ ãã®ã·ãªãŒãºã®ç¬¬2éšã§ã¯ ãä»®æ³ããŒãã«é¢æ°ãã¯ãšãªæ©èœãã€ã³ããã¯ã¹äœæãèšèªæ¡åŒµãªã©ãPostgreSQLã®ããŒã¿æäœãšæ€çŽ¢ã«ã€ããŠèª¬æããŸãã