1 grid.insert

Release 2017.3

Tag available since version 2017.3.

Inserts the rows obtained from a query executed on the work database on nodes of the grid. The selected node where the row is inserted is assigned using the hash algorithm based on the value for the provided key column.

    <select /> !
The sample is based on a temporary table with a set of rows to be selected on the work directory. The insert on grid is obtained from this temporary table and the node is assigned using the hash algorithm based on the value for the provided key column.
To execute this sample it is requisite to create the following table on databases of grid.
create table t_person(
    person_id     char(10),
    person_name   char(10),
    person_gender char(10)
        <table name='@tmpdata' temp='y'>
            <column name='person_id'     type='char' size='10' />
            <column name='person_name'   type='char' size='10' />
            <column name='person_gender' type='char' size='10' />
        <vtable name='v1'>
            <column name='person_id'      type='char' />
            <column name='person_name'    type='char' />
            <column name='person_gender'  type='char' />
        <vtable.insert name='v1'>
            { "A987-QWE", "POL",     "MALE"   }
            { "B123-POI", "MARY",    "FEMALE" }
            { "C456-DJU", "JAN",     "MALE"   }
            { "D912-KIE", "LIAM",    "MALE"   }
            { "E984-XCF", "NOAH",    "FEMALE" }
            { "F498-NUE", "OLIVIA",  "FEMALE" }
            { "G357-HUI", "WILLIAM", "MALE"   }
            { "H756-MNB", "MIA",     "FEMALE" }
            { "I293-CAT", "JAMES",   "MALE"   }
        <vtable.insertIntoTable table='@tmpdata'><v1/></vtable.insertIntoTable>
        <grid.insert name='grid_demo' table='t_person' keyColumn='person_id'>
                <from table='@tmpdata' />
        <drop table='@tmpdata' temp='y' onexception='ignore' />

        <set name='rs'>
            <select.grid name='grid_demo' timeout='30'>
                <from table='t_person' />
|person_id|person_name|person_gender|grid_node     |grid_error|
|char     |char       |char         |char          |char      |
|visible  |visible    |visible      |visible       |visible   |
|D912-KIE |LIAM       |MALE         |demo_sports   |          |
|C456-DJU |JAN        |MALE         |demo_industria|          |
|E984-XCF |NOAH       |FEMALE       |demo_industria|          |
|H756-MNB |MIA        |FEMALE       |demo_industria|          |
|I293-CAT |JAMES      |MALE         |demo_industria|          |
|A987-QWE |POL        |MALE         |demo_cons     |          |
|B123-POI |MARY       |FEMALE       |demo_cons     |          |
|F498-NUE |OLIVIA     |FEMALE       |demo_cons     |          |
|G357-HUI |WILLIAM    |MALE         |demo_cons     |          |

2 Why use insert on grid?

The main advantage of using an insert on a grid is that the node assignment is transparent to the programmer. The assigned node is calculated by an algorithm based on the given key value. The algorithm is responsible for determining the node and the data load is distributed in several databases. This type of programming serves to increase the scalability of the system and improve the management of a big set of data on a multiple databases.