Skip to content

Perf issue with dbWriteTable : RMariaDB much slower than RMySQL (from 2 to 40 times), and it's worse with a remote db #162

@ericemc3

Description

@ericemc3

I experiment writing a table (a tibble: 34,951 x 52) into a MySQL database (5.6):

MySQL database on localhost (same computer):

  • RMySQL = 3.4s
  • RMariaDB = 8s

remote MySQL database:

  • RMySQL = 11s
  • RMariaDB : R still running after 5mn, i have to kill it

remote MySQL database with a reduced table (586 x 52):

  • RMySQL = 0.4s
  • RMariaDB = 16s
library(tidyverse) 
library(readxl) 
library(RMySQL) 
library(RMariaDB) 
library(curl) 

urlhebtour <- "https://insee.fr/fr/statistiques/fichier/2021703/base-cc-tourisme-2020.zip"
xlsfile    <- unzip( curl_download( urlhebtour, "temp.zip" ) )  

dt <- read_excel( xlsfile, sheet = "COM", skip = 5 ) %>% select(-LIBGEO) 

# RMySQL test on localhost
db_cred = list( drv = MySQL(), host="localhost", dbname="donstat", user="xxx", password="xxx" )
mycon <- exec( "dbConnect", !!!db_cred ) 

system.time( dbWriteTable( mycon, value = dt, name = "tourism2020", 
                                    overwrite = TRUE, row.names = FALSE ) )
# RMySQL 3.4s

tbl(mycon, "tourism2020") %>% collect()
# A tibble: 34,951 x 52

dbDisconnect(mycon)  

# RMariaDB test on localhost
db_cred <- list( drv = MariaDB(), host="localhost", dbname="donstat", user="xxx", password="xxx" )
mycon <- exec( "dbConnect", !!!db_cred ) 

system.time( dbWriteTable( mycon, value = dt, name = "tourism2020", 
                                       overwrite = TRUE, row.names = FALSE ) )
# RMariaDB 8s

tbl(mycon, "tourism2020") %>% collect()
# A tibble: 34,951 x 52

With a remote database and RMariaDB, it doesn't end

So let's try with a reduced tibble (=> 586 rows)

system.time( dbWriteTable( mycon, value = dt %>% filter(DEP == "31"), name = "tourism2020", overwrite = TRUE, row.names = FALSE ) )

# RMySQL   = 0.4s
# RMariaDB = 16s

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions