Phỏt biểu, phõn tớch ứng dụng

Một phần của tài liệu Thực hiện song song các câu vắn tin trong CSDL phân tán bằng cách sử dụng luồng (Trang 73)

Giao diện chớnh của chương trỡnh:

Hỡnh 3.2-2. Màn hỡnh chớnh của chương trỡnh

a. Rỳt gọn cõu vấn tin cho phõn mảnh ngang

Xột cõu truy vấn sau: " Hóy cho biết danh sỏch cỏc sinh viờn học cú giới tớnh nữ"

Cõu SQL như sau: SELECT *

FROM HSSV

WHERE GioiTinh="Nữ"

Quan hệ HSSV cú thể được tỏch thành hai mảnh ngang như sau: HSSV H1 = GioiTinh = “Nam” (HSSV)

HSSV H2 = GioiTinh= “Nữ” (HSSV)

Chương trỡnh cục bộ hoỏ cho phõn mảnh ngang trờn là hợp cỏc mảnh lại: HSSV = HSSV H1 HSSV H2

Chương trỡnh cục bộ hoỏ cho phõn mảnh ngang HSSV = HSSV H1

với phộp hợp (hỡnh 3.2-3b), chỳng ta dễ dàng phỏt hiện ra rằng vị từ chọn GioiTinh =“Nữ” mõu thuẫn với vị từ phõn mảnh HSSVH1 (GioiTinh= “Nam”), do vậy tạo ra quan hệ rỗng. Cõu vấn tin bấy giờ chỉ cần ỏp dụng trờn HSSVH2

(hỡnh 3.2-3c).

Kết quả thực hiện

Hỡnh 3.2-4. Kết quả của cõu vấn tin cho phõn mảnh ngang Hỡnh 3.2-3. Rỳt gọn cho phõn mảnh ngang (c) Vấn tin rỳt gọn  GioiTinh = “Nữ” HSSVH2 (a) Vấn tin gốc GioiTinh = “Nữ” HSSV H1 HSSVH2 

(b) Vấn tin đó đổi  cho  GioiTinh = “Nữ”

HSSVH1 HSSVH2

b. Rỳt gọn cõu vấn tin cho phõn mảnh dọc

Xột cõu truy vấn sau: " Hóy cho biết danh sỏch (gồm họ tờn, ngày sinh, số điện thoại, email) cỏc sinh viờn trong trường"

Cõu SQL như sau:

SELECT HoTenSV, NgaySinh, DienThoai, Email FROM HSSV

Quan hệ HSSV cú thể được phõn thành hai mảnh dọc, trong đú thuộc tớnh khúa MASV phải cú mặt trong mọi mảnh dọc.

HSSV V1 =  MaSV,HoTenSV,NgaySinh,DienThoai,Email (HSSV) HSSV V2 = MaSV,GioiTinh,DanToc,MaTinhThanh,DiaChi (HSSV) Chương trỡnh cục bộ húa là

HSSV = HSSV V1 HSSV V2

Cõu vấn tin gốc tương đương trờn HSSVV1 và HSSVV2 được cho trờn hỡnh 3.2-5a, sau khi hoỏn vị phộp chiếu với phộp nối (tức là chiếu trước nối) được cõy hỡnh 3.2-5b, chỳng ta thấy HSSVV2 là vụ dụng vỡ HoTenSV, NgaySinh, DienThoai, Email khụng thuộc HSSVV2. Vỡ vậy phộp chiếu chỉ cần thực hiện trờn HSSVV1 như được trỡnh bày trong hỡnh 3.2-5c

HoTenSV, NgaySinh, DienThoai, Email

HSSVV1 HSSVV2 (a) vấn tin gốc

MaSV ENO

Kết quả thực hiện

Hỡnh 3.2-6. Kết quả của cõu vấn tin cho phõn mảnh dọc

HSSVV1 HSSVV2

(b) vấn tin gốc

HoTenSV, NgaySinh, DienThoai, Email HoTenSV, NgaySinh, DienThoai, Email

MaSV

HSSVV1 (c) vấn tin đó rỳt gọn

