Upgrade to Pro — share decks privately, control downloads, hide ads and more …

PHPerに知ってほしいRDBの事_その2.pdf

soudai sone
May 07, 2016
28k

 PHPerに知ってほしいRDBの事_その2.pdf

soudai sone

May 07, 2016
Tweet

More Decks by soudai sone

Transcript

  1. ࣮ߦܭը CREATE TABLE `demo`.`users` ( `id` INT NOT NULL AUTO_INCREMENT

    COMMENT '', `name` VARCHAR(45) NOT NULL COMMENT '', `age` INT NOT NULL COMMENT '', `created` DATETIME NOT NULL DEFAULT NOW () COMMENT '', PRIMARY KEY (`id`) COMMENT '' ); ——શ݅Λબ୒͢ΔͷͰςʔϒϧεΩϟϯ SELECT * FROM demo.users; ——PRIMARY KEYʢINDEXʣΛར༻ͨ͠ྫ SELECT * FROM demo.users WHERE id > 100; ——INDEX͕ແ͍ͷͰςʔϒϧεΩϟϯ SELECT * FROM demo.users WHERE age > 20;
  2. JOIN SELECT * FROM users INNER JOIN users AS tmp

    ON tmp.id = users.id AND tmp.id BETWEEN 10 AND 100000 WHERE users.created = '2016-02-27 04:31:32'
  3. ෳ਺ར༻ͨ͠INDEX CREATE TABLE public.users ( id integer NOT NULL DEFAULT

    nextval('users_id_seq'::regclass), name text NOT NULL, age integer NOT NULL, created timestamp without time zone NOT NULL DEFAULT now(), CONSTRAINT users_pkey PRIMARY KEY (id)); CREATE INDEX users_created_idx ON public.users USING tree (created); ——idͱcreatedͷINDEXΛར༻͢Δ SELECT * FROM users WHERE id < 100 AND created < '2016-02-27 05:41:28';
  4. ૬ؔαϒΫΤϦ SELECT * FROM users WHERE age IN (SELECT age

    FROM users WHERE id BETWEEN 10 AND 100000)
  5. ੵΈॏͳΔWHERE۟ ༗ޮͳॴଐͷ༗ޮͳΞΧ΢ϯτͷϒϩάΛऔ͖͍ͬͯͨ৔߹ 4&-&$5   '30. CMPH *//&3+0*/VTFST 0/VTFSTJECMPHVTFS@JE "/%VTFSTEFMFUF@qBH

    *//&3+0*/DVTUPNFST 0/DVTUPNFSTJEVTFSTDVTUPNFS@JE "/%DVTUPNFSTEFMFUF@qBH 8)&3& CMPHEFMFUF@qBH +0*/͕ͲΜͲΜੵΈॏͳΔ
  6. ੵΈॏͳΔWHERE۟ ༗ޮͳॴଐͷ༗ޮͳΞΧ΢ϯτͷϒϩάΛऔ͖͍ͬͯͨ৔߹ 4&-&$5   '30. CMPH *//&3+0*/VTFST 0/VTFSTJECMPHVTFS@JE "/%VTFSTEFMFUF@qBH

    *//&3+0*/DVTUPNFST 0/DVTUPNFSTJEVTFSTDVTUPNFS@JE "/%DVTUPNFSTEFMFUF@qBH 8)&3& CMPHEFMFUF@qBH +0*/͕ͲΜͲΜੵΈॏͳΔ 2VFSZ͕ϘτϧωοΫʹ
  7. ͱΓ͋͑ͣ࡟আϑϥά JE OBNF BHF EFMFUFE  TPVEBJ   

    TPVEBJ    TPOF    UBLFUPNP  
  8. ͱΓ͋͑ͣ࡟আϑϥά JE OBNF BHF EFMFUFE  TPVEBJ   

    TPVEBJ    TPOF    UBLFUPNP  
  9. ͱΓ͋͑ͣ࡟আϑϥά JE OBNF BHF EFMFUFE  TPVEBJ   

    TPVEBJ    TPOF    UBLFUPNP   ಉ͡Ϣʔβ໊͕͍ΔͷͰ 6OJRVF੍໿Ͱ͖ͳ͍
  10. ͱΓ͋͑ͣ࡟আϑϥά JE OBNF BHF EFMFUFE  TPVEBJ   

    TPVEBJ    TPOF    UBLFUPNP   ಉ͡Ϣʔβ໊͕͍ΔͷͰ 6OJRVF੍໿Ͱ͖ͳ͍ ΋ͪΖΜ֎෦Ωʔ੍໿΋Ͱ͖ͳ͍
  11. ͱΓ͋͑ͣ࡟আϑϥά JE OBNF BHF EFMFUFE  TPVEBJ   

    TPVEBJ    TPOF    UBLFUPNP   αϩήʔτΩʔͰ֎෦Ωʔ੍໿ͨ͠৔߹͸ ؔ࿈ͨ͠σʔλ͸ผਓѻ͍ʹͳΔ
  12. ͱΓ͋͑ͣ࡟আϑϥά JE OBNF BHF EFMFUFE  TPVEBJ   

    TPVEBJ    TPOF    UBLFUPNP   αϩήʔτΩʔͰ֎෦Ωʔ੍໿ͨ͠৔߹͸ ؔ࿈ͨ͠σʔλ͸ผਓѻ͍ʹͳΔ φνϡϥϧΩʔͷ৔߹͸ࢮ͵
  13. ੵΈॏͳΔWHERE۟ ༗ޮͳॴଐͷ༗ޮͳΞΧ΢ϯτͷϒϩάΛऔ͖͍ͬͯͨ৔߹ 4&-&$5   '30. CMPH *//&3+0*/VTFST 0/VTFSTJECMPHVTFS@JE "/%VTFSTEFMFUF@qBH

    *//&3+0*/DVTUPNFST 0/DVTUPNFSTJEVTFSTDVTUPNFS@JE "/%DVTUPNFSTEFMFUF@qBH 8)&3& CMPHEFMFUF@qBH දࣔͤ͞ΔͨΊʹ ͭͷςʔϒϧ͕ؔ܎͍ͯ͠Δ