Starting from:

$25

DBMS -Database Systems Lab  - SESSION 4 - Solved

Table scan: Linear search on a non-indexed field
 

In this lab session, you will build search in Personal Data Store (PDS) based on a non-indexed field. You are expected to read the data from the data file one block at a time and do a linear search in each block until the requisite record is found.

Main PDS functions
 

A)   pds_open 

No change from Session 3

 

B)   put_rec_by_key 

No change from Session 3

 

C)   get_rec_by_key  rename to get_rec_by_ndx_key 

No change from Session 3

 

D)  pds_close 

No change from Session 3

 

E) get_rec_by_non_ndx_key
This is a new search function you need to add to PDS for the purpose of searching based on a key field on which an index does not exist. This function actually does a full table scan by reading the data file until the desired record is found.

 

int get_rec_by_non_ndx_key(  

                void *key,                 /* The search key */ 

                void *rec,                 /* The output record */ 

int (*matcher)(void *rec, void *key), /*Function pointer for matching*/ int *io_count                 /* Count of the number of records read */ );  

 

F) contact.c changes
Add the following functions to contact.c

 

// Import/Load all the contacts from a given file 

// Input data file is a text file containing one contact record per line with space-separate fields  

int import_contacts( char *contact_data_file ); 

 

// Use get_rec_by_non_ndx_key function to search contact int search_contact_by_phone( struct Contact *c, char *phone ); 

 

//Return 0 if phone of the contact matches with phone parameter 

// Return 1 if phone of the contact does NOT match // Return > 1 in case of any other error 

int match_contact_phone( struct Contact *c, char *phone ); 

                 

Testing
a.       Use the given contact_loader.c program to import contacts in bulk for testing. Input file with data is given to you.

b.       The following driver program is given to you:

•   pds_tester.c (generic testing with input data file like testcase.in).

•   This file takes a file with commands such as (CREATE, STORE, RETRIEVE, OPEN, CLOSE) inside.

c.       Test your program thoroughly with the above driver program with the test input file

d.       Do additional testing by creating your own test input files

Commands
A.      Use the following command for creating contact_loader executable:

gcc -o contact_loader bst.c contact.c pds.c 
Use contact loader to import data using the following command: 

Contact_loader contact_dump.txt 
B.      Use the following command for creating pds_tester executable:

gcc -o pds_tester bst.c contact.c pds.c pds_tester.c 
For testing using pds_tester, use the following command: 

pds_tester testcase.in 
Testing
1.       Use the contact loader program given to you for loading a large number of records into PDS.

2.       Test your program with various RETRIEVE functions with the help of modified pds_tester.c given to you.

More products