Skip to content

Commit

Permalink
feat(mariadb): support indexHints on mariadb dialect (#11573)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamin658 authored and sushantdhiman committed Oct 18, 2019
1 parent 2949a63 commit a34399f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/dialects/mariadb/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ MariadbDialect.prototype.supports = _.merge(
check: false
},
indexViaAlter: true,
indexHints: true,
NUMERIC: true,
GEOMETRY: true,
JSON: true,
Expand Down
48 changes: 48 additions & 0 deletions test/unit/dialects/mariadb/query-generator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const chai = require('chai'),
dialect = Support.getTestDialect(),
_ = require('lodash'),
Op = require('../../../../lib/operators'),
IndexHints = require('../../../../lib/index-hints'),
QueryGenerator = require('../../../../lib/dialects/mariadb/query-generator');

if (dialect === 'mariadb') {
Expand Down Expand Up @@ -764,6 +765,53 @@ if (dialect === 'mariadb') {
arguments: ['User', 'email'],
expectation: "SELECT CONSTRAINT_NAME as constraint_name,CONSTRAINT_NAME as constraintName,CONSTRAINT_SCHEMA as constraintSchema,CONSTRAINT_SCHEMA as constraintCatalog,TABLE_NAME as tableName,TABLE_SCHEMA as tableSchema,TABLE_SCHEMA as tableCatalog,COLUMN_NAME as columnName,REFERENCED_TABLE_SCHEMA as referencedTableSchema,REFERENCED_TABLE_SCHEMA as referencedTableCatalog,REFERENCED_TABLE_NAME as referencedTableName,REFERENCED_COLUMN_NAME as referencedColumnName FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE (REFERENCED_TABLE_NAME = 'User' AND REFERENCED_COLUMN_NAME = 'email') OR (TABLE_NAME = 'User' AND COLUMN_NAME = 'email' AND REFERENCED_TABLE_NAME IS NOT NULL)"
}
],

selectFromTableFragment: [
{
arguments: [{}, null, ['*'], '`Project`'],
expectation: 'SELECT * FROM `Project`'
}, {
arguments: [
{ indexHints: [{ type: IndexHints.USE, values: ['index_project_on_name'] }] },
null,
['*'],
'`Project`'
],
expectation: 'SELECT * FROM `Project` USE INDEX (`index_project_on_name`)'
}, {
arguments: [
{ indexHints: [{ type: IndexHints.FORCE, values: ['index_project_on_name'] }] },
null,
['*'],
'`Project`'
],
expectation: 'SELECT * FROM `Project` FORCE INDEX (`index_project_on_name`)'
}, {
arguments: [
{ indexHints: [{ type: IndexHints.IGNORE, values: ['index_project_on_name'] }] },
null,
['*'],
'`Project`'
],
expectation: 'SELECT * FROM `Project` IGNORE INDEX (`index_project_on_name`)'
}, {
arguments: [
{ indexHints: [{ type: IndexHints.USE, values: ['index_project_on_name', 'index_project_on_name_and_foo'] }] },
null,
['*'],
'`Project`'
],
expectation: 'SELECT * FROM `Project` USE INDEX (`index_project_on_name`,`index_project_on_name_and_foo`)'
}, {
arguments: [
{ indexHints: [{ type: 'FOO', values: ['index_project_on_name'] }] },
null,
['*'],
'`Project`'
],
expectation: 'SELECT * FROM `Project`'
}
]
};

Expand Down

0 comments on commit a34399f

Please sign in to comment.