README.md in embulk-input-mysql-0.9.2 vs README.md in embulk-input-mysql-0.9.3
- old
+ new
@@ -15,10 +15,11 @@
- **user**: database login user name (string, required)
- **password**: database login password (string, default: "")
- **database**: destination database name (string, required)
- If you write SQL directly,
- **query**: SQL to run (string)
+ - **use_raw_query_with_incremental**: If true, you can write optimized query using prepared statement by yourself. See [Use incremental loading with raw query](#use-incremental-loading-with-raw-query) for more detail (boolean, default: false)
- If **query** is not set,
- **table**: destination table name (string, required)
- **select**: expression of select (e.g. `id, created_at`) (string, default: "*")
- **where**: WHERE condition to filter the rows (string, default: no-condition)
- **order_by**: expression of ORDER BY to sort rows (e.g. `created_at DESC, id ASC`) (string, default: not sorted)
@@ -89,9 +90,42 @@
## Trouble shooting
- If you get an exception 'The server time zone value XXX is unrecognized ...', please set proper time zone to the MySQL server or set `true` to the `use_legacy_datetime_code` property.
+
+### Use incremental loading with raw query
+
+**IMPORTANT**: This is an advanced feature and assume you have an enough knowledge about incremental loading using Embulk and this plugin
+
+Normally, you can't write your own query for incremental loading.
+`use_raw_query_with_incremental` option allow you to write raw query for incremental loading. It might be well optimized and faster than SQL statement which is automatically generated by plugin.
+
+Prepared statement starts with `:` is available instead of fixed value.
+`last_record` value is necessary when you use this option.
+Please use prepared statement that is well distinguishable in SQL statement. Using too simple prepared statement like `:a` might cause SQL parse failure.
+
+In the following example, prepared statement `:foo_id` will be replaced with value "1" which is specified in `last_record`.
+
+```yaml
+in:
+ type: mysql
+ query:
+ SELECT
+ foo.id as foo_id, bar.name
+ FROM
+ foo LEFT JOIN bar ON foo.id = bar.id
+ WHERE
+ foo.hoge IS NOT NULL
+ AND foo.id > :foo_id
+ ORDER BY
+ foo.id ASC
+ use_raw_query_with_incremental: true
+ incremental_columns:
+ - foo_id
+ incremental: true
+ last_record: [1]
+```
## Example
```yaml
in: