Just another Telkom University Student Blog site

Month: February 2017

Query Proccessing [Soal Latihan]

Soal Latihan

 

Employee (person_name, street, city)

Works (­person_name, company_name, salary)

Company (company_name, city)

Manages (person_name, manager_name)

 

I.Expression in the relational algebra to express each of the queries.

  1. Πperson_name (σperson_name = manager_name ᴧ employee.city = manages.person_name.city(employee manages))
  2. Пperson_name (σcompany_name ≠ “First Bank Corporation”(works))
  3. Пperson_name (σsalary > (σmax(salary) ᴧ company_name = “Small Bank Corporation(works))

 

II.Expression in the relational algebra to express each of the queries.

  1. Пperson_name, street, city (σmanager_name = “Jones” (employee x manages))
  2. Пcity (σmanager_name = “Jones” (employee x manages))
  3. Gmanages.manager_name = (Gmanages.person_name = “Jones”(manages))
  4. Пperson_name (σsalary > (σmax(salary) ᴧ city = “Mumbai” (employee works))

 

III.–

  1. Пperson_name (σcompany_name = “Small Bank Corporation”(works))
  2. Пperson_name, city (σcompany_name ≠ “First Bank Corporation”(employee works))
  3. Пperson_name, street, city (σcompany_name = “Small Bank Corporation” ᴧ salary > 45000 (employee works))
  4. Пperson_name (σemployee.city = company.city((employee works)company))
  5. Пcity (σcompany_name = “First Bank Corporation”(company))

 

IV. Query Evaluation Plan

Пperson_name (σcompany_name ≠ “First Bank Corporation”(works))

  • Пperson_name [sort the person name]
  • (σcompany_name ≠ “First Bank Corporation”(works)) [A4, Secondary Index, Equality on nonkey)

 

Пperson_name, city (σcompany_name ≠ “First Bank Corporation”(employee works))

  • Пperson_name, city [sort the person name and group with the city]
  • (σcompany_name ≠ “First Bank Corporation”(employee works)) [joining the employee and works table]

 

V. Example, R1 has 20000 tuples and R2 has 45000 tuples. 25 tuples of R1 fit on one block and 30 tuples of R2 fit on one block. Estimate the number of block transfer and seeks required using each of the following join strategies.

Nested Loop Join

From the example we can know that R1 has 20.000 records and 800 blocks. R2 has 45.000 records and 1.500 blocks.

Formula for R1 = nr1 * br2 + br1 blocks transfer and nr1 + br1 seeks

Formula for R2 = nr2 * br1 + br2 blocks transfer and nr2 + br2 seeks

R1 = 20.000 * 1.500 + 800 = 30.000.800 blocks transfer and 20.000 + 800 = 20.800 seeks.

R2 = 45.000 * 800 + 1.500 = 36.001.500 blocks transfer and 45.000 + 1.500 = 46.500 seeks.

 

Block Nested Loop Join

From the example we can know that R1 has 20.000 records and 800 blocks. R2 has 45.000 records and 1.500 blocks.

Formula for R1 = br1 * br2 + br1 blocks transfer and 2 * br1 seeks

Formula for R2 = br2 * br1 + br2 blocks transfer and 2 * br2 seeks

R1 = 800 * 1500 + 800 = 1.200.800 blocks transfer and 2 * 800 = 1.600 seeks.

R2 = 1500 * 800 + 1500 = 1.201.500 blocks transfer and 2 * 1500 = 3.000 seeks.

Cost Estimates for Selection Operation

  1. Algorithm A1 (Linear Search) – membaca setiap blok-blok file dan membaca setiap record untuk menentukan dimana hasil selection yang diminta sesuai kondisi.

Cara menghitung cost estimatenya yaitu,

Cost estimate = br block transfers + 1 seek; dimana br adalah jumlah blok yang terisi oleh record-record relasi r.

Tapi jika selection menurut kata kunci / primary key-nya, rumus cost menjadi,

Cost = (br/2) block transfers + 1 seek

Linear search ini bisa digunakan untuk kondisi seleksi, pengurutan record-record dalam suatu file dan indeks.

 

  1. A2 (Primary Index, equality on key) – hanya mengambil/membaca 1 record yang memenuhi dengan kondisi yang diinginkan. Rumus perhitungan costnya yaitu,

Cost = (hi + 1) * (tT + tS)

 

  1. A3 (Primary Index, equality on nonkey) – mengambil/membaca multiple record yang sesuai dengan kondisi. Rumus perhitungan costnya menjadi,

Cost = hi * (tT + tS) + tS + tT * b; dimana b adalah jumlah blok dengan data yang sesuai kondisi

 

  1. A4 (Secondary Index, equality on nonkey)mengambil/membaca 1 record yang sesuai kondisi, dimana search-keynya merupakan kunci kandidat. Perhitungan costnya menggunakan rumus:

Cost = (hi + 1) * (tT + tS)

 

Kondisi kedua adalah jika searck-keynya bukan merupakan kunci kandidat, perhitungan costnya, yaitu

each of n matching records may be on a different block

Cost =  (hi + n) * (tT + tS)  ; dimana data n yang sesuai dengan kondisi bisa berada dalam blok yang berbeda

 

  1. A5 (Primary Index, comparison)

sA ³ V(r)  digunakan untuk menemukan tuple pertama ³ v  dan memindai secara berurutan.

sA£V (r) digunakan untuk memindai tuple pertama > v dan tidak menggunakan indeks.

 

  1. A6 (Secondary Index, comparison).

Untuk sA ³ V(r)  menggunakan indeks untuk mencari entri pertama ³ v dan memindai secara berurutan mencari pointer

Untuk sA£V (r) hanya memindai pointer indeks hingga entri pertama > v

 

  1. A7 (Conjunctive Selection using One Index).

Pemilihan kombinasi qi dan algoritma A1 melalui A7 menghasilkan biaya untuk sqi (r).

  1. A8 (Conjunctive Selection using Composite Index).

Menggunakan multiple-key indeks yang tersedia.

  1. A9 (Conjunctive Selection by Intersection of Identifiers).

Menggunakan indeks yang sesuai untuk setiap kondisi dan mengambil irisan semua set yang didapat dari pointer.

  1. A10 (Disjunctive Selection by Union of Identifiers).

Berlaku jika semua kondisi memiliki indeks yang tersedia, untuk mencari setiap kondisi dan mengambil gabungan dari semua set yang diperoleh dari pointer.

© 2024 indraaristya's blog

Theme by Anders NorenUp ↑