Hỡnh 3.2-5 a,b,c. Rỳt gọn cho phõn mảnh dọc

c. Rỳt gọn cõu vấn tin cho phõn mảnh ngang dẫn xuất

Xột cõu truy vấn sau: " Hóy cho biết danh sỏch cỏc sinh viờn trong 2 quan hệ HSSV, DMTinhThanh thỏa món mó tỉnh thành trong 2 quan hệ giống nhau và giới tớnh là nữ "

Cõu SQL như sau: SELECT *

FROM HSSV,DMTinhThanh

WHERE HSSV.MaTinhThanh = DMTinhThanh.MaTinhThanh AND GioiTinh = “Nữ”

Thấy rằng liờn hệ từ HSSV (MaSV, HoTenSV, NgaySinh, GioiTinh, DienThoai, DanToc, MaTinhThanh, DiaChi, Email) đến DMTinhThanh (MaTinhThanh, TenTinhThanh) là 1-1.

Gử rằng HSSV được phõn mảnh ngang thành HSSVH1 và HSSVH2 như sau:

HSSV H1 = GioiTinh = “Nam” (HSSV) HSSV H2 = GioiTinh= “Nữ” (HSSV)

Chương trỡnh cục bộ hoỏ phõn mảnh ngang là hợp của cỏc mảnh của nú. Tức là: HSSV = HSSV H1 HSSV H2

Quan hệ DMTinhThanh cú thể được phõn mảnh giỏn tiếp (phõn mảnh dẫn xuất) theo cỏc qui tắc sau:

DMTinhThanh DXH1 = DMTinhThanh HSSVH1

DMTinhThanh DXH2 = DMTinhThanh HSSVH2

Chương trỡnh cục bộ hoỏ cho quan hệ phõn mảnh ngang DMTinhThanh là hợp của cỏc mảnh của nú. Tức:

DMTinhThanh = DMTinhThanhDXH1  DMTinhThanh DXH2

MaTinhThanh MaTinhThanh

Cõu vấn tin gốc được thực thi trờn cỏc mảnh HSSV H1, HSSV H2, DMTinhThanh H1, DMTinhThanh H2 được trỡnh bày trong hỡnh 3.2-7.

Bằng cỏch giao hoỏn dựng phộp chọn GioiTinh= “Nữ” và phộp hợp  của

nhỏnh bờn phải ta được kết quả hỡnh 3.2-8.

Do trong HSSVH1chỉ cú cỏc bộ thỏa vị từ GioiTinh = “Nam” khụng cú bộ nào thỏa món GioiTinh = “Nữ” nờn vị từ chọn mõu thuẫn với vị từ phõn mảnh HSSVH1 và vỡ thế loại bỏ mảnh HSSVH1. Kết quả được cõy ở hỡnh 3.2- 9. Hỡnh 3.2-7. Vấn tin gốc GioiTinh= “Nữ” HSSVH1 HSSVH2 DMTinhThanh H1 TITLE= Mech.Eng” DMTinhThanh H2   MaTinhThanh

Hỡnh 3.2-8. Vấn tin gốc đó được giao hoỏn

GioiTinh= “Nữ” HSSVH1 HSSVH2   MaTinhThanh GioiTinh= “Nữ” DMTinhThanh H1 TITLE= Mech.Eng” DMTinhThanh H2

Để tiếp tục phỏt hiện cỏc vị từ mõu thuẫn, chỳng ta dựng luật phõn phối giữa phộp nối và hợp:

R (S  T) = 

Bõy giờ chỳng ta giao hoỏn phộp và phộp  sẽ được cõy trờn hỡnh 3.2-10.

Cõy con bờn trỏi nối hai mảnh DMTinhThanh DXH1 , HSSVH2 với cỏc vị từ mõu thuẫn do vị từ GioiTinh = “Nam” trong DMTinhThanh DXH1 và GioiTinh = “Nữ” trong HSSVH2. Vỡ thế chỳng ta cú thể loại bỏ nhỏnh bờn trỏi và thu được cõu vấn tin rỳt gọn của hỡnh 3.2-11. Vớ dụ này minh hoạ cho giỏ trị phõn mảnh trong việc cải thiện hiệu năng của cỏc cõu vấn phõn tỏn.

