aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPDatabaseDocument.m
diff options
context:
space:
mode:
authorAbhi Beckert <abhi@abhibeckert.com>2017-03-03 11:06:34 +1000
committerGitHub <noreply@github.com>2017-03-03 11:06:34 +1000
commit8b69a9e3b1ab660fc22a5551ac21dcde33daee5e (patch)
treec8a078c09f6dc45556f190175807733336b4c227 /Source/SPDatabaseDocument.m
parentb87faacf805f76daaa5ad9e2e6e39efc3d558289 (diff)
parentcbf8095cddad4b214c776f355f7ae398763fe431 (diff)
downloadsequelpro-8b69a9e3b1ab660fc22a5551ac21dcde33daee5e.tar.gz
sequelpro-8b69a9e3b1ab660fc22a5551ac21dcde33daee5e.tar.bz2
sequelpro-8b69a9e3b1ab660fc22a5551ac21dcde33daee5e.zip
Merge pull request #2710 from abhibeckert/master
New URL for feedback reporter, and some other small things
Diffstat (limited to 'Source/SPDatabaseDocument.m')
-rw-r--r--Source/SPDatabaseDocument.m65
1 files changed, 65 insertions, 0 deletions
diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m
index c338224b..6b61a99e 100644
--- a/Source/SPDatabaseDocument.m
+++ b/Source/SPDatabaseDocument.m
@@ -856,6 +856,71 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0;
contextInfo:SPAlterDatabaseAction];
}
+- (IBAction)compareDatabase:(id)sender
+{
+ /*
+
+
+ This method is a basic experiment to see how long it takes to read an string compare an entire database. It works,
+ well, good performance and very little memory usage.
+
+ Next we need to ask the user to select another connection (from the favourites list) and compare chunks of ~1000 rows
+ at a time, ordered by primary key, between the two databases, using three threads (one for each database and one for
+ comparisons).
+
+ We will the write to disk every difference that has been found and open the result in FileMerge.
+
+ In future, add the ability to write all difference to the current database.
+
+
+ */
+ NSLog(@"=================");
+
+ SPMySQLResult *showTablesQuery = [mySQLConnection queryString:@"show tables"];
+
+ NSArray *tableRow;
+ while ((tableRow = [showTablesQuery getRowAsArray]) != nil) {
+ @autoreleasepool {
+ NSString *table = tableRow[0];
+
+ NSLog(@"-----------------");
+ NSLog(@"Scanning %@", table);
+
+
+ NSDictionary *tableStatus = [[mySQLConnection queryString:[NSString stringWithFormat:@"SHOW TABLE STATUS LIKE %@", [table tickQuotedString]]] getRowAsDictionary];
+ NSInteger rowCountEstimate = [tableStatus[@"Rows"] integerValue];
+ NSLog(@"Estimated row count: %li", rowCountEstimate);
+
+
+
+ SPMySQLResult *tableContentsQuery = [mySQLConnection streamingQueryString:[NSString stringWithFormat:@"select * from %@", [table backtickQuotedString]] useLowMemoryBlockingStreaming:NO];
+ //NSDate *lastProgressUpdate = [NSDate date];
+ time_t lastProgressUpdate = time(NULL);
+ NSInteger rowCount = 0;
+ NSArray *row;
+ while (true) {
+ @autoreleasepool {
+ row = [tableContentsQuery getRowAsArray];
+ if (!row) {
+ break;
+ }
+
+ [row isEqualToArray:row]; // TODO: compare to the other database, instead of the same one (just doing that to test performance)
+
+ rowCount++;
+ if ((time(NULL) - lastProgressUpdate) > 0) {
+ NSLog(@"Progress: %.1f%%", (((float)rowCount) / ((float)rowCountEstimate)) * 100);
+ lastProgressUpdate = time(NULL);
+ }
+ }
+ }
+ NSLog(@"Done. Actual row count: %li", rowCount);
+ }
+ }
+
+ NSLog(@"=================");
+}
+
#ifndef SP_CODA /* operations on whole databases */
/**
* opens the copy database sheet and copies the databsae