refine mysql index drop/creation, but redundant as have left Erics new commands in - mysql crawls with 10k hands! get postgres :-)

This commit is contained in:
sqlcoder 2009-07-29 07:57:18 +01:00
parent 38ee98e492
commit c2f79ddc24

View File

@ -62,9 +62,14 @@ class Database:
[ ] # no db with index 0 [ ] # no db with index 0
, [ ] # no db with index 1 , [ ] # no db with index 1
, [ # indexes for mysql (list index 2) , [ # indexes for mysql (list index 2)
{'tab':'Players', 'col':'name', 'drop':0} {'tab':'Players', 'col':'name', 'drop':0}
, {'tab':'Hands', 'col':'siteHandNo', 'drop':0} , {'tab':'Hands', 'col':'siteHandNo', 'drop':0}
, {'tab':'Tourneys', 'col':'siteTourneyNo', 'drop':0} , {'tab':'Hands', 'col':'gametypeId', 'drop':0} # mct 22/3/09
, {'tab':'HandsPlayers', 'col':'handId', 'drop':0} # not needed, handled by fk
, {'tab':'HandsPlayers', 'col':'playerId', 'drop':0} # not needed, handled by fk
, {'tab':'HandsPlayers', 'col':'tourneysTypeId', 'drop':0}
, {'tab':'HandsPlayers', 'col':'tourneysPlayersId', 'drop':0}
, {'tab':'Tourneys', 'col':'siteTourneyNo', 'drop':0}
] ]
, [ # indexes for postgres (list index 3) , [ # indexes for postgres (list index 3)
{'tab':'Gametypes', 'col':'siteId', 'drop':0} {'tab':'Gametypes', 'col':'siteId', 'drop':0}
@ -589,6 +594,7 @@ class Database:
Currently keeping the standalone indexes as needed to import quickly""" Currently keeping the standalone indexes as needed to import quickly"""
stime = time() stime = time()
c = self.get_cursor() c = self.get_cursor()
# sc: don't think autocommit=0 is needed, should already be in that mode
if self.backend == self.MYSQL_INNODB: if self.backend == self.MYSQL_INNODB:
c.execute("SET foreign_key_checks=0") c.execute("SET foreign_key_checks=0")
c.execute("SET autocommit=0") c.execute("SET autocommit=0")
@ -607,13 +613,13 @@ class Database:
"AND referenced_column_name = %s ", "AND referenced_column_name = %s ",
(fk['fktab'], fk['fkcol'], fk['rtab'], fk['rcol']) ) (fk['fktab'], fk['fkcol'], fk['rtab'], fk['rcol']) )
cons = c.fetchone() cons = c.fetchone()
#print "preparebulk: cons=", cons print "preparebulk find fk: cons=", cons
if cons: if cons:
print "dropping mysql fk", cons[0], fk['fktab'], fk['fkcol'] print "dropping mysql fk", cons[0], fk['fktab'], fk['fkcol']
try: try:
c.execute("alter table " + fk['fktab'] + " drop foreign key " + cons[0]) c.execute("alter table " + fk['fktab'] + " drop foreign key " + cons[0])
except: except:
pass print " drop failed: " + str(sys.exc_info())
elif self.backend == self.PGSQL: elif self.backend == self.PGSQL:
# DON'T FORGET TO RECREATE THEM!! # DON'T FORGET TO RECREATE THEM!!
print "dropping pg fk", fk['fktab'], fk['fkcol'] print "dropping pg fk", fk['fktab'], fk['fkcol']
@ -644,11 +650,13 @@ class Database:
if self.backend == self.MYSQL_INNODB: if self.backend == self.MYSQL_INNODB:
print "dropping mysql index ", idx['tab'], idx['col'] print "dropping mysql index ", idx['tab'], idx['col']
try: try:
# apparently nowait is not implemented in mysql so this just hands if there are locks # apparently nowait is not implemented in mysql so this just hangs if there are locks
# preventing the index drop :-( # preventing the index drop :-(
c.execute( "alter table %s drop index %s", (idx['tab'],idx['col']) ) c.execute( "alter table %s drop index %s;", (idx['tab'],idx['col']) )
except: except:
pass print " drop index failed: " + str(sys.exc_info())
# ALTER TABLE `fpdb`.`handsplayers` DROP INDEX `playerId`;
# using: 'HandsPlayers' drop index 'playerId'
elif self.backend == self.PGSQL: elif self.backend == self.PGSQL:
# DON'T FORGET TO RECREATE THEM!! # DON'T FORGET TO RECREATE THEM!!
print "dropping pg index ", idx['tab'], idx['col'] print "dropping pg index ", idx['tab'], idx['col']
@ -713,7 +721,7 @@ class Database:
+ fk['fkcol'] + ") references " + fk['rtab'] + "(" + fk['fkcol'] + ") references " + fk['rtab'] + "("
+ fk['rcol'] + ")") + fk['rcol'] + ")")
except: except:
pass print " create fk failed: " + str(sys.exc_info())
elif self.backend == self.PGSQL: elif self.backend == self.PGSQL:
print "creating fk ", fk['fktab'], fk['fkcol'], "->", fk['rtab'], fk['rcol'] print "creating fk ", fk['fktab'], fk['fkcol'], "->", fk['rtab'], fk['rcol']
try: try:
@ -722,7 +730,7 @@ class Database:
+ " foreign key (" + fk['fkcol'] + " foreign key (" + fk['fkcol']
+ ") references " + fk['rtab'] + "(" + fk['rcol'] + ")") + ") references " + fk['rtab'] + "(" + fk['rcol'] + ")")
except: except:
pass print " create fk failed: " + str(sys.exc_info())
else: else:
print "Only MySQL and Postgres supported so far" print "Only MySQL and Postgres supported so far"
return -1 return -1
@ -735,7 +743,7 @@ class Database:
c.execute( "alter table %s add index %s(%s)" c.execute( "alter table %s add index %s(%s)"
, (idx['tab'],idx['col'],idx['col']) ) , (idx['tab'],idx['col'],idx['col']) )
except: except:
pass print " create fk failed: " + str(sys.exc_info())
elif self.backend == self.PGSQL: elif self.backend == self.PGSQL:
# pass # pass
# mod to use tab_col for index name? # mod to use tab_col for index name?
@ -745,8 +753,7 @@ class Database:
c.execute( "create index %s_%s_idx on %s(%s)" c.execute( "create index %s_%s_idx on %s(%s)"
% (idx['tab'], idx['col'], idx['tab'], idx['col']) ) % (idx['tab'], idx['col'], idx['tab'], idx['col']) )
except: except:
print " ERROR! :-(" print " create index failed: " + str(sys.exc_info())
pass
else: else:
print "Only MySQL and Postgres supported so far" print "Only MySQL and Postgres supported so far"
return -1 return -1
@ -1614,7 +1621,7 @@ class HandToWrite:
self.tableName = None self.tableName = None
self.seatNos = None self.seatNos = None
except: except:
print "htw.init error: " + str(sys.exc_info) print "htw.init error: " + str(sys.exc_info())
raise raise
# end def __init__ # end def __init__
@ -1664,7 +1671,7 @@ class HandToWrite:
self.tableName = tableName self.tableName = tableName
self.seatNos = seatNos self.seatNos = seatNos
except: except:
print "htw.set_all error: " + str(sys.exc_info) print "htw.set_all error: " + str(sys.exc_info())
raise raise
# end def set_hand # end def set_hand