Synchronize data using Insert method

    The INSERT statement is used in a similar way to the INSERT statement used in databases such as MySQL. The INSERT statement supports the following two syntaxes:

    Here we only introduce the second way. For a detailed description of the INSERT command, see the INSERT command documentation.

    Single write means that the user directly executes an INSERT command. An example is as follows:

    For Doris, an INSERT command is a complete import transaction.

    Therefore, whether it is importing one piece of data or multiple pieces of data, we do not recommend using this method for data import in the production environment. The INSERT operation of high-frequency words will result in a large number of small files in the storage layer, which will seriously affect the system performance.

    This method is only used for simple offline tests or low-frequency operations.

    We recommend that the number of inserts in a batch be as large as possible, such as thousands or even 10,000 at a time. Or you can use PreparedStatement to perform batch inserts through the following procedure.

    JDBC example

    Here we give a simple JDBC batch INSERT code example:

    Please note the following:

    1. The JDBC connection string needs to add the parameter and use the method.

      Currently, Doris does not support PrepareStatemnt on the server side, so the JDBC Driver will perform batch Prepare on the client side.

      will ensure that the Driver executes batches. And finally form an INSERT statement of the following form and send it to Doris:

    2. Import atomicity

      Like other import methods, the INSERT operation itself supports atomicity. Each INSERT operation is an import transaction, which guarantees atomic writing of all data in an INSERT.

      As mentioned earlier, we recommend that when using INSERT to import data, use the “batch” method to import, rather than a single insert.

      At the same time, we can set a Label for each INSERT operation. Through the , the idempotency and atomicity of operations can be guaranteed, and the data will not be lost or heavy in the end. For the specific usage of Label in INSERT, you can refer to the INSERT document.