Speed up account loading on mysql (especially) by creating an index on the tx_guid field

of the splits table.  Without this, mysql can take a *really* long time to get the transactions
for an account.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18131 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Phil Longstaff
2009-06-14 03:36:40 +00:00
parent c04176b323
commit 558efe9c57

View File

@@ -56,7 +56,7 @@
#define TRANSACTION_TABLE "transactions"
#define TX_TABLE_VERSION 2
#define SPLIT_TABLE "splits"
#define SPLIT_TABLE_VERSION 2
#define SPLIT_TABLE_VERSION 3
typedef struct {
/*@ dependent @*/ GncSqlBackend* be;
@@ -434,6 +434,7 @@ static void
create_transaction_tables( GncSqlBackend* be )
{
gint version;
gboolean ok;
g_return_if_fail( be != NULL );
@@ -449,9 +450,26 @@ create_transaction_tables( GncSqlBackend* be )
version = gnc_sql_get_table_version( be, SPLIT_TABLE );
if( version == 0 ) {
(void)gnc_sql_create_table( be, SPLIT_TABLE, SPLIT_TABLE_VERSION, split_col_table );
} else if( version == 1 ) {
/* Upgrade 64 bit int handling */
gnc_sql_upgrade_table( be, SPLIT_TABLE, split_col_table );
ok = gnc_sql_create_index( be, "splits_tx_guid_index", SPLIT_TABLE, guid_col_table );
if( !ok ) {
PERR( "Unable to create index\n" );
}
} else if( version < SPLIT_TABLE_VERSION ) {
/* Perform the various upgrades based on the current version number */
switch( version ) {
case 1:
/* Upgrade 64 bit int handling */
gnc_sql_upgrade_table( be, SPLIT_TABLE, split_col_table );
/* fallthrough */
case 2:
ok = gnc_sql_create_index( be, "splits_tx_guid_index", SPLIT_TABLE, guid_col_table );
if( !ok ) {
PERR( "Unable to create index\n" );
}
}
(void)gnc_sql_set_table_version( be, SPLIT_TABLE, SPLIT_TABLE_VERSION );
}
}