1

What is the use of index in table creation in magento2

->addIndex($installer->getIdxName('blog_comment', ['parent_id']), ['parent_id'])

Thanks

6

You can create your column as index key for better performance and speedy retrieval of data from a table.

An index is a performance optimization feature that enables data to be accessed faster compare to other nonindex columns. An index is used to more quickly find rows in the table based on the values which are part of the index and they don’t define the uniqueness of a column.

You can add your column as Index key using Magento 2 by below way using InstallSchema or UpgradeSchema.php file,

->addIndex(
    $installer->getIdxName('table_name', ['table_field']),
    ['table_field']
)

Here table_name is your table name of database and table_field is your field which you want to create index key. You can check blog for Add foreign key to table, Add Foreign key to table using Magento 2

  • Thanks. Its work for me.... – Anas Mansuri Oct 23 at 12:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.