Three pointers need to be established so that we know where to begin each linked list. These pointers, called heads, are stored separately from the data. The head of the $500 linked list is RRN1. Record 1 links to record 2, which in turn links to record 7. Record 7 has a zero in the link position, indicating that it is the end of the list. Consequently, the $500 credit limit set consists of records 1, 2, and 7. Similarly, the $700 set contains records 3, 5, and 10; the $1000 set contains relative records 4, 6, 8, 9, and 11.
The $1000-set linked list can be used to answer a query such as “How many accounts in the $1000 set have a balance in excess of 900?” In this way, only those records in the $1000 set need to be read from the file and examined. Although the advantage of this approach is not readily apparent in this small ex-ample, suppose that there are 100,000 CUSTOMER records, and only 100 of them are in the $1000 set. If there is no linked list, all 100,000 records must be examined; but with the linked list, only 100 records need to be examined—namely, the ones in the $1000 set. Using the linked list, therefore, saves 99,900 reads.
Using linked lists is not an effective technique for every secondary-key application. In particular, if the records are processed nonsequentially in a set, linked lists are inefficient. For example, if it is often nec-essary to find the 10th or 120th or nth record in the $500 CreditLimit set, processing will be slow. Linked lists are inefficient for direct access.
In addition, if the application requires that secondary keys be created or destroyed dynamically, the linked-list approach is undesirable. Whenever a new key is created, a link field must be added to every record, which often requires reorganizing the database, which is a time-consuming and expensive pro-cess.
Finally, if the secondary keys are unique, each list will have a length of one, and a separate linked list will exist for every record in the database. Because this situation is unworkable, linked lists cannot be used for unique keys. For example, suppose that the CUSTOMER records contain another unique field, say, Social Security Number. If we attempt to represent this unique secondary key using a linked list, every Social Security Number will be a separate linked list. Furthermore, each linked list will have just one item in it: the single record having the indicated Social Security Number.
How Can We Represent Secondary Keys with Indexes?
A second technique for representing secondary keys uses an index; one is established for each second-ary key. The approach varies, depending on whether the key values are unique or nonunique.
Unique Secondary Keys
Suppose that the CUSTOMER records in Figure H-33 contain Social Security Numbers (SSN) as well as the fields shown. To provide key access to the CUSTOMER records using SSN, we simply build an index on the SSN field. Sample CUSTOMER data are shown in Figure H-35(a), and a corresponding index is illus-trated in Figure H-35(b). This index uses relative record numbers as addresses. It is possible to use
สามตัวชี้จำเป็นต้องได้รับการจัดตั้งขึ้นเพื่อให้เราทราบว่าจะเริ่มในแต่ละรายการที่เชื่อมโยง คำแนะนำเหล่านี้เรียกว่าหัวจะถูกเก็บไว้แยกต่างหากจากข้อมูล หัวของรายการที่เชื่อมโยง $ 500 เป็น RRN1 ระเบียน 1 การเชื่อมโยงในการบันทึก 2 ซึ่งในการเชื่อมโยงการเปิดการบันทึก 7. บันทึก 7 มีศูนย์อยู่ในตำแหน่งที่ลิงค์แสดงให้เห็นว่ามันเป็นจุดสิ้นสุดของรายการ ดังนั้น $ 500 วงเงินชุดประกอบด้วยระเบียน 1, 2, 7 และในทำนองเดียวกันชุดที่ $ 700 มีระเบียน 3, 5 และ 10; ชุดที่ $ 1,000 มีระเบียนญาติ 4, 6, 8, 9, และ 11
$ การ 1000 ชุดรายการที่เชื่อมโยงสามารถนำมาใช้ในการตอบแบบสอบถามเช่น "วิธีหลายบัญชีในชุดที่ $ 1000 มียอดเงินในส่วนที่เกิน 900 หรือไม่?" ใน วิธีนี้เฉพาะระเบียนผู้ที่อยู่ใน $ 1,000 ชุดจะต้องมีการอ่านจากแฟ้มและตรวจสอบ แม้ว่าจะได้เปรียบของวิธีนี้คือไม่พร้อมที่เห็นได้ชัดในขนาดเล็กนี้อดีตเพียงพอที่คิดว่ามี 100,000 ระเบียนของลูกค้าและมีเพียง 100 ของพวกเขาอยู่ใน $ 1,000 ชุด ถ้าไม่มีรายการที่เชื่อมโยงทั้งหมด 100,000 ระเบียนต้องถูกตรวจสอบ; แต่มีรายการที่เชื่อมโยงเพียง 100 บันทึกจะต้องมีการตรวจสอบ-คือคนที่อยู่ใน $ 1,000 ชุด ใช้รายการที่เชื่อมโยงจึงช่วยประหยัด 99,900 อ่าน.
ใช้รายการที่เชื่อมโยงไม่ได้เป็นเทคนิคที่มีประสิทธิภาพสำหรับทุกโปรแกรมที่สองที่สำคัญ โดยเฉพาะอย่างยิ่งถ้าระเบียนที่มีการประมวลผล nonsequentially ในชุดรายการที่เชื่อมโยงจะไม่มีประสิทธิภาพ ตัวอย่างเช่นถ้ามันมักจะมิได้-essary หา 10 หรือ 120 หรือบันทึกที่ n ในชุด CreditLimit $ 500, การประมวลผลจะช้า รายการที่เชื่อมโยงจะไม่มีประสิทธิภาพสำหรับการเข้าถึงโดยตรง.
นอกจากนี้ถ้าสมัครต้องว่าคีย์รองถูกสร้างขึ้นหรือถูกทำลายแบบไดนามิกวิธีการเชื่อมโยงรายการเป็นที่ไม่พึงประสงค์ เมื่อใดก็ตามที่คีย์ใหม่จะถูกสร้างขึ้นที่สนามการเชื่อมโยงจะต้องเพิ่มทุกระเบียนซึ่งมักจะต้องมีการจัดระเบียบฐานข้อมูลซึ่งเป็นที่ใช้เวลานานและมีราคาแพงโปรภาษี.
สุดท้ายหากแป้นรองจะไม่ซ้ำกันในแต่ละรายการจะมี ความยาวของหนึ่งและรายการที่เชื่อมโยงที่แยกจากกันจะมีอยู่สำหรับการบันทึกในฐานข้อมูลทุก เพราะสถานการณ์นี้คือทำไม่ได้, รายการที่เชื่อมโยงไม่สามารถใช้สำหรับคีย์ที่ไม่ซ้ำกัน ตัวอย่างเช่นสมมติว่าระเบียนลูกค้าประกอบด้วยเขตข้อมูลที่ไม่ซ้ำกันอีกพูด, หมายเลขประกันสังคม ถ้าเราพยายามที่จะเป็นตัวแทนที่สำคัญรองที่ไม่ซ้ำกันโดยใช้รายการที่เชื่อมโยงทุกหมายเลขประกันสังคมจะเป็นรายการที่เชื่อมโยงแยกต่างหาก นอกจากนี้ในแต่ละรายการที่เชื่อมโยงจะมีเพียงหนึ่งรายการในมันบันทึกเดียวที่มีการระบุหมายเลขประกันสังคม.
วิธีที่เราสามารถเป็นตัวแทนของคีย์รองกับดัชนี?
เทคนิคที่สองสำหรับการเป็นตัวแทนของแป้นรองใช้ดัชนี; อย่างใดอย่างหนึ่งที่จะจัดตั้งขึ้นสำหรับแต่ละที่สำคัญสอง Ary วิธีแตกต่างกันไปขึ้นอยู่กับว่าค่าที่สำคัญคือไม่ซ้ำกันหรือ nonunique.
ที่ไม่ซ้ำมัธยมศึกษาคีย์สมมติว่าระเบียนลูกค้าในรูป H-33 มีหมายเลขประกันสังคม (SSN) เช่นเดียวกับสาขาที่แสดง
เพื่อให้การเข้าถึงที่สำคัญในการบันทึกลูกค้าโดยใช้ SSN เราก็สร้างดัชนีในเขต SSN ข้อมูลตัวอย่างลูกค้าจะแสดงในรูป H-35 (ก) และดัชนีที่สอดคล้องกัน illus-trated ในรูป H-35 (ข) ดัชนีนี้จะใช้การบันทึกหมายเลขญาติที่อยู่ มันเป็นไปได้ที่จะใช้
การแปล กรุณารอสักครู่..
