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 example,
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 necessary
to find the 10th or 120th or n
th 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 process.
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 secondary
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 illustrated
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
และ. โดย$ 1,000 ชุดเชื่อมโยงรายการสามารถใช้ในการตอบแบบสอบถามเช่น "วิธีการหลายบัญชีใน $ 1,000
ชุดมีความสมดุลในส่วนที่เกินจาก900?" ใน วิธีนี้เฉพาะระเบียนผู้ที่อยู่ใน $ 1,000
ชุดจะต้องมีการอ่านจากไฟล์และการตรวจสอบ แม้ว่าข้อดีของวิธีนี้ไม่ได้อย่างง่ายดายในตัวอย่างเล็ก ๆ
นี้คิดว่ามี100,000 ระเบียนของลูกค้าและมีเพียง 100 ของพวกเขาอยู่ใน $ 1,000 ชุด ถ้าไม่มีรายการที่เชื่อมโยงทั้งหมด 100,000 ระเบียนต้องถูกตรวจสอบ;
แต่มีรายการที่เชื่อมโยงเพียง 100 บันทึกจะต้องมีการตรวจสอบ-คือคนที่อยู่ใน $ 1,000 ชุด
ใช้รายการที่เชื่อมโยงจึงช่วยประหยัด 99,900
อ่าน.
ใช้รายการที่เชื่อมโยงไม่ได้เป็นเทคนิคที่มีประสิทธิภาพสำหรับทุกโปรแกรมที่สองที่สำคัญ โดยเฉพาะอย่างยิ่งถ้าบันทึกมีการประมวลผล nonsequentially ในชุดรายการที่เชื่อมโยงจะไม่มีประสิทธิภาพ
ตัวอย่างเช่นถ้ามันมักจะเป็นสิ่งที่จำเป็นที่จะหา 10 หรือ 120 หรือ n วันที่บันทึกอยู่ในชุด CreditLimit $ 500, การประมวลผลจะช้า เชื่อมโยงรายการจะไม่มีประสิทธิภาพสำหรับการเข้าถึงโดยตรง. นอกจากนี้ถ้าสมัครต้องว่าคีย์รองถูกสร้างขึ้นหรือถูกทำลายแบบไดนามิกที่วิธีการเชื่อมโยงรายการที่ไม่พึงประสงค์ เมื่อใดก็ตามที่คีย์ใหม่จะถูกสร้างขึ้นที่สนามการเชื่อมโยงจะต้องเพิ่มทุกบันทึกซึ่งมักจะต้องมีการจัดระเบียบฐานข้อมูลซึ่งเป็นกระบวนการที่ใช้เวลานานและมีราคาแพง. สุดท้ายหากแป้นรองจะไม่ซ้ำกันในแต่ละรายการจะมีความยาวของ หนึ่งและรายการที่เชื่อมโยงที่แยกจากกันจะมีอยู่สำหรับทุกระเบียนในฐานข้อมูล เพราะสถานการณ์นี้คือทำไม่ได้, รายการที่เชื่อมโยงไม่สามารถใช้สำหรับคีย์ที่ไม่ซ้ำกัน ตัวอย่างเช่นสมมติว่าระเบียนลูกค้าประกอบด้วยเขตข้อมูลที่ไม่ซ้ำกันอีกพูด, หมายเลขประกันสังคม ถ้าเราพยายามที่จะเป็นตัวแทนที่สำคัญรองที่ไม่ซ้ำกันโดยใช้รายการที่เชื่อมโยงทุกหมายเลขประกันสังคมจะเป็นรายการที่เชื่อมโยงแยกต่างหาก นอกจากนี้ในแต่ละรายการที่เชื่อมโยงจะมีเพียงหนึ่งรายการในมันบันทึกเดียวที่มีการระบุหมายเลขประกันสังคม. วิธีที่เราสามารถเป็นตัวแทนของคีย์รองกับดัชนี? เทคนิคที่สองสำหรับการเป็นตัวแทนของแป้นรองใช้ดัชนี; อย่างใดอย่างหนึ่งที่จะจัดตั้งขึ้นสำหรับแต่ละรองที่สำคัญ วิธีแตกต่างกันไปขึ้นอยู่กับว่าค่าที่สำคัญคือไม่ซ้ำกันหรือ nonunique. ที่ไม่ซ้ำมัธยมศึกษาคีย์สมมติว่าระเบียนลูกค้าในรูป H-33 มีหมายเลขประกันสังคม (SSN) เช่นเดียวกับสาขาที่แสดงให้เห็น เพื่อให้การเข้าถึงที่สำคัญในการบันทึกลูกค้าโดยใช้ SSN เราก็สร้างดัชนีบนสนามSSN ข้อมูลตัวอย่างลูกค้าจะแสดงในรูป H-35 (ก) และดัชนีที่สอดคล้องกันจะแสดงในรูปที่H-35 (ข) ดัชนีนี้จะใช้การบันทึกหมายเลขญาติที่อยู่ มันเป็นไปได้ที่จะใช้
การแปล กรุณารอสักครู่..
