Files
phpmyadmin/libraries/get_foreign.lib.php
Garvin Hicking b8df10e41e Get rid of mysql_data_seek(). Use pre-cached PHP array for mysqli
compatibility and bandwidth saving.

Memory issues by caching should not arise, as the used cache will (in our
previously used cases) only cache index fields and max. 200 relation rows.

I tested performance on my machine: By fetching 400kb of data twice via
mysql_fetch_row() -> mysql_data_seek() -> mysql_fetch_row() this was
performed in 0.25 seconds. By fetching it once and caching in a PHP array
via mysql_fetch_row -> foreach this is performed in 0.32 seconds.

With usual data as used in PMA (10kb) I could only detect a performance
change of 0.009 seconds, which is respectable I think.

By not using mysql_data_seek we are later able to use global mysqli
USE_RESULT options to fetch rows singly. I discussed that yesterday with
Rabus, and if there are any objections we can surely discuss that further on
the list.
2004-01-28 11:23:38 +00:00

59 lines
2.4 KiB
PHP

<?php
/* $Id$ */
// vim: expandtab sw=4 ts=4 sts=4:
/**
* Gets foreign keys in preparation for a drop-down selector
* Thanks to <markus@noga.de>
*/
// lem9: we always show the foreign field in the drop-down; if a display
// field is defined, we show it besides the foreign field
$foreign_link = false;
if ($foreigners && isset($foreigners[$field])) {
$foreigner = $foreigners[$field];
$foreign_db = $foreigner['foreign_db'];
$foreign_table = $foreigner['foreign_table'];
$foreign_field = $foreigner['foreign_field'];
// Count number of rows in the foreign table. Currently we do
// not use a drop-down if more than 200 rows in the foreign table,
// for speed reasons and because we need a better interface for this.
//
// We could also do the SELECT anyway, with a LIMIT, and ensure that
// the current value of the field is one of the choices.
$the_total = PMA_countRecords($foreign_db, $foreign_table, TRUE);
if ((isset($override_total) && $override_total == true) || $the_total < 200) {
// foreign_display can be FALSE if no display field defined:
$foreign_display = PMA_getDisplayField($foreign_db, $foreign_table);
$dispsql = 'SELECT ' . PMA_backquote($foreign_field)
. (($foreign_display == FALSE) ? '' : ', ' . PMA_backquote($foreign_display))
. ' FROM ' . PMA_backquote($foreign_db) . '.' . PMA_backquote($foreign_table)
. (($foreign_display == FALSE) ? '' :' ORDER BY ' . PMA_backquote($foreign_table) . '.' . PMA_backquote($foreign_display))
. (isset($foreign_limit) ? $foreign_limit : '');
$disp = PMA_DBI_query($dispsql);
if ($disp) {
// garvin: If a resultset has been created, pre-cache it in the $disp_row array
// This helps us from not needing to use mysql_data_seek by accessing a pre-cached
// PHP array. Usually those resultsets are not that big, so a performance hit should
// not be expected.
$disp_row = array();
while ($single_disp_row = @PMA_DBI_fetch_assoc($disp)) {
$disp_row[] = $single_disp_row;
}
@PMA_DBI_free_result($disp);
}
}
else {
unset($disp);
$foreign_link = true;
}
} // end if $foreigners
?>