Paul J Stevens wrote: > > I have this implemented already, and the loop now is through in no time. > > Moreover, my version is probably faster than yours - because no extra > > COUNT is needed, and because my db_get_result won't perform a single > > seek in all this loop! It checks if the row we want is the next row from > > the one already fetched, and if so, just fetches it! > > SHow me the code. against 2.0 or cvs I don't really care. This change > is so small and localized it doesn't > much matter. I too have fixed this, but I'm curious how you did it. > I've attached my own patch.
Attaching mine. (regular patch, not dpatch). Our patches are actually compatible, they're in fact against different files. Whether yours is needed after mine is up to you - I'm not sure either way. On a second thought, probably it is, because mine only gives an improvement for mysql. Mine might fix things in other places which I don't even know about. It basically improves speed every time one reads from several fields on the same row, AND when one reads one row and then the next. > > I think that any writing of mime-parsers today is a waste of developer > > time. There are many lying ready. > > Which is why I started using gmime. Agreed. > > But, what has a mime-parser got to do with the number of queries here? > > Joining all the queries, except the one for messageblks, into one or two > > big queries for ALL messages can be implemented with no changes in the > > mime parser, right? And even that will give us a 3 or 4 times better > > performance. > > When messages are retrieved by _ic_fetch, they are parsed by dbmail's > mime-parser in many cases, like for > retrieving a list of the message-headers. Didnt realize that. (I got lost in the code before this point). Yours, Mikhail Ramendik
--- mysql/dbmysql.c.orig 2004-06-03 16:41:55.000000000 +0400 +++ mysql/dbmysql.c 2004-10-23 16:10:31.000000000 +0400 @@ -1,6 +1,8 @@ /* Copyright (C) 1999-2004 IC & S [EMAIL PROTECTED] + Modified 2004 by Mikhail Ramendik [EMAIL PROTECTED] (MR) + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either @@ -49,6 +51,11 @@ static MYSQL_RES *stored_res = NULL; /**< MySQL result set backup */ static MYSQL_ROW last_row; /**< MySQL result row */ +/* Additions by MR */ + +static int res_changed = 1; /* result set changed */ +static unsigned last_row_number = 0; /* the number of the row in last_row */ + /** database parameters */ db_param_t _db_params; @@ -134,6 +141,7 @@ trace(TRACE_WARNING, "%s,%s: Trying to free result set " "that is already NULL!", __FILE__, __func__); res = NULL; + res_changed = 1; /*MR*/ } @@ -154,9 +162,28 @@ return NULL; } - mysql_data_seek(res, row); - last_row = mysql_fetch_row(res); + /*MR*/ + + if (res_changed) + + { + mysql_data_seek(res, row); + last_row = mysql_fetch_row(res); + } else { + if (row == last_row_number+1) + last_row = mysql_fetch_row(res); + else if (row != last_row_number) { + mysql_data_seek(res, row); + last_row = mysql_fetch_row(res); + }; + /* otherwise last_row is already loaded and does not need to change! MR*/ + }; + res_changed = 0; + last_row_number = row; + + /*MR changes end here*/ + if (last_row == NULL) { trace(TRACE_WARNING, "%s,%s: row is NULL\n", __FILE__, __func__); @@ -238,6 +265,7 @@ } res = mysql_store_result(&conn); + res_changed = 1; /*MR*/ return 0; } @@ -304,12 +332,14 @@ { stored_res = res; res = msgbuf_res; + res_changed = 1; /*MR*/ } void db_store_msgbuf_result() { msgbuf_res = res; res = stored_res; + res_changed = 1; /*MR*/ } void *db_get_result_set() @@ -320,4 +350,5 @@ void db_set_result_set(void *the_result_set) { res = (MYSQL_RES *) the_result_set; + res_changed = 1; /*MR*/ }