Hỡnh 3.2-9. Vấn tin sau khi dựng vị từ mõu thuẫn

 GioiTinh= “Nữ” HSSVH2  MaTinhThanh DMTinhThanh H1 TITLE= Mech.Eng” DMTinhThanh H2

MaTinhThanh (R MaTinhThanh S) (R MaTinhThanh T)

MaTinhThanh DMTinhThanh DXH2 DMTinhThanh DXH1  GioiTinh= “Nữ” HSSVH2 MaTinhThanh MaTinhThanh GioiTinh= “Nữ” HSSVH2

Kết quả thực hiện

Hỡnh 3.2-12. Kết quả của cõu vấn tin cho phõn mảnh ngang dẫn xuất

d. Rỳt gọn cõu vấn tin cho phõn mảnh hỗn hợp

Xột cõu truy vấn sau: " Hóy cho biết danh sỏch (gồm họ tờn, ngày sinh, số điện thoại, email) cỏc sinh viờn trong trường cú giới tớnh là nữ"

Cõu SQL như sau:

SELECT HoTenSV, NgaySinh, DienThoai, Email FROM HSSV WHERE GioiTinh = “Nữ” Hỡnh 3.2-11. Rỳt gọn cho phõn mảnh dẫn xuất  GioiTinh= “Nữ” HSSVH2 MaTinhThanh DMTinhThanh H2

