The MAGIC tool that builds the DDF's has been flawed for years -- but they don't seem interested in fixing it. Your only solution is to understand the structures and either recreate all new DDF's that do properly match the file structures, or to try to patch your existing DDF's to match..
Unfortunately, you didn't mention your PSQL version, and the methods to do either change depending on your version of the engine and what tools you have. With PSQL7, the tool you start with is DDFEase, which allows you to compare the DDF contents with the Btrieve files. With PSQL2000i and PSQLV8, you right-click on the database and select Tasks/Check Database. This brings up the Check Database Wizard which can allow you to run a full consistency check on the data. If you have PSQLv9, you must download the consistency check separately from Pervasive's website -- look for the ComponentZone in the developer area to find it, and the run this tool.
Once you know which files don't match (likely most of them, from my MAGIC experience), you'll know why your PHP scripts run slow. Any indices that don't match can be thrown out by the SQL engine, forcing a table scan in almost every case. Not a big deal for small databases, but if you join four (tiny) 1000-record files, a tablescan on all joins can force the system to examine 1,000,000,000,000 combinations -- and it will NOT be pretty.
So, how to fix it? With PSQL2000i and PSQLV8, you can use the built in table editor (Right Click the table, Edit Table Design) to modify the DDF structure. However, it is imperative that you verify upon entering this tool that you are in UNLINKED mode (lower right corner) before making any changes. If you are in LINKED mode, then you will change the Btrieve file, and will get errors from Magic. Look at the Tools or OPtions menu to change the mode. Once in UNLINKED mode, any changes you make will get changed in the DDF's ONLY, and the Btrieve files will be fine. Make any needed changes and save them. When done, run the consistency check once again to validate that it fixed the issues. When learning these tools, do one index and file at a time until you get the hang of what is needed.
If you have PSQLv9, the problem is worse -- you'll need the Pervasive DDF Builder product, available via free download from their website. Unfortunately, this tool is far from ideal and still has some serious flaws that limit its use. If you must do this, work slowly and make frequent backup copies.
My own personal favorite solution is to build a set of CREATE TABLE statements (and CREATE INDEX, too) for my database. With a bit of experience, you can build a CREATE TABLE statement that creates the DDF's and Btrieve file that EXACTLY matches the ones created by MAGIC. Once you can do this, the resulting DDF's will match the Btrieve files, and will be much less work overall than using the GUI tools to edit them one at a time. There are some cases whereby the CREATE statements do NOT create the same table, so some experimentation is also in order there. However, we've been successful at building CREATE statements for numerous customer databases, and these have the advantage of being easily modifiable and easy to reproduce -- just re-run the scripts.
Main Topics
Browse All Topics





by: mirtheilPosted on 2006-08-08 at 18:07:32ID: 17275930
Post a BUTIL -STAT of the data file.
Are you sure it's not using indexes? How have you determined that it's not using the indexes? Is it just "slow"?
Does the Query Plan show that it's using indexes?
What indexes are defined in the DDFs?
How were the DDFs created? Can you recreate them from within Magic and get indexes?