Fastest Method for Mass Inserts

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default Re: Fastest Method for Mass Inserts

    TheOriginalJman wrote:
    > HELP, I've been using ColdFusion for years and keep running into the same wall
    > on various projects, now the need is desperate. I need to insert between
    > 60,000 and 100,000 records at a time into a database. CFMX7 with MySQL 5 as
    not particular to mysql but doing it db to db is always better. having
    no idea what mysql supports, see if this makes sense. if it isn't easily
    accomplished natively (anything like sql server's DTS or ftp/bulk
    insert?), dump the out as CSV or whatever mysql will swallow, copy that
    between servers & use whatever myql's import tool is to re-import that
    data. this is usually best done against a "transfer" table w/out any
    indexes. the merging can be done after the data is in the transfer
    table. does mysql have index types that ignore duplicates (ie when a
    duplicate row is found during an insert, it's ignored & not inserted)?
    if so, use those to do the merge. otherwise, does this version of mysql
    support sub-queries? if so, use those to do the merge.

    if none of this is possible, i suppose you might try the JDBC driver
    instead of the ODBC one to see if that improves things & do the cfquery
    transfer in small batches.
    PaulH *TMM* Guest

  2. Similar Questions and Discussions

    1. What's the fastest way to reload textures?
      Im in a situation where I need to first alter a texture via copyPixels() and then reload it. So I was wondering, what's the fastest way to reload...
    2. What's the fastest method to populate data into GRID
      Hi Everyone, I have ASP.NET application which is working fine in the Country lever having 20+ remote users. Speed, performance everything is ok...
    3. fastest way to parse pop mails?
      hi there :-) how would you solve the following problem? i am writing a small mailchecker atm, which needs to receive all headers to show them in...
    4. Fastest FSO loop question
      Well I have seen this posted before and haven't seen much in response. My application has to browse through various folders and find file names....
    5. which the fastest way of working with recordset ?
      In general, DAO will be faster with data stored in Access (Jet). Frank, you probably know enough to set up a timing trial with your actual data,...
  3. #2

    Default Re: Fastest Method for Mass Inserts

    I've tried the transfer server to server, but becasue of firewalls and other
    concerns, I must use a queries only, and must allow CF to control the data
    flow. The subquery Idea is interesting. I'm not sure of how to do that
    though. The two tables are in different datasources making it a little more
    difficult. Mysql does support suqueries, and I use them often, but have only
    delt with tables in the same datasource.

    The DB does support ignoring dupes, however, CF seems to through an error when
    they occur, When I was using the raw dumps for transfering I had no problem
    with dupes, but since I can only use CF, the dumps are not an option.

    On the ODBC subject, I miss stated, I am using jdbc, as that is the only
    connection to MYSQL 5 that CF 7 can use at the current time. Thanks so much
    for these ideas. If you could give me an idea of using the subueries idea that
    would welcomed indeed, especially if this can be done without using a <cfloop>
    to loop through the query.

    Thanks so much for the ideas so far.

    -J

    TheOriginalJman Guest

  4. #3

    Default Re: Fastest Method for Mass Inserts

    TheOriginalJman wrote:
    > I've tried the transfer server to server, but becasue of firewalls and other
    > concerns, I must use a queries only, and must allow CF to control the data
    > flow. The subquery Idea is interesting. I'm not sure of how to do that
    you should still use the CVS dump or whatever to get the data over to
    the 2nd server, it will be quicker to manipulate it there. get the IDs
    of existing rows in the 2nd server's table to use in getting the data
    out of the 1st server. probably need to chunk this.
    > though. The two tables are in different datasources making it a little more
    shouldn't matter i think. does mysql support naming like
    database.owner.table? can each server see the other?
    > The DB does support ignoring dupes, however, CF seems to through an error when
    > they occur, When I was using the raw dumps for transfering I had no problem
    stick the code in a cftry block & ignore the duplicate errors.
    > for these ideas. If you could give me an idea of using the subueries idea that
    > would welcomed indeed, especially if this can be done without using a <cfloop>
    > to loop through the query.
    can mysql do insert/selects? does it know EXISTS?
    INSERT secondTable (columnsList...)
    SELECT columnsList...
    FROM firstTable
    WHERE someID NOT IN (SELECT someID FROM secondTable WHERE...)

    or something like that.
    PaulH *TMM* Guest

  5. #4

    Default Re: Fastest Method for Mass Inserts

    how woulc i code a select i sert where queryresult needs to be inserted into a table in a different datasource. it's the second datasource that trips me
    TheOriginalJman Guest

  6. #5

    Default Re: Fastest Method for Mass Inserts

    TheOriginalJman wrote:
    > how woulc i code a select i sert where queryresult needs to be
    > inserted into a table in a different datasource. it's the second
    > datasource that trips me
    " does mysql support naming like database.owner.table? can each server
    see the other? " and if the servers can communicate w/each other...does
    mysql have anything like linked servers? does mysql have replication?
    otherwise it's back to the CSV dump, query the 2nd server for existing
    IDs, then use that info (valueList function) to filter the first table's
    resultset to rows not in the 2nd table.

    sorry i can't be more specific, i don't know mysql that well.

    PaulH *TMM* Guest

  7. #6

    Default Re: Fastest Method for Mass Inserts

    as far as I know you can't specify datasource.tablein CF7 and the two MySQL
    Servers could possibly see each other, and ther e is a replication feature in
    MySQL, however the replications is master slave replication, and each slave
    (which is where the data is being inserted into) can have only one master in my
    situation I have many masters all needing to hav their data pulled and putinto
    a single database. each server is scattered around the world, and each is
    behid a firewall and I only have port 3306 available to me. I have looked at
    utilities that would do the replication, but it casues major headaches in the
    CF website app if CF doesn't maintain control of updates and such.

    For these and many other reasns I am left with the option of pulling the data
    one source at a time and then inserting it into the local datasource. I was
    just hoping that there is a faster method of inserting the data into CF 7 then
    using a <CFLOOP> to loop through all the records and insert them one at a time.

    I see the benifits of

    <cfquery name ="remote" datasource="remote"> select * from table1</cfquery>
    <cfquery name ="local" datasource="local"> select * from table1</cfquery>
    <cfquery name = "notexisting" dbtype="query"> select * from remote where
    remote.keyfield not in (select keyfield from local)
    <cfrloop> .... loop through notexisiting and insert records ... </cfloop>


    any better ideas????

    TheOriginalJman Guest

  8. #7

    Default Re: Fastest Method for Mass Inserts

    TheOriginalJman wrote:
    > as far as I know you can't specify datasource.tablein CF7 and the two MySQL
    missed the point, can you do it in mysql?
    > utilities that would do the replication, but it casues major headaches in the
    > CF website app if CF doesn't maintain control of updates and such.
    i don't see how that can be. the db maintains the data, not cf.
    > I see the benifits of
    i don't. it will be slower than using native db functionality. sorry i
    don't know mysql well enough to be specific but somebody does. perhaps
    you can put this question to a mysql support list?
    > any better ideas????
    <cfquery name="existingData" datasource="local">
    SELECT keyField
    FROM table1
    </cfquery>

    <cfquery name="remote" datasource="remote">
    SELECT *
    FROM table1
    WHERE keyField NOT IN (#valueList(existingData.keyField)#)
    </cfquery>


    PaulH *TMM* Guest

  9. #8

    Default Re: Fastest Method for Mass Inserts

    One option would be to query the remote db and dump the result set into a CSV
    Then use LOAD DATA INFILE on the db you want to import to
    [url]http://dev.mysql.com/doc/refman/5.0/en/load-data.html[/url]

    Ken
    The ScareCrow Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139