Giả sử ta cú phõn mảnh hỗn hợp quan hệ HSSV như sau: HSSV HH1 = GioiTinh=“Nam” (MaSV,HoTenSV,NgaySinh,DienThoai,Email (HSSV) HSSV HH2 =  GioiTinh= “Nữ” (MaSV,HoTenSV,NgaySinh,DienThoai,Email (HSSV) HSSV HH3 =  MaSV,GioiTinh,DanToc,MaTinhThanh,DiaChi (HSSV) Chương trỡnh cục bộ hoỏ sẽ là: HSSV = (HSSV HH1 HSSV HH2) HSSV HH3 Cõy vấn tin gốc ở hỡnh 2.2-12

Cõy vấn tin gốc ở hỡnh 3.2-13 cú thể được rỳt gọn bằng cỏch đẩy phộp chọn xuống để loại bỏ HSSVHH1. Hỡnh 3.2-14. Cõy vấn tin đó loại HSSVHH1

MaSV  MaSV,HoTenSV,NgaySinh,DienThoai,Email  GioiTinh= “Nữ” HSSVHH3 HSSVHH1 HSSVHH2  Hỡnh 3.2-13. Cõy vấn tin gốc MaSV

Đẩy phộp chiếu xuống, phộp nối lờn được cõy vấn tin trong hỡnh 3.2-15.

Trong cõy ở hỡnh 3.2-15 loại nhỏnh phải do khụng cú thuộc tớnh HoTenSV, NgaySinh, DienThoai, Email. Kết quả cuối cựng trờn hỡnh 3.2-16.

HSSVHH2

Hỡnh 3.2-15. Cõy vấn tin đó đẩy phộp chiếu xuống, phộp nối lờn

MaSV  GioiTinh= “Nữ” HSSVHH3  GioiTinh= “Nữ”  MaSV,HoTenSV,NgaySinh,DienThoai,Email  MaSV,HoTenSV,NgaySinh,DienThoai,Email  MaSV,HoTenSV,NgaySinh,DienThoai,Email HSSVHH2 MaSV  GioiTinh= “Nữ” HSSVHH3  GioiTinh= “Nữ”

Tỏi thiết cõu lệnh đại số quan hệ từ cõy 3.2-16 sẽ được:

 MaSV,HoTenSV,NgaySinh,DienThoai,Email (GioiTinh= “Nữ” HSSVHH2) Tỏi thiết cõu lệnh SQL từ cõu lệnh đại số quan hệ sẽ được:

SELECT HoTenSV, NgaySinh, DienThoai, Email FROM HSSVHH2

WHERE GioiTinh = “Nữ”

Kết quả thực hiện

Hỡnh 3.2-17. Kết quả của cõu vấn tin cho phõn mảnh hỗn hợp

 MaSV,HoTenSV,NgaySinh,DienThoai,Email

 GioiTinh= “Nữ”

HSSVHH2

3.2.3. M nguồn chương trỡnh

- Mó nguồn form chọn tham số: Imports System.Data.Common

Imports Microsoft.Practices.EnterpriseLibrary.Data

Imports Microsoft.Practices.EnterpriseLibrary.Data.Database Public Class frmChonThamSo

Private Sub ShowNewForm() Handles btnRun.Click

Dim FILE_NAME_NAMSINH As String = Application.StartupPath + "\NamSinh.ini"

If System.IO.File.Exists(FILE_NAME_NAMSINH) = True Then Dim objWriter As New

System.IO.StreamWriter(FILE_NAME_NAMSINH) objWriter.WriteLine(Me.txtGioiTinh.SelectedIndex) objWriter.Close() End If Shell(Application.StartupPath + "\PhanManhDoc.exe", AppWinStyle.NormalFocus) Shell(Application.StartupPath + "\PhanManhHonHop.exe", AppWinStyle.NormalFocus) Shell(Application.StartupPath + "\PhanManhNgangDanXuat.exe", AppWinStyle.NormalFocus) Shell(Application.StartupPath + "\PhanManhNgangTheoKhoang.exe", AppWinStyle.NormalFocus) End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Me.Close() End Sub End Class

- Mó nguồn form chớnh: Imports System.Windows.Forms Public Class frmMain

Sub New()

' This call is required by the Windows Form Designer. InitializeComponent()

' Add any initialization after the InitializeComponent() call. BackGround()

End Sub

Private Sub BackGround()

Dim filebackground As String = Application.StartupPath + "\bg.jpg" Dim ximage As Image = Image.FromFile(filebackground)

Dim width, height As Integer

width = Screen.PrimaryScreen.Bounds.Width height = Screen.PrimaryScreen.Bounds.Height

Me.BackgroundImage = ResizeImage(ximage, New Size(width, height)) End Sub

Private Sub CloseAllForm()

' Close all child forms of the parent.

For Each ChildForm As Form In Me.MdiChildren ChildForm.Close()

Next End Sub

Private Sub ShowForm(ByVal frm As Form) CloseAllForm() frm.WindowState = FormWindowState.Maximized frm.MdiParent = Me frm.Show() End Sub

Private Sub mnuTruyVanDuLieu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuTruyVanDuLieu.Click

Dim frm As New frmChonThamSo frm.ShowDialog() End Sub End Class - Mó nguồn form phõn mảnh dọc: Imports System.Data.Common Imports Microsoft.Practices.EnterpriseLibrary.Data Imports Microsoft.Practices.EnterpriseLibrary.Data.Database Public Class frmPhanManhDoc

Private TABLE_SINHVIEN As DataTable = CauTrucBangDuLieu() Sub New()

' This call is required by the Windows Form Designer. InitializeComponent()

' Add any initialization after the InitializeComponent() call. Me.MainView.DataSource = TABLE_SINHVIEN

LuongLayDuLieu() End Sub

Private Sub CustomDrawRowIndicator(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs) Handles GridView.CustomDrawRowIndicator

If (e.Info.IsRowIndicator And e.RowHandle >= 0) Then e.Info.DisplayText = e.RowHandle + 1

e.Info.ImageIndex = -1 End If

End Sub

Friend Function CauTrucBangDuLieu() As DataTable Dim table As New DataTable

table.Columns.Add("MaSV", Type.GetType("System.String")) table.Columns.Add("HoTenSV", Type.GetType("System.String")) table.Columns.Add("NgaySinh", Type.GetType("System.DateTime")) table.Columns.Add("DienThoai", Type.GetType("System.String")) table.Columns.Add("Email", Type.GetType("System.String")) Return table End Function

Private Sub LoadDuLieu() Dim db As Database

Dim objCmd As DbCommand Dim objDs As DataSet

db = DatabaseFactory.CreateDatabase()

objCmd = db.GetStoredProcCommand("[dbo].[SinhVien_Page]") objDs = db.ExecuteDataSet(objCmd)

TABLE_SINHVIEN = objDs.Tables(0) End Sub

Private Sub LuongLayDuLieu() Handles btnRun.Click

Dim thread As New Threading.Thread(AddressOf LoadDuLieu) thread.Start() thread.Priority = Threading.ThreadPriority.Highest thread.IsBackground = True thread.Join() Me.MainView.DataSource = TABLE_SINHVIEN Me.GridView.BestFitColumns() End Sub End Class - Mó nguồn form phõn mảnh hỗn hợp: Imports System.Data.Common Imports Microsoft.Practices.EnterpriseLibrary.Data Imports Microsoft.Practices.EnterpriseLibrary.Data.Database Public Class frmPhanManhHonHop

Public MaGioiTinh As Boolean

Private TABLE_SINHVIEN As DataTable = CauTrucBangDuLieu() Sub New()

' This call is required by the Windows Form Designer. InitializeComponent()

' Add any initialization after the InitializeComponent() call. Me.MainView.DataSource = TABLE_SINHVIEN

Dim FILE_NAME_NAMSINH As String = Application.StartupPath + "\NamSinh.ini"

If System.IO.File.Exists(FILE_NAME_NAMSINH) = True Then Dim objReader As New

MaGioiTinh = IIf(objReader.ReadToEnd = 0, False, True) objReader.Close()

LuongLayDuLieu() End If

End Sub

Private Sub CustomDrawRowIndicator(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs) Handles GridView.CustomDrawRowIndicator

If (e.Info.IsRowIndicator And e.RowHandle >= 0) Then e.Info.DisplayText = e.RowHandle + 1

e.Info.ImageIndex = -1 End If

End Sub

Friend Function CauTrucBangDuLieu() As DataTable Dim table As New DataTable

table.Columns.Add("MaSV", Type.GetType("System.String")) table.Columns.Add("HoTenSV", Type.GetType("System.String")) table.Columns.Add("NgaySinh", Type.GetType("System.DateTime")) table.Columns.Add("DienThoai", Type.GetType("System.String")) table.Columns.Add("Email", Type.GetType("System.String")) Return table End Function

Private Sub LoadDuLieu() Dim db As Database

Dim objCmd As DbCommand Dim objDs As DataSet

objCmd = db.GetStoredProcCommand("[dbo].[SinhVien_Page]") db.AddInParameter(objCmd, "@GioiTinh", DbType.Boolean, MaGioiTinh)

objDs = db.ExecuteDataSet(objCmd) TABLE_SINHVIEN = objDs.Tables(0) End Sub

Private Sub LuongLayDuLieu() Handles btnRun.Click

'MaGioiTinh = IIf(Me.txtGioiTinh.SelectedIndex = 0, False, True) Dim thread As New Threading.Thread(AddressOf LoadDuLieu) thread.Start() thread.Priority = Threading.ThreadPriority.Highest thread.IsBackground = True thread.Join() Me.MainView.DataSource = TABLE_SINHVIEN Me.GridView.BestFitColumns() End Sub End Class

- Mó nguồn form phõn mảnh ngang dẫn xuất: Imports System.Data.Common

Imports Microsoft.Practices.EnterpriseLibrary.Data

Imports Microsoft.Practices.EnterpriseLibrary.Data.Database Public Class frmPhanManhNgangDanXuat

Public MaGioiTinh As Boolean

Private TABLE_SINHVIEN As DataTable = CauTrucBangDuLieu() Sub New()

' This call is required by the Windows Form Designer. InitializeComponent()

' Add any initialization after the InitializeComponent() call. Me.MainView.DataSource = TABLE_SINHVIEN

Dim FILE_NAME_NAMSINH As String = Application.StartupPath + "\NamSinh.ini"

If System.IO.File.Exists(FILE_NAME_NAMSINH) = True Then Dim objReader As New

System.IO.StreamReader(FILE_NAME_NAMSINH)

MaGioiTinh = IIf(objReader.ReadToEnd = 0, False, True) objReader.Close()

LuongLayDuLieu() End If

End Sub

Private Sub CustomDrawRowIndicator(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs) Handles GridView.CustomDrawRowIndicator

If (e.Info.IsRowIndicator And e.RowHandle >= 0) Then e.Info.DisplayText = e.RowHandle + 1

e.Info.ImageIndex = -1 End If

End Sub

Friend Function CauTrucBangDuLieu() As DataTable Dim table As New DataTable

table.Columns.Add("MaSV", Type.GetType("System.String")) table.Columns.Add("HoTenSV", Type.GetType("System.String")) table.Columns.Add("NgaySinh", Type.GetType("System.DateTime")) table.Columns.Add("GioiTinh", Type.GetType("System.Boolean")) table.Columns.Add("DienThoai", Type.GetType("System.String"))

table.Columns.Add("DanToc", Type.GetType("System.String")) table.Columns.Add("MaTinhThanh", Type.GetType("System.String")) table.Columns.Add("DiaChi", Type.GetType("System.String")) table.Columns.Add("Email", Type.GetType("System.String")) Return table End Function

Private Sub LoadDuLieu() Dim db As Database

Dim objCmd As DbCommand Dim objDs As DataSet

db = DatabaseFactory.CreateDatabase()

objCmd = db.GetStoredProcCommand("[dbo].[SinhVien_Page]") db.AddInParameter(objCmd, "@GioiTinh", DbType.Boolean, MaGioiTinh)

objDs = db.ExecuteDataSet(objCmd) TABLE_SINHVIEN = objDs.Tables(0) End Sub

Private Sub LuongLayDuLieu() Handles btnRun.Click

'MaGioiTinh = IIf(Me.txtGioiTinh.SelectedIndex = 0, False, True) Dim thread As New Threading.Thread(AddressOf LoadDuLieu) thread.Start() thread.Priority = Threading.ThreadPriority.Highest thread.IsBackground = True thread.Join() Me.MainView.DataSource = TABLE_SINHVIEN Me.GridView.BestFitColumns() End Sub

End Class

- Mó nguồn form phõn mảnh ngang: Imports System.Data.Common

Imports Microsoft.Practices.EnterpriseLibrary.Data

Imports Microsoft.Practices.EnterpriseLibrary.Data.Database Public Class frmPhanManhNgangTheoKhoang

Public MaGioiTinh As Boolean

Private TABLE_SINHVIEN As DataTable = CauTrucBangDuLieu() Sub New()

' This call is required by the Windows Form Designer. InitializeComponent()

' Add any initialization after the InitializeComponent() call. Me.MainView.DataSource = TABLE_SINHVIEN

Dim FILE_NAME_NAMSINH As String = Application.StartupPath + "\NamSinh.ini"

If System.IO.File.Exists(FILE_NAME_NAMSINH) = True Then Dim objReader As New

System.IO.StreamReader(FILE_NAME_NAMSINH)

MaGioiTinh = IIf(objReader.ReadToEnd = 0, False, True) objReader.Close()

LuongLayDuLieu() End If

End Sub

Private Sub CustomDrawRowIndicator(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs) Handles GridView.CustomDrawRowIndicator

If (e.Info.IsRowIndicator And e.RowHandle >= 0) Then e.Info.DisplayText = e.RowHandle + 1

e.Info.ImageIndex = -1 End If

End Sub

Friend Function CauTrucBangDuLieu() As DataTable Dim table As New DataTable

table.Columns.Add("MaSV", Type.GetType("System.String")) table.Columns.Add("HoTenSV", Type.GetType("System.String")) table.Columns.Add("NgaySinh", Type.GetType("System.DateTime")) table.Columns.Add("GioiTinh", Type.GetType("System.Boolean")) table.Columns.Add("DienThoai", Type.GetType("System.String")) table.Columns.Add("DanToc", Type.GetType("System.String")) table.Columns.Add("MaTinhThanh", Type.GetType("System.String")) table.Columns.Add("DiaChi", Type.GetType("System.String")) table.Columns.Add("Email", Type.GetType("System.String")) Return table End Function

Private Sub LoadDuLieu() Dim db As Database

Dim objCmd As DbCommand Dim objDs As DataSet

db = DatabaseFactory.CreateDatabase() objCmd =

db.GetStoredProcCommand("[dbo].[SinhVien_PageTinhThanh]") db.AddInParameter(objCmd, "@GioiTinh", DbType.Boolean, MaGioiTinh)

objDs = db.ExecuteDataSet(objCmd) TABLE_SINHVIEN = objDs.Tables(0) End Sub

Private Sub LuongLayDuLieu() Handles btnRun.Click

'MaGioiTinh = IIf(Me.txtGioiTinh.SelectedIndex = 0, False, True) Dim thread As New Threading.Thread(AddressOf LoadDuLieu) thread.Start() thread.Priority = Threading.ThreadPriority.Highest thread.IsBackground = True thread.Join() Me.MainView.DataSource = TABLE_SINHVIEN Me.GridView.BestFitColumns() End Sub End Class

- Mó nguồn khởi tạo luồng phõn mảnh ngang theo giới tớnh: Private Sub LuongLayDuLieu() Handles btnRun.Click

'MaGioiTinh = IIf(Me.txtGioiTinh.SelectedIndex = 0, False, True)

Dim thread As New Threading.Thread(AddressOf LoadDuLieu) // Khai bỏo luồng

thread.Start() // Khởi động thực thi luồng

thread.Priority = Threading.ThreadPriority.Highest thread.IsBackground = True thread.Join() Me.MainView.DataSource = TABLE_SINHVIEN Me.GridView.BestFitColumns() End Sub

- Mó nguồn khởi tạo luồng phõn mảnh dọc theo danh sỏch (gồm họ tờn, ngày sinh, số điện thoại, email):

Private Sub LuongLayDuLieu() Handles btnRun.Click

Dim thread As New Threading.Thread(AddressOf LoadDuLieu) // Khai bỏo luồng

thread.Start()// Khởi động thực thi luồng

thread.Priority = Threading.ThreadPriority.Highest thread.IsBackground = True thread.Join() Me.MainView.DataSource = TABLE_SINHVIEN Me.GridView.BestFitColumns() End Sub

- Mó nguồn khởi tạo luồng phõn mảnh ngang dẫn xuất theo giới tớnh và mó tỉnh thành:

Private Sub LuongLayDuLieu() Handles btnRun.Click

'MaGioiTinh = IIf(Me.txtGioiTinh.SelectedIndex = 0, False, True)

Dim thread As New Threading.Thread(AddressOf LoadDuLieu) // Khai bỏo luồng

thread.Start()// Khởi động thực thi luồng

thread.Priority = Threading.ThreadPriority.Highest thread.IsBackground = True thread.Join() Me.MainView.DataSource = TABLE_SINHVIEN Me.GridView.BestFitColumns() End Sub

- Mó nguồn khởi tạo luồng phõn mảnh hỗn hợp theo dọc theo danh sỏch (gồm họ tờn, ngày sinh, số điện thoại, email) và giới tớnh:

Private Sub LuongLayDuLieu() Handles btnRun.Click

'MaGioiTinh = IIf(Me.txtGioiTinh.SelectedIndex = 0, False, True)

Dim thread As New Threading.Thread(AddressOf LoadDuLieu) // Khai bỏo luồng

thread.Start()// Khởi động thực thi luồng

thread.Priority = Threading.ThreadPriority.Highest thread.IsBackground = True thread.Join() Me.MainView.DataSource = TABLE_SINHVIEN Me.GridView.BestFitColumns() End Sub

- Mó nguồn thực hiện chạy đa luồng trong 1 bộ vi xử lý: Private Sub ShowNewForm() Handles btnRun.Click

Dim FILE_NAME_NAMSINH As String = Application.StartupPath + "\NamSinh.ini"

If System.IO.File.Exists(FILE_NAME_NAMSINH) = True Then Dim objWriter As New

System.IO.StreamWriter(FILE_NAME_NAMSINH) objWriter.WriteLine(Me.txtGioiTinh.SelectedIndex) objWriter.Close() End If Shell(Application.StartupPath + "\PhanManhDoc.exe", AppWinStyle.NormalFocus) Shell(Application.StartupPath + "\PhanManhHonHop.exe", AppWinStyle.NormalFocus) Shell(Application.StartupPath + "\PhanManhNgangDanXuat.exe", AppWinStyle.NormalFocus)

Shell(Application.StartupPath + "\PhanManhNgangTheoKhoang.exe", AppWinStyle.NormalFocus)

End Sub

3.3. Kết luận chương 3

Trong chương này tỏc giả đó ỏp dụng lý thuyết của chương 2 vào cơ sở dữ liệu của trường Đại học sư phạm Hà Nội 2 (dạng demo) thụng qua việc phỏt biểu và phõn tớch cỏc bài toỏn.

Mỗi bào toỏn thể hiện kết quả rỳt gọn cõu vấn tin cho phõn mảnh ngang, phõn mảnh doc, phõn mảnh ngang dẫn xuất, phõn mảnh hỗn hợp.

KẾT LUẬN

Một vấn đề mà tất cả cỏc Hệ quản trị CSDL phải giải quyết là cơ sở dữ liệu phõn tỏn, xử lý song song. Cỏc phương phỏp thực hiện song song cõu vấn tin dựa vào luồng-tiến trỡnh, vào chức năng và vào dữ liệu đó được nhiều nhà tin học quan tõm phỏt triển. Luận văn này đó dành phần lớn trỡnh bày cỏc phương phỏp thực hiện song song cỏc cõu vấn tin trong cơ sở dữ liệu phõn tỏn dựa vào luồng-tiến trỡnh. Cỏc thuật toỏn được trỡnh bày, dựa trờn cấu trỳc luồng song song để rỳt gọn cõu vấn tin.

Luận văn đó ỏp dụng cỏc phương phỏp thực hiện song song cỏc cõu vấn tin trong cơ sở dữ liệu phõn tỏn dựa vào luồng vào ứng dụng tại Trường Đại học sư phạm Hà Nội 2.

Do thời gian và kiến thức cũn nhiều hạn chế nờn luận văn khụng trỏnh khỏi những thiếu sút vỡ vậy em rất mong nhận được sự gúp ý chõn thành từ quý thầy cụ và cỏc bạn đồng nghiệp để luận văn này được hoàn thiện hơn.

TÀI LIỆU THAM KHẢO

[1] Đoàn Văn Ban, Nguyễn Mậu Hõn, Xử lý song song và phõn tỏn,

NXB Khoa học và Kỹ thuật, 2006.

[2] Đỗ Xuõn Lụi, Cấu trỳc dữ liệu và giải thuật, NXB Khoa học và Kỹ thuật, 1996

[3] Lờ Huy Thập, Cơ sở lý thuyết song song, NXB Thụng tin và Truyền thụng, 8-2010

[4] Lờ Huy Thập, Giỏo trỡnh kỹ thuật lập trỡnh, Tập 1, NXB Khoa học Tự nhiờn và Cụng nghệ, 2008

[5] Lờ Huy Thập, Phõn mảnh trờn giỏ trị lặp của cỏc thuộc tớnh trong Cơ Sở Dữ Liệu quan hệ, Tạp chớ tin học và điều khiển học, Tập 23, Số 1, 86 – 98, 2007

[6] Lờ Huy Thập, Nguyờn lý Hệ Điều Hành, Bài giảng tại Học Viện Cảnh Sỏt Nhõn Dõn

[7] M.Tamer Ozsu, Patrick Valduriez. “Nguyờn lý cỏc hệ cơ dữ liệu phõn tỏn”. Trần Đức Quang biờn dịch. NXB Thống kờ, 1999

[8] Seyed H. Roo, “Parallel processing and Parallel Algorithms, Theory and Coputation”, Springer 1999

[9] Robert Sedgewick, Cẩm nang thuật toỏn Vol.1 and Vol.2. NXB Khoa học và Kỹ thuật, 2001

Một phần của tài liệu Thực hiện song song các câu vắn tin trong CSDL phân tán bằng cách sử dụng luồng (Trang 73)

Tải bản đầy đủ (PDF)

(100 trang)