Skip to content

copy_dm_to() generates unchunked INSERT … VALUES on MSSQL since 1.1.0 #2467

Description

@Layalchristine24

Summary

copy_dm_to() hangs against SQL Server (FreeTDS) in dm 1.1.0+ when used as a staging step before dm_rows_append(). Same pipeline completes on dm 1.0.4 (slowly but reliably).

Likely cause: the 1.1.0 change to have copy_dm_to() create key constraints on the database (#1887, #2022). Our destination tables already have PK/UK/FK constraints defined, so the auto-setup probably races on SQL Server metadata locks.

Versions

dm version result
1.0.4 works (slow)
1.1.1 hangs
1.1.2 hangs

(1.1.0 not retested. 1.1.1 was only an igraph-fallback fix on top of 1.1.0, so 1.1.0 is the suspect.)

Environment

  • R 4.6.0, macOS x86_64
  • FreeTDS ODBC driver, Microsoft SQL Server
  • Destination tables have clustered compound PKs, FKs with ON DELETE CASCADE, some with NONCLUSTERED INDEXes

Pipeline

append_data <- function(con, dm_table, data) {
  my_dm <- dm::dm_from_con(con)
  table_name <- as.name(dm_table)
  staged <- dm::copy_dm_to(con, dm::dm(!!table_name := data))  # hangs here on 1.1.x
  dm::dm_rows_append(my_dm, staged, in_place = TRUE)
}

Called for three tables (~150k, ~137k, ~83k rows) sequentially. On 1.0.4 the whole sequence completes in ~14 min. On 1.1.x, copy_dm_to START is logged, then nothing.

Concrete log:

[10:13:16] Appending 3 dm table(s): table1 (149423 rows), table2 (136941 rows), table3 (82762 rows)
[10:13:16] append_data START: table1 (149423 rows)
[10:13:17]   copy_dm_to START: uploading 149423 rows...
[10:19:17]   copy_dm_to done (359.7s)
[10:19:17]   dm_rows_append START...
[10:19:30]   dm_rows_append done (12.8s)
[10:19:30] append_data START: table2 (136941 rows)
[10:19:31]   copy_dm_to START: uploading 136941 rows...
[10:24:31]   copy_dm_to done (299.3s)
[10:24:31]   dm_rows_append START...
[10:25:19]   dm_rows_append done (47.9s)
[10:25:19] append_data START: table3 (82762 rows)
[10:25:20]   copy_dm_to START: uploading 82762 rows...
[10:26:32]   copy_dm_to done (71.6s)
[10:26:32]   dm_rows_append START...
[10:26:52]   dm_rows_append done (20.3s)

Workaround

pak::pak("cynkra/dm@v1.0.4")
# or: remotes::install_version("dm", version = "1.0.4")

Question

Is there a way (in 1.1.x or planned) to skip constraint creation in copy_dm_to() when the destination already exists with the right schema? Our destination table already has all its constraints defined (via DDL elsewhere). copy_dm_to() only needs to stage the rows in a throwaway temp table so dm_rows_append() can copy them into the real destination. Setting up constraints during the staging step isn't needed in this use case.

Happy to gather a fuller trace if useful.

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions