home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / database / dbmax.zip / DBMAX.TXT
Text File  |  1986-11-11  |  33KB  |  793 lines

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