home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / mbug / mbug060.arc / CPM#006.LBR / DB2&3MAX.INF < prev    next >
Encoding:
Text File  |  1979-12-31  |  31.9 KB  |  793 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.                     Maximizing Performance with dBase II and III
  7.  
  8.                                   by Alan Simpson
  9.  
  10.                          Reprinted from "Personal Systems",
  11.                    The Journal of the San Diego Computer Society
  12.                Issues of November and December 1984 and January 1985
  13.                  Typed and Formatted by Rick Yount, Oak Harbor, WA
  14.                                    (206) 675-9797
  15.  
  16.            This article may be reprinted for any non-commercial purpose;
  17.                   please credit the Author and "Personal Systems".
  18.  
  19.                                  TABLE OF CONTENTS:
  20.  
  21.                    Trimming Minutes Down to Seconds ........... 1
  22.                    Don't Resort to Re-Sorting ................. 2
  23.                    Faster Sorts ............................... 4
  24.                    Faster Searching ........................... 4
  25.                    Faster Math ................................ 5
  26.                    Faster Reports ............................. 6
  27.                    Faster Copying ............................. 6
  28.                    Faster Edits ............................... 7
  29.                    Searching for Ranges ....................... 8
  30.                    Estimating Performance ..................... 8
  31.                    Managing Multiple Index Files .............. 9
  32.                    Trade-Offs ................................ 10
  33.                    Technical Rationale ....................... 12
  34.  
  35.  
  36.               Everyone wants the most out of their computer.  Granted, it's
  37.          nice that the computer can trim down to minutes what usually
  38.          requires humans hours to perform.  But then, nobody complains if
  39.          those computer minutes can be trimmed down to seconds.  In this
  40.          paper we'll discuss and compare general techniques for maximizing
  41.          the performance of dBase.  We'll trim some of those long dBase
  42.          processing minutes down to quick dBase seconds.
  43.  
  44.  
  45.          TRIMMING MINUTES DOWN TO SECONDS
  46.  
  47.               We'll begin by benchmarking (comparing) a few techniques for
  48.          performing some basic tasks with dBase II.  We'll use a simple
  49.          mailing list database as an example.  Its name is MAIL.DBF, and it
  50.          has this structure:
  51.  
  52.               FLD          NAME            TYPE        WIDTH      DEC
  53.  
  54.               001          LNAME            C          020        000
  55.               002          FNAME            C          020        000
  56.               003          ADDRESS          C          020        000
  57.               004          CITY             C          020        000
  58.               005          STATE            C          010        000
  59.               006          ZIP              C          010        000
  60.               007          AMOUNT           N          009        002
  61.          First, let's discuss various methods for sorting this database:
  62.  
  63.           ----------------------------------------------------------------
  64.              Maximizing dBase II and III Performance - by Alan Simpson
  65.                                        Page 1
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.          DON'T RESORT TO RE-SORTING
  75.  
  76.               There are basically four methods to maintain a sorted list of
  77.          items in a database.  The first is to simply CREATE the MAIL
  78.          database, add records to it, then sort it with the SORT command.
  79.          For example, suppose you CREATE MAIL and APPEND 999 records to it.
  80.          To add another record to it, and maintain an alphabetical listing
  81.          by last name, you would need to use the commands:
  82.  
  83.                    USE MAIL
  84.                    APPEND
  85.                    SORT ON LNAME TO TEMP
  86.  
  87.               This procedure would require about 940 seconds to re-sort a
  88.          database with 1000 records in it.
  89.  
  90.               Another method would be to USE MAIL, APPEND the new record,
  91.          then INDEX the file on the LNAME field, using the commands below:
  92.  
  93.                    USE MAIL
  94.                    APPEND
  95.                    INDEX ON LNAME TO NAMES
  96.  
  97.               This procedure requires about 530 seconds to re-sort the
  98.          1000-record database back into last name order
  99.  
  100.               A third method would be to locate the position in the
  101.          database that the new record belongs, and INSERT a new record into
  102.          its proper alphabetical place, as below:
  103.  
  104.                    USE MAIL
  105.                    LIST (to find the insertion point)
  106.                    INSERT
  107.  
  108.               The time required would be however long it takes you to find
  109.          the appropriate place to insert the new record, plus about 124
  110.          seconds for the INSERT command to rearrange the database.
  111.  
  112.               The fourth method is to create an index file of the field to
  113.          sort on, and keep that index file active while adding the new
  114.          record(s).  In most cases, the best time to index a file is
  115.          immediately after creating it, as in the commands below:
  116.  
  117.                    CREATE MAIL
  118.                    USE MAIL
  119.                    INDEX ON LNAME TO NAMES
  120.  
  121.               It only takes about two seconds to create the index file when
  122.          the database is empty.  At this point, the MAIL.DBF database and
  123.          the LNAME.NDX files exist on disk, but both are empty.  To add new
  124.          data, you would need to make the NAMES.NDX file active by typing
  125.          in the commands:
  126.  
  127.  
  128.  
  129.  
  130.           ----------------------------------------------------------------
  131.              Maximizing dBase II and III Performance - by Alan Simpson
  132.                                        Page 2
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.                    USE MAIL INDEX NAMES
  141.  
  142.               If you always USE MAIL INDEX NAMES when you add new data, the
  143.          index file will automatically be updated, therefore the data will
  144.          always be sorted.  So to add one record to the MAIL database with
  145.          999 records in it, you would type the commands:
  146.  
  147.                    USE MAIL INDEX NAMES
  148.                    APPEND
  149.  
  150.               There is no need to go through the INDEX ON procedure again,
  151.          because the NAMES.NDX file was active during the appending
  152.          procedure.  The time required to automatically re-sort the index
  153.          file using this method is a scant 3 seconds.  Add to that the
  154.          original two seconds for the INDEX ON command to create the
  155.          initial index file for a total of 5 seconds.  Table 1 compares the
  156.          processing times for the four methods (using a 16-bit computer
  157.          with 256K RAM, floppies, and dBase II Version 2.4):
  158.  
  159.          -------------------------------------------------------
  160.          Method       Commands Used                Time Required
  161.  
  162.          1            USE, APPEND and SORT         940 seconds
  163.          2            USE, APPEND and INDEX ON     530 seconds
  164.          3            USE, INSERT                  129 seconds
  165.          4            USE file1 INDEX file2 APPEND   5 seconds
  166.          -------------------------------------------------------
  167.          Table 1:  Sorting Times; Four Different Approaches
  168.  
  169.               Remember, you need to first create an index file based upon
  170.          the field(s) you wish the database to be sorted by.  Use the INDEX
  171.          ON command to create the index (.NDX) file.  For example, to
  172.          maintain an alphabetical listing of people on the MAIL database by
  173.          last name, type in the commands:
  174.  
  175.                    USE MAIL
  176.                    INDEX ON LNAME TO NAMES
  177.  
  178.               This creates and stores an index file called NAMES.NDX on
  179.          disk.  To make the index file active, specify its name in the USE
  180.          command, as below:
  181.  
  182.                    USE MAIL INDEX NAMES
  183.  
  184.               Once the file is made active in this way, any changes to the
  185.          database, whether they be through APPEND, EDIT, BROWSE, REPLACE,
  186.          PACK or READ will automatically re-sort and adjust the index file
  187.          accordingly.
  188.  
  189.               Avoiding the re-sorting process on only one way in which
  190.          index files can greatly improve the speed of a dBase II software
  191.          system. Most types of processing that involve searching can also
  192.          be accelerated.
  193.  
  194.  
  195.  
  196.  
  197.           ----------------------------------------------------------------
  198.              Maximizing dBase II and III Performance - by Alan Simpson
  199.                                        Page 3
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.               FASTER SORTS
  208.  
  209.               In some cases, a database should be physically sorted rather
  210.          than indexed.  For example, the UPDATE command works best if the
  211.          file you are updating FROM is physically pre-sorted.  You could
  212.          use the SORT command to create a sorted database called TEMP from
  213.          the MAIL database using the commands:
  214.  
  215.                    USE MAIL
  216.                    SORT ON LNAME TO TEMP
  217.  
  218.               This approach takes about 940 seconds, or about 15 minutes of
  219.          processing time.  If the NAMES index file already exists, you can
  220.          achieve the same result using the commands:
  221.  
  222.                    USE MAIL INDEX NAMES
  223.                    COPY TO TEMP
  224.  
  225.               Copying the contents of the indexed file only required about
  226.          326 seconds of processing time; about one-third the time.  When
  227.          you COPY an indexed file to another database, the records on the
  228.          database you copy to will be physically sorted.
  229.  
  230.  
  231.          FASTER SEARCHING
  232.  
  233.               Let's assume that the MAIL.DBF database already has 1,000
  234.          records on it.  Ten individuals on this database have the last
  235.          name (LNAME field) "Miller".   The question is:  Just how long
  236.          does it take to LIST, COUNT, or COPY all the "Miller"'s to another
  237.          database; or how long does it take to print a formatted REPORT
  238.          with only "Miller"'s, or to SUM the amounts for the "Miller"'s?
  239.          The answer, of course, is:  It depends on how you do it.
  240.  
  241.               For our benchmark comparisons, we'll assume that the database
  242.          has already been indexed on the LNAME field, using the commands:
  243.  
  244.                    USE MAIL
  245.                    INDEX ON LNAME TO NAMES
  246.  
  247.               Let's begin by comparing processing times using two different
  248.          command files and approaches.  The first method will use the
  249.          standard LIST FOR approach to fish out all the "Miller"'s.  The
  250.          command file looks like this:
  251.  
  252.                    ********** Method 1:  LIST FOR approach
  253.  
  254.                    ERASE
  255.                    USE MAIL INDEX NAMES
  256.                    ACCEPT " List all with what last name? " to SEARCH
  257.                    LIST FOR LNAME=SEARCH
  258.  
  259.               When you DO this command file, it clears the screen and
  260.          displays the prompt:
  261.  
  262.                    List all with what last name?
  263.  
  264.           ----------------------------------------------------------------
  265.              Maximizing dBase II and III Performance - by Alan Simpson
  266.                                        Page 4
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273.  
  274.  
  275.               Suppose you type in the name "Miller" and press the RETURN
  276.          key.  The program will then display the records of all ten
  277.          "Miller"'s on the screen.  The time required for the command file
  278.          to display the "Miller"'s and return to the dot prompt is about
  279.          148 seconds on a floppy disk system.  Almost two and a half
  280.          minutes.
  281.  
  282.               A second approach to solve this problem is to use the FIND
  283.          command to look up the first "Miller" in the NAMES index, then use
  284.          the WHILE option to display the remaining "Miller"'s in the
  285.          database, as in the program below:
  286.  
  287.                    ********** Method 2:  FIND and LIST WHILE approach
  288.  
  289.                    ERASE
  290.                    ACCEPT " List all with what last name? " to SEARCH
  291.                    FIND &SEARCH
  292.                    LIST WHILE LNAME = SEARCH
  293.  
  294.               Processing time for the second method to display all 10
  295.          "Miller"'s then redisplay the dot prompt on the screen, is less
  296.          than 9 seconds.  Table 2 compares processing times for the two
  297.          different methods.  Both methods perform exactly the same task,
  298.          but the processing times vary dramatically.
  299.  
  300.               -------------------------------------------------------
  301.               Method       Commands Used                Time Required
  302.  
  303.               1            LIST FOR                     148.75 seconds
  304.               2            FIND and LIST WHILE            8.94 seconds
  305.               --------------------------------------------------------
  306.               Table 2:  Comparison of Processing Times; Two Methods
  307.  
  308.  
  309.          FASTER MATH
  310.  
  311.               The FIND and WHILE approach with indexed databases can offer
  312.          significant time savings with dBase commands other than LIST.  For
  313.          example, if you want dBase to COUNT how many "Miller"'s are in the
  314.          database, you can use the commands:
  315.  
  316.                    USE MAIL
  317.                    COUNT FOR LNAME = "Miller"
  318.  
  319.               This approach requires about 55.5 seconds to display the fact
  320.          that there are 10 "Miller"'s in the database, then redisplay the
  321.          dot prompt.  You can cut this time down significantly using the
  322.          commands:
  323.  
  324.                    USE MAIL INDEX NAMES
  325.                    FIND Miller
  326.                    COUNT WHILE LNAME = "Miller"
  327.  
  328.               This approach performs the same task in about 3.20 seconds;
  329.          quite a significant time savings.
  330.  
  331.           ----------------------------------------------------------------
  332.              Maximizing dBase II and III Performance - by Alan Simpson
  333.                                        Page 5
  334.  
  335.  
  336.  
  337.  
  338.  
  339.  
  340.  
  341.  
  342.               Suppose you wish to SUM the AMOUNT field for just the
  343.          "Miller"'s?  You could use these commands:
  344.  
  345.                    USE MAIL
  346.                    SUM AMOUNT FOR LNAME = "Miller"
  347.  
  348.               Processing time using this method is about 58 seconds.  The
  349.          alternative approach uses these commands:
  350.  
  351.                    USE MAIL INDEX NAMES
  352.                    FIND "Miller"
  353.                    SUM AMOUNT WHILE LNAME = "Miller"
  354.  
  355.               This approach takes 5.28 seconds; less than one-tenth the
  356.          time.
  357.  
  358.  
  359.          FASTER REPORTS
  360.  
  361.               You can use the WHILE command with the REPORT command, also.
  362.          For example, suppose you've already created a formatted report
  363.          called MAILIST using the REPORT command.  To display all the
  364.          "Miller"'s on the formatted report, you could use the commands:
  365.  
  366.                    USE MAIL
  367.                    REPORT FORM MAILIST FOR LNAME = "Miller"
  368.  
  369.               This approach requires about 135.3 seconds to display all the
  370.          "Miller"'s on the report, then redisplay the dot prompt.  The
  371.          faster approach uses these commands:
  372.  
  373.                    USE MAIL INDEX NAMES
  374.                    FIND Miller
  375.                    REPORT FORM MAILIST WHILE LNAME = "Miller"
  376.  
  377.               These commands perform the same job in a slim 14.03 seconds.
  378.  
  379.  
  380.          FASTER COPYING
  381.  
  382.               For copying portions of the MAIL database to a database
  383.          called TEMP, the commands:
  384.  
  385.                    USE MAIL INDEX NAMES
  386.                    COPY TO TEMP FOR LNAME = "Miller"
  387.  
  388.          require a hefty 200.6 seconds; more than three minutes.  You can
  389.          perform the same job using these commands:
  390.  
  391.                    USE MAIL INDEX NAMES
  392.                    FIND Miller
  393.                    COPY TO TEMP WHILE LNAME = "Miller"
  394.  
  395.               These commands trim the copying time down to a comfortable
  396.          18.7 seconds.
  397.  
  398.           ----------------------------------------------------------------
  399.              Maximizing dBase II and III Performance - by Alan Simpson
  400.                                        Page 6
  401.  
  402.  
  403.  
  404.  
  405.  
  406.  
  407.  
  408.          FASTER EDITS
  409.  
  410.               Indexed files can also speed up the editing process.  For
  411.          example, suppose you want to BROWSE through the database to edit
  412.          data for one of the "Miller"'s.  One approach would be to type in
  413.          the commands:
  414.  
  415.                    USE MAIL
  416.                    BROWSE
  417.  
  418.               These commands will set up the dBase BROWSE screen with the
  419.          names and addresses in their original order, as displayed in
  420.          Figure 1:
  421.  
  422.  
  423.          LNAME--------------------FNAME------------------ADDRESS
  424.          Bond                     James                  007 Spy St.
  425.          Kenney                   Dave                   123 Clark St.
  426.          Newell                   Jeff                   341 Lou Drive
  427.          Mohr                     Richard                350 W. Leadora St.
  428.          Rosiello                 Rick                   999 Buddy Way
  429.          Wallace                  Doug                   345 Killer St.
  430.          Miller                   Mike                   601 Lemon Dr.
  431.  
  432.          Figure 1:  An unindexed BROWSE screen.
  433.  
  434.               You will need to use lots of CTRL-C commands to scroll
  435.          through the database to find the "Miller" you're looking for.
  436.          There's no telling how long it might take you to find the
  437.          particular "Miller" you wish to edit, because the "Miller"'s will
  438.          be placed randomly throughout the database.
  439.  
  440.               If, on the other hand, you use these commands to BROWSE:
  441.  
  442.                    USE MAIL INDEX NAMES
  443.                    FIND Miller
  444.                    BROWSE
  445.  
  446.               The BROWSE screen will display the first "Miller" on the
  447.          database, and all the remaining "Miller"'s immediately beneath, as
  448.          shown in Figure 2:
  449.  
  450.  
  451.          LNAME--------------------FNAME------------------ADDRESS
  452.          Miller                   Mollie                 601 Mission Blvd.
  453.          Miller                   Shiela                 1234 Genessee
  454.          Miller                   Ms. Stephanie S.       734 Rainbow Dr.
  455.          Miller                   Patti                  626 Mazda Way
  456.          Miller                   George                 P.O. Box 2802
  457.          Miller                   Julie                  999 Love St.
  458.          Miller                   Caron                  123 Princess Way
  459.          Miller                   Ms. Chrissie           321 Hynde St.
  460.          Miller                   Mrs. Sally S.          325 Seco Ct.
  461.          Miller                   Dr. James T.           701 Newport Dr.
  462.  
  463.          Figure 2:  A BROWSE screen with an indexed database
  464.  
  465.           ----------------------------------------------------------------
  466.              Maximizing dBase II and III Performance - by Alan Simpson
  467.                                        Page 7
  468.  
  469.  
  470.  
  471.  
  472.  
  473.  
  474.  
  475.               No need to go scrolling through pages and pages of BROWSE
  476.          screens to find the "Miller" you wish to edit, because all ten
  477.          "Miller"'s are displayed immediately and simultaneously on one
  478.          BROWSE screen.
  479.  
  480.               Similarly, if you wish to use the EDIT command to change the
  481.          data for a particular "Miller", you can use the commands:
  482.  
  483.                    USE MAIL INDEX NAMES
  484.                    FIND Miller
  485.                    EDIT WHILE LNAME = "Miller"
  486.  
  487.               These commands will quickly display the first "Miller" in the
  488.          database on the EDIT screen.  Each subsequent CTRL-C command will
  489.          immediately position you to the next "Miller" in the database.  So
  490.          once again, you can save a great deal of time by not having to
  491.          scroll around and search for individual "Miller"'s.
  492.  
  493.  
  494.          SEARCHING FOR RANGES
  495.  
  496.               The FIND and WHILE approach can also be used for searching
  497.          for ranges of data.  For example, if a database had a DATE field
  498.          with dates stored in MM/DD/YY format, and the database was indexed
  499.          on the date field, the following command file would list all
  500.          records between the requested starting and ending dates:
  501.  
  502.                USE file INDEX datefield
  503.                STORE "        " TO START, FINISH
  504.                @ 2,2 SAY "Enter Start Date " GET START PICTURE "99/99/99"
  505.                @ 4,2 SAY "Enter End Date " GET FINISH PICTURE "99/99/99"
  506.                READ
  507.  
  508.                FIND &START
  509.                LIST WHILE DATE <= FINISH
  510.                (This command file assumes that all dates have the same
  511.                year.  It's a little trickier when the data is spread across
  512.                several years
  513.  
  514.  
  515.          ESTIMATING PERFORMANCE
  516.  
  517.               Performance can be an important issue in developing a custom
  518.          dBase II software system.  Generally, processing times tend to
  519.          increase linearly with the size of a database.  Therefore, on a
  520.          database with 5,000 records in it, displaying all the "Miller"'s
  521.          could take as long as 740 seconds, a little over 12 minutes, with
  522.          the LIST FOR approach.  Using an indexed file with the FIND and
  523.          LIST WHILE approach will perform the same task in about 45
  524.          seconds, less than a minute.  Double those times for a database
  525.          with 10,000 record in it:  A whopping 24 minutes (almost a half
  526.          hour) with the FOR approach, vs. 88 seconds (under a minute and a
  527.          half) with the FIND and WHILE approach.
  528.  
  529.  
  530.  
  531.  
  532.           ----------------------------------------------------------------
  533.              Maximizing dBase II and III Performance - by Alan Simpson
  534.                                        Page 8
  535.  
  536.  
  537.  
  538.  
  539.  
  540.  
  541.  
  542.  
  543.               Keep in mind that any dBase command that allows the FOR
  544.          option will allow the WHILE option instead (e.g.  LIST, DISPLAY,
  545.          COPY, REPORT, SUM, COUNT, REPLACE, DELETE, TOTAL).  Therefore, any
  546.          of these processes can be greatly expedited with an index file and
  547.          the FIND and WHILE commands.
  548.  
  549.  
  550.          MANAGING MULTIPLE INDEX FILES
  551.  
  552.          In the previous examples, we compared processing times using an
  553.          index file called NAMES.  This index file contains only the LNAME
  554.          field.  Realistically, a mailing list will probably require two
  555.          separate sort orders;  1) a sort by last name and first name for
  556.          printing a directory listing, and 2) a sort by zip code for bulk
  557.          mailings.  In that case, you need to create two index files to
  558.          manage the two different sort orders.  One index file, which we'll
  559.          call NAMES, will keep the mailing list data in last name and first
  560.          name order.  A second index file, which we'll call ZIPS, will
  561.          maintain a zip code order for handling bulk mailings.  To create
  562.          both of these index files, you'll need to first CREATE the
  563.          MAIL.DBF database with the CREATE command, then immediately create
  564.          the two index files using the commands:
  565.  
  566.                    USE MAIL
  567.                    INDEX ON LNAME + FNAME TO NAMES
  568.                    INDEX ON ZIP TO ZIPS
  569.  
  570.               The MAIL.DBF database now has two index files associated with
  571.          it; NAMES.NDX and ZIPS.NDX.  You can keep both index files active
  572.          by using the command:
  573.  
  574.                    USE MAIL INDEX NAMES,ZIPS
  575.  
  576.               By specifying two index files in this fashion, all future
  577.          modifications to the database with the APPEND, EDIT, BROWSE, READ,
  578.          or REPLACE commands will  * *  AUTOMATICALLY  * *  update both
  579.          index files.
  580.  
  581.               If you LIST or DISPLAY ALL the records in the database, they
  582.          will be displayed in last name order, since NAMES is the first-
  583.          listed index file in the INDEX portion of the command line.
  584.  
  585.               Furthermore, you can only use the FIND command with the first
  586.          listed index, NAMES.  Therefore, to display all the records in the
  587.          database in zip code order, you need not go through the INDEX ON
  588.          ZIP TO ZIPS procedure again.  Instead, you can simply type in the
  589.          command:
  590.  
  591.                    SET INDEX TO ZIPS
  592.  
  593.               This eliminates the time required to sort the file again.
  594.          Before adding new records or editing the database, be sure to use
  595.          the commands:
  596.  
  597.  
  598.  
  599.           ----------------------------------------------------------------
  600.              Maximizing dBase II and III Performance - by Alan Simpson
  601.                                        Page 9
  602.  
  603.  
  604.  
  605.  
  606.  
  607.  
  608.  
  609.                    USE MAIL INDEX NAMES,ZIPS
  610.                    or
  611.                    USE MAIL INDEX ZIPS,NAMES
  612.  
  613.               This is required to make both index files active again.
  614.          Otherwise, you'll be likely to get a RECORD OUT OF RANGE error
  615.          sometime in the not too distant future.
  616.  
  617.  
  618.          TRADE-OFFS
  619.  
  620.               There are some trade-offs to contend with when using multiple
  621.          index files.  Generally, the more index files you have active at
  622.          any given moment, the longer it takes to perform an APPEND, EDIT
  623.          or REPLACE procedure.  For example, if you want to add records to
  624.          the MAIL database without any active index files, you can just use
  625.          the commands:
  626.  
  627.                    USE MAIL
  628.                    APPEND
  629.  
  630.               As you type in each new individual's data, the screen will
  631.          immediately accept each new record and re-display the next APPEND
  632.          screen.  However, if you decide to get carried away and create
  633.          four index files, and keep them all active as:
  634.  
  635.                    USE MAIL INDEX NAMES, ZIPS, CITIES, STATE
  636.  
  637.          You will notice a definite delay between the time you fill one
  638.          APPEND screen and the appearance of the next blank APPEND screen.
  639.          On a large data file with over 1,000 records in it, the delay
  640.          could be as much as 20 seconds, depending on how many fields are
  641.          in each index file and the RAM capacity of your computer.
  642.  
  643.               In general, one or two active index files are sufficient for
  644.          most databases.  The delays caused by one or two active index
  645.          files are relatively insignificant, and are more than compensated
  646.          for by the time savings that the FIND and WHILE commands offer, as
  647.          well as by the time savings gained by avoiding re-indexing.
  648.  
  649.               Another disadvantage to indexed files occurs during global
  650.          replaces.  For example, if for some reason you wished to set all
  651.          the AMOUNT fields back to zero in your hypothetical MAIL database,
  652.          you could use the commands:
  653.  
  654.                    USE MAIL INDEX NAMES,ZIPS
  655.                    REPLACE ALL AMOUNT WITH 0
  656.  
  657.               On a database with 1000 records in it, this process could
  658.          easily take 45 minutes.  However, the commands above waste
  659.          processing time by updating the index files when it is not
  660.          necessary to do so.
  661.  
  662.  
  663.  
  664.  
  665.  
  666.           ----------------------------------------------------------------
  667.              Maximizing dBase II and III Performance - by Alan Simpson
  668.                                       Page 10
  669.  
  670.  
  671.  
  672.  
  673.  
  674.  
  675.  
  676.               Recall that the NAMES index contains the LNAME and FNAME
  677.          fields, and the ZIPS index contains the ZIP field.  The AMOUNT
  678.          field is not used in either index file.  Therefore you can use the
  679.          NOUPDATE option (supplied in dBase Versions 2.4 and higher) to
  680.          perform the replace.  These commands:
  681.  
  682.                    USE MAIL INDEX NAMES,ZIPS
  683.                    REPLACE NOUPDATE ALL AMOUNT WITH 0
  684.  
  685.          perform the update in about six minutes.  The NOUPDATE option
  686.          informs dBase that, even though there are two active index files,
  687.          there is no need to update them while performing this REPLACE
  688.          command.
  689.  
  690.               There are some important points to keep in mind about the
  691.          INDEX and FIND commands.  First, the FIND command only works on an
  692.          indexed field.  If a database is in use with multiple index files,
  693.          the FIND command only works with the first listed index file.  For
  694.          example, if you open the MAIL data base with the two index files
  695.          as below:
  696.  
  697.                    USE MAIL INDEX ZIPS, NAMES
  698.  
  699.          the FIND command can only be used to locate a zip code.
  700.  
  701.               If the data to look up in a database is stored in a variable,
  702.          then the variable name must be "macro-ized" to be used with the
  703.          FIND command, as below:
  704.  
  705.                    ACCEPT "Look up whom? " to SEARCH
  706.                    FIND &SEARCH
  707.  
  708.               Also, FIND does not support functions or operators.  That is,
  709.          you cannot use the commands:  FIND Miller .OR. Smith or FIND
  710.          !(&SEARCH) nor FIND LNAME > &SEARCH.
  711.  
  712.               If you create two index files, but later add, edit, or delete
  713.          data with only one or neither of the index files active, the index
  714.          files will be corrupted, and you will most likely get a RECORD OUT
  715.          OF RANGE error at a later time.  In this case, both index files
  716.          must be re-created by typing in the commands:
  717.  
  718.                    USE MAIL
  719.                    INDEX ON LNAME + FNAME TO NAMES
  720.                    INDEX ON ZIP TO ZIPS
  721.  
  722.          or . . .
  723.  
  724.                    USE MAIL INDEX NAMES,ZIPS
  725.                    REINDEX
  726.  
  727.               Again, you can avoid the re-indexing by always keeping both
  728.          index files active with the command USE MAIL INDEX NAMES, ZIPS
  729.          when working with the database.
  730.  
  731.  
  732.  
  733.           ----------------------------------------------------------------
  734.              Maximizing dBase II and III Performance - by Alan Simpson
  735.                                       Page 11
  736.  
  737.  
  738.  
  739.  
  740.  
  741.  
  742.  
  743.          TECHNICAL RATIONALE
  744.  
  745.               From a technical standpoint, the reason that the FIND and
  746.          WHILE approach always dramatically outperforms the FOR approach is
  747.          quite simple.  Whenever you use the FOR option to perform a
  748.          search, dBase always starts accessing the records from record
  749.          number 1 and reads every single record directly from disk.
  750.          Therefore, if you had a database with 10,000 names in it, ten of
  751.          which were "Miller", dBase would perform 10,000 disk accesses to
  752.          display the 10 "Miller"'s.  Ten thousand disk accesses takes a
  753.          very, very long time.
  754.  
  755.               Many unnecessary disk accesses can be avoided by the fact
  756.          that dBase always stores an active index file in RAM (at least, as
  757.          much of it as will fit in RAM).  Furthermore, the index file is
  758.          always in sorted order in RAM.
  759.  
  760.               When you use the FIND command with an index file, dBase finds
  761.          the first "Miller" in the index file in RAM, which requires no
  762.          disk accesses.  Furthermore, the WHILE option only searches WHILE
  763.          (as long as) the search condition is true.  Therefore, dBase will
  764.          stop searching as soon as it encounters the first non-"Miller" in
  765.          the index file.  Since the index is already in sorted order,
  766.          "Miller"'s are all clumped together and disk accesses will stop as
  767.          soon as all the "Miller"'s have been displayed.
  768.  
  769.               So the FOR command requires 10,000 disk accesses to display
  770.          the ten "Miller"'s, while the FIND and WHILE approach only
  771.          requires 10 disk accesses; thereby eliminating 9,990 unnecessary
  772.          disk accesses and about 20 or 30 minutes of time depending on the
  773.          size of the database, the amount of RAM your computer has, and the
  774.          speed of your disk drives.
  775.  
  776.                                       - EOF -
  777.  
  778.  
  779.  
  780.  
  781.  
  782.  
  783.  
  784.  
  785.  
  786.  
  787.  
  788.  
  789.  
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796.  
  797.  
  798.  
  799.  
  800.           ----------------------------------------------------------------
  801.              Maximizing dBase II and III Performance - by Alan Simpson
  802.                                       Page 12
  803.  
  804.  
  805. √