PostgreSQL | ||
---|---|---|
Prev | Next |
¤³¤ì¤Þ¤Ç¤Î¤È¤³¤í¤Ç¤Ï¡¢¿·¤·¤¤·¿¤ä¿·¤·¤¤´Ø¿ô¡¢¤ª¤è¤Ó¿·¤·¤¤±é»»»Ò ¤Ë¤Ä¤¤¤ÆÀâÌÀ¤·¤Æ¤¤Þ¤·¤¿¡£¤·¤«¤·¤Ê¤¬¤é¡¢¿·¤·¤¤·¿¤ä¤½¤Î±é»»»Ò¤Ë ÂФ¹¤ë¡ÊB-tree, R-tree ¤ä¥Ï¥Ã¥·¥å¥¢¥¯¥»¥¹¥á¥½¥Ã¥É¤Ê¤É¤ò»È¤Ã¤¿¡Ë£²¼¡¥¤¥ó¥Ç¥Ã¥¯¥¹¤Ë¤Ä¤¤¤Æ¤Ï ÀâÌÀ¤·¤Æ¤¤¤Þ¤»¤ó¤Ç¤·¤¿¡£
The major Postgres system catalogs ¤ò¤â¤¦°ìÅÙÆɤßÊÖ¤·¤Æ¤ß¤Æ¤¯¤À¤µ¤¤¡£¤³¤³¤Î¥Ú¡¼¥¸¤Î±¦È¾Ê¬¤Ç¤Ï¡¢ ¥æ¡¼¥¶ÄêµÁ¤Î·¿¤ª¤è¤Ó¡¿¤Þ¤¿¤Ï¥¤¥ó¥Ç¥Ã¥¯¥¹ÉÕ¤¤Î¥æ¡¼¥¶ÄêµÁ±é»»»Ò ¡Ê¤¹¤Ê¤ï¤Ápg_am, pg_amop, pg_amproc¤ª¤è¤Ó pg_opclass¡Ë¤Î»È¤¤Êý¤ò Postgres¤ËÂФ·¤ÆÅÁ¤¨¤ë¤¿¤á¤Ë¡¢ Êѹ¹¤¹¤ëɬÍפΤ¢¤ë¥«¥¿¥í¥°¤Ë´Ø¤·¤Æ¤´¾Ò²ð¤·¤Æ¤¤¤Þ¤¹¡£ »ÄÇ°¤Ê¤¬¤é¡¢¤³¤ì¤é¤Î¤³¤È¤ò¹Ô¤¦¤¿¤á¤Î¥·¥ó¥×¥ë¤Ê¥³¥Þ¥ó¥É¤Ï¸ºß¤·¤Þ¤»¤ó¡£ ¤³¤³¤Ç¤Ï¡¢¤³¤ì¤é¤Î¥«¥¿¥í¥°¤òÊѹ¹¤¹¤ë¤ä¤ê¤«¤¿¤Ë¤Ä¤¤¤Æ¡¢ À°¿ô¤òÃͤÎÀäÂÐÃͤξº½ç¤Ë¥½¡¼¥È¤¹¤ë¡¢B-tree ¥¢¥¯¥»¥¹¥á¥½¥Ã¥É¤ò»È¤Ã¤¿¿·¤·¤¤±é»»»Ò¥¯¥é¥¹¤òºî¤ë¤È¤¤¤¦Îã¤òµó¤²¤Æ ¤´¾Ò²ð¤·¤Þ¤¹¡£
pg_am¥¯¥é¥¹¤Ë¤Ï¡¢¥æ¡¼¥¶ÄêµÁ¤Î³Æ¥¢¥¯¥»¥¹¥á¥½¥Ã¥É ¤´¤È¤Î£±¤Ä¤Î¥¤¥ó¥¹¥¿¥ó¥¹¤¬´Þ¤Þ¤ì¤Æ¤¤¤Þ¤¹¡£ Postgres¤Ë¤Ï¥Ò¡¼¥×¥¢¥¯¥»¥¹¥á¥½¥Ã¥É¤¬ ÁȤ߹þ¤Þ¤ì¤Æ¤¤¤Þ¤¹¤¬¡¢Â¾¤Î¤¹¤Ù¤Æ¤Î¥¢¥¯¥»¥¹¥á¥½¥Ã¥É¤ò¤³¤³¤Ç¤´¾Ò²ð ¤·¤Þ¤¹¡£³µÍפȤ·¤Æ¤Ï°Ê²¼¤ÎÄ̤ê¤Ç¤¹¡£
Table 36-1. ¥¤¥ó¥Ç¥Ã¥¯¥¹¤Î³µÍ×
°À | ÀâÌÀ |
---|---|
amname | ¥¢¥¯¥»¥¹¥á¥½¥Ã¥É¤Î̾Á° |
amowner | pg_user ¤Ë¤ª¤±¤ë¡¢½êͼԤΥ¤¥ó¥¹¥¿¥ó¥¹¤Î¥ª¥Ö¥¸¥§¥¯¥ÈID(oid) |
amkind | ¸½ºß¤Ï»È¤ï¤ì¤Æ¤¤¤Ê¤¤¤¬¡¢¾ì½ê¤ò³ÎÊݤ¹¤ë¤¿¤á¤Ë(as a place holder) 'o' ¤ò¥»¥Ã¥È¤¹¤ë |
amstrategies | ¤³¤Î¥¢¥¯¥»¥¹¥á¥½¥Ã¥ÉÍѤΥ¹¥È¥é¥Æ¥¸¤Î¿ô¡Ê¸å½Ò¡Ë |
amsupport | ¤³¤Î¥¢¥¯¥»¥¹¥á¥½¥Ã¥ÉÍѤΥµ¥Ý¡¼¥È¥ë¡¼¥Á¥ó¤Î¿ô¡Ê¸å½Ò¡Ë |
amgettuple aminsert ... | ¤½¤Î¥¢¥¯¥»¥¹¥á¥½¥Ã¥É¤Ø¤Î¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¥ë¡¼¥Á¥ó¤Î¤¿¤á¤Î ¥×¥í¥·¡¼¥¸¥ã¼±Ê̻ҡ£¤¿¤È¤¨¤Ð regproc id ¤Ï¡¢¤³¤³¤Ç¤´¾Ò²ð¤¹¤ë ¥¢¥¯¥»¥¹¥á¥½¥Ã¥É¤ò¥ª¡¼¥×¥ó¡¿¥¯¥í¡¼¥º¤·¤¿¤ê¡¢¤½¤³¤«¤é¥¤¥ó¥¹¥¿¥ó¥¹ ¤ò¼èÆÀ¤·¤¿¤ê¤¹¤ë¤¿¤á¤Î¤â¤Î¤Ç¤¹¡£ |
pg_am¤Ë¤ª¤±¤ë¥¤¥ó¥¹¥¿¥ó¥¹¤Î ¥ª¥Ö¥¸¥§¥¯¥È¼±ÊÌ»Ò(oid)¤Ï¡¢¤½¤Î¾¿¤¯¤Î¥¯¥é¥¹¤Ë¤ª¤¤¤ÆÂåÂØ¥¡¼ ¤È¤·¤Æ»ÈÍѤµ¤ì¤Þ¤¹¡£¤³¤Î¥¯¥é¥¹¤Ë¿·¤·¤¤¥¤¥ó¥¹¥¿¥ó¥¹¤òÄɲ乤ëɬÍ×¤Ï ¤¢¤ê¤Þ¤»¤ó¡£É¬ÍפʤΤϡ¢³ÈÄ¥¤·¤¿¤¤¥¢¥¯¥»¥¹¥á¥½¥Ã¥É¤Î¥¤¥ó¥¹¥¿¥ó¥¹¤Î ¥ª¥Ö¥¸¥§¥¯¥È¼±ÊÌ»Ò(oid)¤À¤±¤Ç¤¹¡£
SELECT oid FROM pg_am WHERE amname = 'btree'; +----+ |oid | +----+ |403 | +----+
amstrategies°À¤Ï¡¢¥Ç¡¼¥¿·¿¤ò¤Þ¤¿¤¬¤ëÈæ³Ó½èÍý ¤òɸ½à²½¤¹¤ë¤¿¤á¤Ë¤¢¤ê¤Þ¤¹¡£¤¿¤È¤¨¤ÐB-tree¤Î¾ì¹ç¡¢ ¥¡¼¤¬¾®¤µ¤¤Êý¤«¤éÂ礤¤Êý¤Ø¸·Ì©¤Ëʤó¤Ç¤¤¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¡£ Postgres¤Ç¤Ï¥æ¡¼¥¶¤¬±é»»»Ò¤òÄêµÁ¤Ç¤¤ë¤Î¤Ç¡¢ Postgres¤Ï±é»»»Ò¡Ê¤¿¤È¤¨¤Ð ">" ¤ä "<"¡Ë¤Î ̾Á°¤ò¸«¤Ä¤±¤ë¤³¤È¤¬¤Ç¤¤º¡¢¤½¤Î±é»»»Ò¤ËÂФ·¤Æ¤É¤Î¤è¤¦¤ÊÈæ³Ó¤ò¹Ô¤¨¤Ð Îɤ¤¤«¤ò»Ø¼¨¤¹¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡£¼ÂºÝ¡¢¥¢¥¯¥»¥¹¥á¥½¥Ã¥É¤Ë¤è¤Ã¤Æ¤Ï ¤Þ¤Ã¤¿¤¯½ç½øÀ¤òµ¬Äꤷ¤Ê¤¤¤â¤Î¤â¤¢¤ê¤Þ¤¹¡£¤¿¤È¤¨¤ÐR-tree ¤Ï»Í³Ñ·Á¤ËÊĤ¸¤¿´Ø·¸¤òɽ¤·¤Þ¤¹¤¬¡¢¥Ï¥Ã¥·¥å¥Ç¡¼¥¿¤Ï¥Ï¥Ã¥·¥å ´Ø¿ô¤ÎÃͤˤè¤Ã¤Æ¥Ó¥Ã¥ÈËè¤ÎÎà»÷À¤òɽ¤·¤Æ¤¤¤ë¤À¤±¤Ç¤¹¡£ Postgres¤Ï¡¢¥¯¥¨¥ê¡¼¤ò¼Â¹Ô¤¹¤ëºÝ¤Ë ²¿¤é¤«¤Î°ì´ÓÀ¤Î¤¢¤ë¥Ç¡¼¥¿¤Î¸ÂÄêÊýË¡¤òɬÍפȤ¹¤ë¤¿¤á¡¢±é»»»Ò¤ò¸«¤Ä¤±¤Æ¡¢ »ÈÍѤǤ¤ë¥¤¥ó¥Ç¥Ã¥¯¥¹¤¬Â¸ºß¤¹¤ë¤«¤É¤¦¤«¤ò·èÄꤷ¤Þ¤¹¡£¤È¤¤¤¦¤³¤È¤Ï¡¢ Postgres¤Ï¡¢¤¿¤È¤¨¤ÐB-tree ¤ò¶èÀÚ¤ë "<=" ¤ä ">" ±é»»»Ò¤òÃΤäƤ¤¤ëɬÍפ¬¤¢¤ë¤³¤È¤Ë¤Ê¤ê¤Þ¤¹¡£ Postgres¤Ï¡¢±é»»»Ò¤È¡¢¥¤¥ó¥Ç¥Ã¥¯¥¹¤ò¥¹¥¥ã¥ó ¤¹¤ë¤¿¤á¤ÎÊýË¡¤Î´Ö¤Î¤³¤ì¤é¤Î´Ø·¸¤ò¡¢¥¹¥È¥é¥Æ¥¸¤ò»È¤Ã¤Æɽ¸½¤·¤Þ¤¹¡£
¿·¤·¤¤¥¹¥È¥é¥Æ¥¸¡¦¥»¥Ã¥È¤ÎÄêµÁ¤Ï¤³¤³¤ÎµÄÏÀ¤ÎÈϰϤǤϤ¢¤ê¤Þ¤»¤ó¤¬¡¢ ¿·¤·¤¤±é»»»Ò¥¯¥é¥¹¤òÄɲ乤뤿¤á¤ËɬÍפʤΤǡ¢¤³¤³¤Ç¤Ï B-tree¥¹¥È¥é¥Æ¥¸¤¬¤É¤¦¤¤¤¦¤Õ¤¦¤ËÆ°ºî¤¹¤ë¤« ¤òÀâÌÀ¤¹¤ë¤³¤È¤Ë¤·¤Þ¤¹¡£pg_am¥¯¥é¥¹¤Ë¤ª¤¤¤Æ amstrategies °À¤Ï¡¢¤³¤Î¥¢¥¯¥»¥¹¥á¥½¥Ã¥É¤Î¤¿¤á¤ËÄêµÁ¤µ¤ì¤¿ ¥¹¥È¥é¥Æ¥¸¤Î¿ô¤Ç¤¹¡£B-tree¤Ë¤ª¤¤¤Æ¤Ï¤³¤Î¿ô¤Ï 5 ¤Ç¤¹¡£¤³¤ì¤é¤Î¥¹¥È¥é¥Æ¥¸¤Ï¡¢°Ê²¼¤Î¤â¤Î¤ËÂбþ¤·¤Æ¤¤¤Þ¤¹¡£
Table 36-2. B-tree ¥¹¥È¥é¥Æ¥¸
¥ª¥Ú¥ì¡¼¥·¥ç¥ó | ¥¤¥ó¥Ç¥Ã¥¯¥¹ |
---|---|
¤è¤ê¾®¤µ¤¤ | 1 |
¤è¤ê¾®¤µ¤¤¤«Åù¤·¤¤ | 2 |
Åù¤·¤¤ | 3 |
¤è¤êÂ礤¤¤«Åù¤·¤¤ | 4 |
¤è¤êÂ礤¤ | 5 |
¹Í¤¨Êý¤È¤·¤Æ¤Ï¡¢Èæ³ÓÊýË¡¤ËÂбþ¤¹¤ë½èÍý¤ò¡¢¾åµ¤Îpg_amop ¥ê¥ì¡¼¥·¥ç¥ó¡Ê¸å½Ò¡Ë¤ËÄɲ乤ëɬÍפ¬¤¢¤ë¤È¤¤¤¦¤³¤È¤Ç¤¹¡£ B-tree¤ò¤É¤¦Ê¬³ä¤¹¤ë¤«¡¢ÁªÂòÀ¤ò¤É¤¦·×»»¤¹¤ë¤« ¤Ê¤É¤ò¸«¤Ä¤±¤ë¤¿¤á¤Ë¡¢¥¢¥¯¥»¥¹¥á¥½¥Ã¥É¤Î¥³¡¼¥É¤Ï¡¢¥Ç¡¼¥¿·¿¤Ë ¤«¤«¤ï¤é¤º¤³¤ì¤é¤Î¥¹¥È¥é¥Æ¥¸ÈÖ¹æ¤ò»ÈÍѤ¹¤ë¤³¤È¤¬¤Ç¤¤Þ¤¹¡£ ½èÍý¤òÄɲ乤뤿¤á¤Î¶ñÂÎŪ¤ÊÊýË¡¤Ë¤Ä¤¤¤Æ¤Ï¤Þ¤Àµ¤¤Ë¤«¤±¤ë¤³¤È¤Ï ¤¢¤ê¤Þ¤»¤ó¡£B-tree¤¬Áàºî¤Ç¤¤ë int2, int4, oid¤½¤Î¾¤Î¥Ç¡¼¥¿·¿¤Î¤¿¤á¤Ë¡¢¤³¤ì¤é¤Î ¼ê³¤¤¬É¬ÍפǤ¢¤ë¤È¤¤¤¦¤³¤È¤¬Íý²ò¤Ç¤¤ì¤Ð¤è¤¤¤Î¤Ç¤¹¡£ ¥¹¥È¥é¥Æ¥¸¤Ï¡¢¥·¥¹¥Æ¥à¤¬¥¤¥ó¥Ç¥Ã¥¯¥¹¤ò»È¤¦ÊýË¡¤ò¸«¤Ä¤±¤ë¤Î¤Ë½½Ê¬¤Ê ¾ðÊó¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¾ì¹ç¤â¤¢¤ê¤Þ¤¹¡£¥¢¥¯¥»¥¹¥á¥½¥Ã¥É¤ÎÃæ¤Ë¤Ï¡¢Æ°ºî¤¹¤ë ¤¿¤á¤Ë¤½¤Î¾¤Î¥µ¥Ý¡¼¥È¥ë¡¼¥Á¥ó¤¬É¬Íפʤâ¤Î¤â¤¢¤ê¤Þ¤¹¡£¤¿¤È¤¨¤Ð B-tree¥¢¥¯¥»¥¹¥á¥½¥Ã¥É¤Ç¤Ï£²¤Ä¤Î¥¡¼¤òÈæ³Ó¤·¡¢ ¤è¤êÂ礤¤¤Î¤«¡¢Åù¤·¤¤¤Î¤«¡¢¤è¤ê¾®¤µ¤¤¤Î¤«¤Ê¤É¤ò·èÄê¤Ç¤¤Ê¤±¤ì¤Ð ¤Ê¤ê¤Þ¤»¤ó¡£Æ±Íͤˡ¢R-tree¥¢¥¯¥»¥¹¥á¥½¥Ã¥É¤Ï £´³Ñ·Á¤Î¸òº¹¡¢¥æ¥Ë¥ª¥ó¡¢¥µ¥¤¥º¤Ê¤É¤ò·×»»¤Ç¤¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¡£ ¤³¤ì¤é¤ÎÁàºî¤Ï SQL ¥¹¥Æ¡¼¥È¥á¥ó¥È¤Ë¤ª¤±¤ë¥æ¡¼¥¶¤Î¸ÂÄê¤È¤ÏÂбþ¤·¤Þ¤»¤ó¡£ ¤³¤ì¤é¤ÏÆâÉôŪ¤Ë¥¢¥¯¥»¥¹¥á¥½¥Ã¥É¤«¤é»ÈÍѤµ¤ì¤ë´ÉÍý¥ë¡¼¥Á¥ó¤Ç¤¹¡£
¤¹¤Ù¤Æ¤ÎPostgres¥¢¥¯¥»¥¹¥á¥½¥Ã¥É¤ËÂФ·¤Æ ÍÍ¡¹¤Ê¥µ¥Ý¡¼¥È¥ë¡¼¥Á¥ó¤ò·Ñ³Ū¤Ë´ÉÍý¤¹¤ë¤¿¤á¤Ë¡¢pg_am ¤Ïamsupport¤È¸Æ¤Ð¤ì¤ë°À¤ò ¥¤¥ó¥¯¥ë¡¼¥É¤·¤Æ¤¤¤Þ¤¹¡£¤³¤Î°À¥ì¥³¡¼¥É¤Ç¤Ï¡¢£±¤Ä¤Î¥¢¥¯¥»¥¹¥á¥½¥Ã¥É ¤«¤é»È¤ï¤ì¤ë¥ë¡¼¥Á¥ó¤Î¿ô¤òÄêµÁ¤·¤Æ¤¤¤Þ¤¹¡£B-tree ¤Ë¤ª¤¤¤Æ¤Ï¤³¤Î¿ô¤Ï£±¤Ç¤¹¡£¤³¤Î¥ë¡¼¥Á¥ó¤Ç¤Ï¡¢ºÇ½é¤Î¥¡¼¤¬£²ÈÖÌܤΠ¥¡¼¤è¤ê¾®¤µ¤¤¤«Åù¤·¤¤¤«Â礤¤¤«¤Ë¤è¤ê¡¢¤½¤ì¤¾¤ì -1, 0, +1 ¤òÊÖ¤·¤Þ¤¹¡£
NOTE: ¸·Ì©¤Ë¸À¤¦¤È¡¢¤³¤Î¥ë¡¼¥Á¥ó¤ÏÉé¿ô(< 0)¡¢0¡¢¤ª¤è¤Ó£°¤Ç¤Ê¤¤Àµ¿ô(> 0)¤ò ÊÖ¤¹¤³¤È¤¬¤Ç¤¤Þ¤¹¡£
pg_am ¤Îamstrategies¥¨¥ó¥È¥ê¤Ï¡¢Ì䤤¹ç¤ï¤»¤Ë ¤ª¤±¤ë¥¢¥¯¥»¥¹¥á¥½¥Ã¥É¤Î¤¿¤á¤ËÄêµÁ¤µ¤ì¤Æ¤¤¤ë¥¹¥È¥é¥Æ¥¸¤Î¿ô¤Ë ²á¤®¤Þ¤»¤ó¡£¤è¤ê¾®¤µ¤¤¡¢¾®¤µ¤¤¤«Åù¤·¤¤¡¢¤Ê¤É¤Î¼ê³¤¤Ï pg_am¤Ë¤Ï¸½¤ì¤Þ¤»¤ó¡£Æ±Íͤˡ¢ amsupport¤Ï¥¢¥¯¥»¥¹¥á¥½¥Ã¥É¤¬Í׵᤹¤ë¥µ¥Ý¡¼¥È¥ë¡¼¥Á¥ó¤Î ¿ô¤Ë²á¤®¤Þ¤»¤ó¡£¼ÂºÝ¤Î¥ë¡¼¥Á¥ó·²¤ÏÊ̤ΤȤ³¤í¤ËÄêµÁ¤µ¤ì¤Æ¤¤¤Þ¤¹¡£
¼¡¤Ë½ÅÍפʤΤϡ¢pg_opclass ¥¯¥é¥¹¤Ç¤¹¡£¤³¤Î¥¯¥é¥¹¤Ï̾Á°¤È oid ¤ò ´ØÏ¢ÉÕ¤±¤ë¤¿¤á¤À¤±¤Ë¸ºß¤·¤Þ¤¹¡£pg_amop ¤Ë¤ª¤¤¤Æ¤Ï¡¢¤¹¤Ù¤Æ¤Î B-tree±é»»»Ò¥¯¥é¥¹¤Ï¡¢¾åµ¤Ë¤Ë¼¨¤·¤¿¤è¤¦¤Ë¡¢ £±¤«¤é£µ¸Ä¤Î¼ê³¤¤Î¥»¥Ã¥È¤ò»ý¤Ã¤Æ¤¤¤Þ¤¹¡£Â¸ºß¤¹¤ë opclass ¤È¤·¤Æ¤Ï¡¢ int2_ops, int4_ops, oid_ops¤¬¤¢¤ê¤Þ¤¹¡£ ¤¢¤Ê¤¿¤Ï¤³¤Î¥¤¥ó¥¹¥¿¥ó¥¹¤ò¡¢¼«Ê¬¤Î opclass ̾¡Ê¤¿¤È¤¨¤Ð complex_abs_ops¡Ë¤È¶¦¤Ëpg_opclass ¤ËÄɲ䷤Ƥä¤é¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¡£¤³¤Î¥¤¥ó¥¹¥¿¥ó¥¹¤Îoid ¤Ï¾¤Î¥¯¥é¥¹¤Ë¤ª¤±¤ëÂåÂØ¥¡¼(foreign key)¤È¤Ê¤ê¤Þ¤¹¡£
INSERT INTO pg_opclass (opcname) VALUES ('complex_abs_ops'); SELECT oid, opcname FROM pg_opclass WHERE opcname = 'complex_abs_ops'; +------+--------------+ |oid | opcname | +------+--------------+ |17314 | int4_abs_ops | +------+--------------+Ãí°Õ¡§¤¢¤Ê¤¿¤Îpg_opclass¥¤¥ó¥¹¥¿¥ó¥¹¤Î¤¿¤á¤Î oid ¤Ï°Û¤Ê¤Ã¤Æ¤¤¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤ê¤Þ¤»¤ó¡£¤³¤ì°Ê¹ß¤ÎµÄÏÀ¤Ë¤ª¤¤¤Æ¤Ï¡¢ 17314 ¤ò¤¢¤Ê¤¿¤Î¼ÂºÝ¤ÎÃͤËÆɤßÂؤ¨¤Æ²¼¤µ¤¤¡£
¤³¤ì¤Ç¥¢¥¯¥»¥¹¥á¥½¥Ã¥É¤È±é»»»Ò¥¯¥é¥¹¤¬¤Ç¤¤Þ¤·¤¿¡£¼¡¤Ë¡¢±é»»»Ò¤Î ¥»¥Ã¥È¤¬É¬Íפˤʤê¤Þ¤¹¡£±é»»»Ò¤òÄêµÁ¤¹¤ë¤¿¤á¤Î¼ê³¤¤Ï¤³¤Î ¥Þ¥Ë¥å¥¢¥ë¤ÇÁ°½Ò¤·¤Þ¤·¤¿¡£Btrees ¾å¤Î complex_abs_ops ±é»»»Ò ¤Ë¤Ä¤¤¤Æ¤Ï¡¢°Ê²¼¤Î¤è¤¦¤Ë¤·¤Þ¤¹¡£
absolute value less-than absolute value less-than-or-equal absolute value equal absolute value greater-than-or-equal absolute value greater-than
ÄêµÁ¤µ¤ì¤Æ¤¤¤ë´Ø¿ô¤ò¼ÂÁõ¤¹¤ë¥³¡¼¥É¤Ï¡¢ PGROOT/src/tutorial/complex.c ¤Ë³ÊǼ¤µ¤ì¤Æ¤¤¤Þ¤¹¡£
¥³¡¼¥É¤Î°ìÉô¤ò°Ê²¼¤Ë¼¨¤·¤Þ¤¹¡£ ¡ÊÃí°Õ¡§¤³¤ÎÎã¤Î»Ä¤ê¤ÎÉôʬ¤Ç¤Ï¡¢¥¤¥³¡¼¥ë±é»»»Ò¤Î¤ß¤ò¼¨¤¹¤³¤È¤Ë¤·¤Þ¤¹¡£ ¾¤Î£´¤Ä¤Î±é»»»Ò¤Ë¤Ä¤¤¤Æ¤âÎɤ¯»÷¤Æ¤¤¤Þ¤¹¡£¾ÜºÙ¤Ï¡¢ complex.c¤Þ¤¿¤Ïcomplex.sql ¤ò¤´Í÷¤¯¤À¤µ¤¤¡£¡Ë
#define Mag(c) ((c)->x*(c)->x + (c)->y*(c)->y) bool complex_abs_eq(Complex *a, Complex *b) { double amag = Mag(a), bmag = Mag(b); return (amag==bmag); }
¤³¤³¤Ç½ÅÍפʤ³¤È¤¬£²¤Ä¤Û¤É¤¢¤ê¤Þ¤¹¡£
¤Þ¤º¡¢int4ÍѤÎless-than,less-than-or-equal, equal, greater-than-or-equal, greater-than ¤Î¤¿¤á¤Î±é»»»Ò¤¬ÄêµÁ ¤µ¤ì¤è¤¦¤È¤·¤Æ¤¤¤ë¤È¤¤¤¦¤³¤È¤Ç¤¹¡£¤³¤ì¤é¤Î±é»»»Ò¤Ï¡¢ int4¤Î¤¿¤á¤Ë¡¢<, <=, =, >= ,> ¤È¤¤¤¦Ì¾Á°¤Ç ¤¹¤Ç¤ËÄêµÁ¤µ¤ì¤Æ¤¤¤Þ¤¹¡£¤â¤Á¤í¤ó¿·¤·¤¤±é»»»Ò¤Ï°Û¤Ê¤Ã¤¿¿¶¤ëÉñ¤¤¤ò ¤·¤Þ¤¹¡£Postgres¤¬¸Å¤¤±é»»»Ò¤Ç¤Ê¤¯ ¤³¤ì¤é¤Î¿·¤·¤¤±é»»»Ò¤ò»È¤¦¤³¤È¤òÊݾڤ¹¤ë¤¿¤á¤Ë¡¢¤³¤ì¤é¤Ë¤Ï¸Å¤¤¤â¤Î ¤È¤Ï°Û¤Ê¤Ã¤¿Ì¾Á°¤òÉÕ¤±¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¡£¤³¤³¤¬´Î¿´¤Ç¤¹¡£ ¤½¤Î±é»»»Ò¤¬°ú¿ô·¿¤Î¤¿¤á¤ËÄêµÁ¤µ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ë¤Î¤ß¡¢ Postgres¤Ç±é»»»Ò¤ò¥ª¡¼¥Ð¡¼¥í¡¼¥É¤¹¤ë ¤³¤È¤¬¤Ç¤¤Þ¤¹¡£¤¹¤Ê¤ï¤Á¡¢(int4, int4) ¤Î¤¿¤á¤Î < ¤¬¤¢¤ë¾ì¹ç¡¢ ¤½¤ì¤òºÆÅÙÄêµÁ¤¹¤ë¤³¤È¤Ï¤Ç¤¤Þ¤»¤ó¡£±é»»»Ò¤òÄêµÁ¤¹¤ëºÝ¤Ë¡¢ Postgres¤Ï¤³¤Î½ÅÊ£¤ò¥Á¥§¥Ã¥¯¤·¤Ê¤¤¤Î¤Ç Ãí°Õ¤·¤Æ²¼¤µ¤¤¡£¤³¤ÎÌäÂê¤òÈò¤±¤ë¤¿¤á¤Ë¡¢±é»»»Ò¤Ë¤ÏÉ÷ÊѤï¤ê¤Ê̾Á°¤¬ »È¤ï¤ì¤Þ¤¹¡£¤³¤ì¤¬¼é¤é¤ì¤Ê¤¤¤È¡¢¥¹¥¥ã¥ó¤ò¼Â¹Ô¤¹¤ëºÝ¤Ë¡¢ ¥¢¥¯¥»¥¹¥á¥½¥Ã¥É¤Ï¥¯¥é¥Ã¥·¥å¤òµ¯¤³¤·¤Æ¤·¤Þ¤¦¤«¤â¤·¤ì¤Þ¤»¤ó¡£
¤â¤¦£±¤Ä¤Î½ÅÍפÊÅÀ¤Ï¡¢¤¹¤Ù¤Æ¤Î±é»»»Ò´Ø¿ô¤Ï¥Ö¡¼¥ëÃͤòÊÖ¤¹¤È¤¤¤¦ ¤³¤È¤Ç¤¹¡£¥¢¥¯¥»¥¹¥á¥½¥Ã¥É¤Ï¤³¤Î»ö¼Â¤òµò¤ê½ê¤Ë¤·¤Æ¤¤¤Þ¤¹¡£¡Ê°ìÊý¡¢ ¥µ¥Ý¡¼¥È´Ø¿ô¤ÏÆÃÄê¤Î¥¢¥¯¥»¥¹¥á¥½¥Ã¥É¤¬´üÂÔ¤¹¤ë¤â¤Î -- ¤³¤Î¥±¡¼¥¹¤Ç¤Ï Éä¹æÉÕ¤À°¿ô -- ¤òÊÖ¤·¤Þ¤¹¡£¡Ë ¥Õ¥¡¥¤¥ëÃæ¤ÎºÇ¸å¤Î¥ë¡¼¥Á¥ó¤Ï¡¢pg_am¥¯¥é¥¹¤Î amsupport °À¤òµÄÏÀ¤·¤¿»þ¤Ë¸ÀµÚ¤·¤¿ "¥µ¥Ý¡¼¥È¥ë¡¼¥Á¥ó" ¤Ç¤¹¡£ ¤³¤ì¤Ï¸å¤Ç»È¤¤¤Þ¤¹¤Î¤Ç¡¢º£¤Ï̵»ë¤·¤Æ¤ª¤¤¤Æ¤«¤Þ¤¤¤Þ¤»¤ó¡£
CREATE FUNCTION complex_abs_eq(complex, complex) RETURNS bool AS 'PGROOT/tutorial/obj/complex.so' LANGUAGE 'c';
¤³¤³¤Ç¤³¤ì¤é¤ò»ÈÍѤ¹¤ë±é»»»Ò¤òÄêµÁ¤·¤Þ¤¹¡£Ãí°Õ¤·¤¿¤è¤¦¤Ë¡¢ ±é»»»Ò¤Î̾Á°¤Ï¡¢£²¤Ä¤Îint4¥ª¥Ú¥é¥ó¥É¤ò¼è¤ë ¤¹¤Ù¤Æ¤Î±é»»»Ò¤Î´Ö¤Ç°ì°Õ¤Ç¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¡£¸å½Ò¤¹¤ë¡¢ÄêµÁºÑ¤ß ±é»»»Ò̾¤Î¥ê¥¹¥È¤òÆÀ¤ë¤Ë¤Ï¡¢pg_operator ¤ËÂФ·¤Æ¥¯¥¨¥ê¡¼¤òȯ¹Ô¤·¤Þ¤¹¡£
/* * ¤³¤Î¥¯¥¨¥ê¡¼¤Ï¡¢Àµµ¬É½¸½±é»»»Ò (~) ¤ò»È¤Ã¤Æ¡¢Ê¸»ú & ¤Ç * ½ª¤ï¤ë£³Ê¸»ú¤Î±é»»»Ò̾¤ò¸«¤Ä¤±¤Þ¤¹¡£ */ SELECT * FROM pg_operator WHERE oprname ~ '^..&$'::text;
¤³¤³¤ÇÂç»ö¤Ê¤³¤È¤Ï¡¢¼ê³¤¡Ê¾åµ¤Î¾ì¹ç¤ÏC¤ÈƱµÁ¸ì¡Ë ¤È restrict ¤È join ÁªÂò´Ø¿ô¤Ç¤¹¡£¤¢¤Ê¤¿¤Ï¸å½Ò¤Ë¤ª¤¤¤Æ»È¤ï¤ì¤Æ¤¤¤ë ¤¦¤Á¤Î£±¤Ä¤À¤±¤ò»È¤¦¤Ù¤¤Ç¤¹ -- Ãí°Õ¡§less-than, equal, greater-than ¤Î ¥±¡¼¥¹¤Ë¤ª¤¤¤Æ¡¢¤³¤Î¤è¤¦¤Ë°Û¤Ê¤Ã¤¿´Ø¿ô¤¬¤¢¤ë¤³¤È¤ËÃí°Õ¤·¤Æ²¼¤µ¤¤¡£ ¤³¤ì¤é¤¬Ä󶡤µ¤ì¤Ê¤¤¤È¡¢¥¢¥¯¥»¥¹¥á¥½¥Ã¥É¤¬¤½¤Î±é»»»Ò¤ò»È¤ª¤¦¤È¤¹¤ë¤È ¥¯¥é¥Ã¥·¥å¤·¤Þ¤¹¡£restrict ¤È join ¤Ë¤Ï̾Á°¤ò¥³¥Ô¡¼¤¹¤ë¤Ù¤ ¤Ç¤¹¤¬¡¢ºÇ¸å¤Î¥¹¥Æ¥Ã¥×¤Ç¤ÏÄêµÁ¤·¤¿¼ê³¤Ì¾¤ò»È¤Ã¤Æ²¼¤µ¤¤¡£
CREATE OPERATOR = ( leftarg = complex, rightarg = complex, procedure = complex_abs_eq, restrict = eqsel, join = eqjoinsel )
Ãí°Õ¡§¤è¤ê¾®¤µ¤¤¡¢¾®¤µ¤¤¤«Åù¤·¤¤¡¢Åù¤·¤¤¡¢¤è¤êÂ礤¤¡¢¤ª¤è¤Ó ¤è¤êÂ礤¤¤«Åù¤·¤¤¡¢¤ËÂбþ¤·¤¿£µ¤Ä¤Î±é»»»Ò¤¬ÄêµÁ¤µ¤ì¤Æ¤¤¤Þ¤¹¡£
¤µ¤¢¡¢¤â¤¦¤¹¤°¤Ç½ª¤ï¤ê¤Ç¤¹¡£ºÇ¸å¤Ë¡¢pg_amop ¥ê¥ì¡¼¥·¥ç¥ó¤ò¹¹¿·¤·¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¡£¤³¤ì¤Ë¤Ï°Ê²¼¤Î°À¤¬ ɬÍפǤ¹¡£
Table 36-3. pg_amproc¥¹¥¡¼¥Þ
°À | ÀâÌÀ |
---|---|
amopid | B-tree ¤Î¤¿¤á¤Îpg_am¥¤¥ó¥¹¥¿¥ó¥¹¤Î oid¡Ê== 403¡¢Á°½Ò¡Ë |
amopclaid | int4_abs_ops pg_opclass oid 17314 |
amopopr | opclass ¤Î¤¿¤á¤Î±é»»»Ò¤Îoid ¡Ê¤¹¤°¤Ë¼èÆÀ¤Ç¤¤ë¡Ë |
amopselect, amopnpages | ¥³¥¹¥È´Ø¿ô |
¤³¤Î¤¿¤á¡¢ÄêµÁ¤·¤¿±é»»»Ò¤Îoid¤¬É¬Íפˤʤê¤Þ¤¹¡£ ¤³¤³¤Ç¡¢£²¤Ä¤Îint4¤ò¼è¤ë¤¹¤Ù¤Æ¤Î±é»»»Ò¤Î̾Á° ¤ò¸¡º÷¤·¡¢¤½¤ÎÃ椫¤é»ä¤¿¤Á¤Î¤â¤Î¤òÃê½Ð¤·¤Æ¤ß¤Þ¤¹¡£
SELECT o.oid AS opoid, o.oprname INTO TABLE complex_ops_tmp FROM pg_operator o, pg_type t WHERE o.oprleft = t.oid and o.oprright = t.oid and t.typname = 'complex'; +------+---------+ |oid | oprname | +------+---------+ |17321 | < | +------+---------+ |17322 | <= | +------+---------+ |17323 | = | +------+---------+ |17324 | >= | +------+---------+ |17325 | > | +------+---------+¡Ê¤³¤³¤ÇºÆ¤Ó¡£¤¢¤Ê¤¿¤Î¤¤¤¯¤Ä¤«¤ÎoidÈÖ¹æ¤Ï¡¢ ¤Û¤È¤ó¤É³Î¼Â¤Ë°Û¤Ê¤Ã¤Æ¤¤¤Þ¤¹¤Í¡£¡Ë¤³¤³¤ÇÃΤꤿ¤¤¤Î¤Ï¡¢ oid¤¬ 17321 ¤«¤é 17325 ¤Þ¤Ç¤Î¤â¤Î¤Ç¤¹¡£ ¤¢¤Ê¤¿¤¬ÆÀ¤é¤ì¤ë¤³¤ì¤é¤ÎÃͤϤª¤½¤é¤¯°Û¤Ê¤Ã¤Æ¤¤¤ë¤Î¤Ç¡¢°Ê²¼¤Ë¼¨¤¹ ÃͤËÃÖ¤´¹¤¨¤Æ¹Í¤¨¤Æ¤¯¤À¤µ¤¤¡£²æ¡¹¤Ï¡¢º£Äɲä·¤¿¤Ð¤«¤ê¤Î±é»»»Ò¤Î ̾Á°¤ò¸«¤Ä¤±¤Æ¼è¤ê½Ð¤¹¤³¤È¤¬¤Ç¤¤Þ¤¹¡£
¤³¤³¤Ç¡¢»ä¤¿¤Á¤Ï¿·¤·¤¤±é»»»Ò¥¯¥é¥¹¤Çpg_amop ¤ò¹¹¿·¤¹¤ë½àÈ÷¤¬¤Ç¤¤Þ¤·¤¿¡£¤³¤ÎµÄÏÀÁ´ÂΤÎÃæ¤Ç°ìÈÖÂçÀڤʤ³¤È¤Ï¡¢ pg_amop¤ÎÃæ¤Ç¤Ï¡¢±é»»»Ò¤Ï¡¢¾®¤µ¤¤¤«Åù¤·¤¤¡¢ ¤«¤éÂ礤¤¤«Åù¤·¤¤¤Þ¤Çʤó¤Ç¤¤¤ë¤È¤¤¤¦¤³¤È¤Ç¤¹¡£É¬Íפʥ¤¥ó¥¹¥¿¥ó¥¹ ¤òÄɲ䷤Ƥߤޤ¹¡£
INSERT INTO pg_amop (amopid, amopclaid, amopopr, amopstrategy, amopselect, amopnpages) SELECT am.oid, opcl.oid, c.opoid, 3, 'btreesel'::regproc, 'btreenpage'::regproc FROM pg_am am, pg_opclass opcl, complex_ops_tmp c WHERE amname = 'btree' and opcname = 'complex_abs_ops' and c.oprname = '=';Ãí°Õ¡§½ç½ø¤È¤·¤Æ¤Ï¡¢"less than" ¤Ï 1¡¢"less than or equal" ¤Ï 2¡¢ "equal" ¤Ï 3¡¢"greater than or equal" ¤Ï 4¡¢"greater than" ¤Ï 5 ¤Ç¤¹¡£
ºÇ½ª¥¹¥Æ¥Ã¥×¡ÊºÇ¸å¡ª¡Ë¤Ï¡¢pg_am¤Î¤È¤³¤í¤Ç µÄÏÀ¤·¤¿¡¢"¥µ¥Ý¡¼¥È¥ë¡¼¥Á¥ó" ¤ÎÅÐÏ¿¤Ç¤¹¡£¤³¤Î¥µ¥Ý¡¼¥È¥ë¡¼¥Á¥ó¤Î oid¤Ïpg_amproc¥¯¥é¥¹¤Ë ³ÊǼ¤µ¤ì¤Æ¤ª¤ê¡¢¥¢¥¯¥»¥¹¥á¥½¥Ã¥É¤Îoid¤È ±é»»»Ò¥¯¥é¥¹¤Îoid¤¬¥¡¼¤Ë¤Ê¤Ã¤Æ¤¤¤Þ¤¹¡£ ºÇ½é¤Ë¡¢Postgres¤Ë¤ª¤¤¤Æ´Ø¿ô¤òÅÐÏ¿ ¤¹¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£ ¡Ê»ä¤¿¤Á¤Ï¡¢±é»»»Ò¥ë¡¼¥Á¥ó¤ò¼ÂÁõ¤·¤¿¥Õ¥¡¥¤¥ë¤ÎºÇ¸å¤Ë¡¢¤³¤Î¥ë¡¼¥Á¥ó ¤ò¼ÂÁõ¤¹¤ëC¥³¡¼¥É¤òÃÖ¤¯¤³¤È¤ò»×¤¤½Ð¤·¤Æ²¼¤µ¤¤¡£
CREATE FUNCTION int4_abs_cmp(int4, int4) RETURNS int4 AS 'PGROOT/tutorial/obj/complex.so' LANGUAGE 'c'; SELECT oid, proname FROM pg_proc WHERE prname = 'int4_abs_cmp'; +------+--------------+ |oid | proname | +------+--------------+ |17328 | int4_abs_cmp | +------+--------------+¡ÊºÆ¤Ó¡£¤¢¤Ê¤¿¤ÎoidÈÖ¹æ¤Ï¤ª¤½¤é¤¯°Û¤Ê¤Ã¤Æ¤¤¤ë ¤Ç¤·¤ç¤¦¤«¤é¡¢¸å½Ò¤ÎÃͤËÃÖ¤´¹¤¨¤Æ¹Í¤¨¤Æ¤¯¤À¤µ¤¤¤Í¡£¡Ë B-tree¥¤¥ó¥¹¥¿¥ó¥¹¤Î oid ¤Ï 403 ¤Ç¡¢ int4_abs_ops¤Î¤½¤ì¤Ï 17314 ¤Ç¤¢¤ë¤³¤È¤ò »×¤¤½Ð¤·¤Æ¤¯¤À¤µ¤¤¡£°Ê²¼¤Î¤è¤¦¤Ë¿·¤·¤¤¥¤¥ó¥¹¥¿¥ó¥¹¤òÄɲ乤뤳¤È¤¬ ¤Ç¤¤Þ¤¹¡£
INSERT INTO pg_amproc (amid, amopclaid, amproc, amprocnum) VALUES ('403'::oid, -- btree oid '17314'::oid, -- pg_opclass tuple '17328'::oid, -- new pg_proc oid '1'::int2);
Prev | Home | Next |
Postgres¥ë¡¼¥ë¥·¥¹¥Æ¥à | Up | GiST Indices |