Thursday, November 24, 2011

MongoDB Indexes

To make the query fast we use indexes. Without indexes mongodb query optimizer need to check all the documents in order to sort and order the results.

Simplest form of creating an index.
> db.family.find();

{ "_id" : ObjectId("4ec0d4bc5c77613167cdf743"), "name" : "kasun" }
{ "_id" : ObjectId("4ec0d4bf5c77613167cdf744"), "name" : "kushan" }
 

> db.family.ensureIndex({name : 1});
> db.family.getIndexes();
[
        {
                "name" : "_id_",
                "ns" : "kasun.family",
                "key" : {
                        "_id" : 1
                },
                "v" : 0
        },
        {
                "_id" : ObjectId("4ec0db7f5c77613167cdf745"),
                "ns" : "kasun.family",
                "key" : {
                        "name" : 1
                },
                "name" : "name_1",
                "v" : 0
        }
]

ensureIndex()
Function create index based on the parameter pass within. It only create the index if it is not exists.

When we create index (standard) it block the other database operations. So the best way would be create the index with “background : true”. This will make sure the database is responsive even when you creating an index. When the collection data is very large this function is useful.
“name : 1” means the index is ascending order. You can give -1 also which is in descending order.
Even creating compound index is possible. You can use the ensureIndex() except it has multiple keys rather single key. And it is very important to choose either 1 or -1 for index in compound index (for single key it doesn’t matter). It will use this in sorts or range queries.

db.family.ensureIndex({name : 1, age: -1});
When you have multiple keys you can use it for beginning subset of a field.

_id index
Every collection has this type of index. It will automatically create during collection creation and can’t be deleted.

Anyway capped collections deviate from this behavior.
Dotted indexes

You can index a key inside embedded document. Also known as “Dot Notation”. Same time you can index a document as well.
db.places.insert( { name: "home", address: { city: "bandarawela", prov: "Uva", district: "badulla" } } );

db.places.ensureIndex( { address : 1 } );
// below queries can use the above index

db.places.find( { "address" : { "city" : "bandarawela", "prov" : "Uva", "district" : "badulla" } } );
// below one match, as { city: "bandarawela" } < { city: "bandarawela", prov: "Uva" }
db.places.find( { address: { $gte : { city: "bandarawela" } } } );

// below query does not match the document cause the order of fields is significant
db.factories.find( { address: { district: "badulla" ,prov : "Uva", city: "bandarawela" } } );

Sparse Index
The documents with indexed field, Documents which doesn’t have the sparse index will not be including into the index. These indexes are not complete. Behave differently on sorts and filtering because some documents not are including to the indexes.

Unique Index
A duplicate index field for this type of document is not allowed.

db.family.ensureIndex({name: 1}, {unique: true});
dropdups - This is fabulous feature in a way. Only limitation is it only keep the 1st document except others will be drop out.

This is feature you can use for existing collection when you want to create new index where there will be duplicates, and except for first document others will be drop.

More Index

Commonly used commands

To drop all the indexes can use the below method.
db.collection.dropIndexes();

To drop single key.
db.collection.dropIndexes({name :1});

To recreate index.
db.collection.reIndex();

Monday, June 27, 2011

Love

What is really Love? Parents to kids, or to your brother/sister, Love at first sight, to your husband/wife and the cycle goes on. What is really mean by Love? It’s a feeling or responsibility or both. Where it is this resides? Is it real need of your life? Can you live without Love?

It’s a very famous topic specially when you’re a teenager. But do we really understand it at that age? Or do we understand at it all?

For a civilized person living without love is almost impossible. We cannot define the Love by few sentences, but you can feel it when you’re in Love.

But Love is general form that used to describe a close connection with another party. When your kid or wife is around it’s your total responsibility and care that you provided for them. But when your brother is around it’s more like friendship. Your mother cares you more than you care for her.

Love at first sight, hmmm….. Is means physical attraction? So far you’re not in touch with her. So how come you Love a stranger. You don’t know her feelings. Any species has one goal when you see the world for the first time. It’s your duty to make sure the existence of your species. That’s why when you’re mature enough you will have your family. Whatever ceremonies, rituals you follow the prime idea behind getting married is having kids. Someone can argue that “I don’t want to have kids, but I will get married one day”. The point is as species you are a failure. It’s in our genes. No requirement or guidelines it is built in to the system.

Think how you cross your dog. Dog doesn’t need guidelines, isn’t it?

So what is homo-sexuality? Definitely you can’t have offspring. So why doesn’t it vanished during evolution.

Certain animals team up to protect them self from intruders, specially their offspring. So bond between team members need to be very high. Mutual understanding needs to be very high. This may be a reason.

And any bullet proof system has its own holes. ;)

May be its another way how it control the population.

Back to the topic- So these ceremonies, rituals, and modern life style is also a part of the biological human evolution. No right!!! But when you think what the real outcome of these is? Then you realize you’re still a player of the entire game. We think we created these, but rather those came to us. By doing that we pass our genes to next generation. So the Love also has its own variations. And is Love a part of the evolution?
Once you have kids then your parents love your kid more than you. They are much happier when your kid is around more than anything. Legally you cannot leave your kid whenever you want, but you can leave out your parents at any time. Why is that? Kid is your responsibility but still you “Love” him/her. So still we are playing the game of nature which make sure your kid grown up and have their own kids’ one day.
Do you know any animal that protect their parents? But mum protects her kid all the time. But humans care about their parents. We took a different path for our survival which any other species wasn’t able to do it so far. So we can accept the different. But for some reason we didn’t built that as a policy. Its heavily push up by religions.
Still we care more than anything when it’s come to our son/daughter. Simple reason may be whatever you are; biologically still specie that has top priority on survival.
So next question why you Love other animals? Cause they compete with each us. Remember you evolve in a way that no animal will able to challenge you anymore. So you’re superior. So nature tricks you to love other species so they survive.

So is the Love between different parties still part of the human evolution? Or it just happened to be? Are we super heroes of this movie?
Or is that nature tricks you. So you think you are superman, Thats ok. But remember you still playing their game.

Friday, June 17, 2011

Folder share with Virtual Box

My requirement is share my Windows7 folder with Fedora-13 on virtual Box. Steps were quite straightforward except wasn’t able to find details in document. Steps were followed after went through few searches.

Initially I shared one folder from virtual Box main view. But wasn’t able to mount using file system vboxsf/vboxfs.

sudo mount -t vboxsf share-vm /home/kasun/window-share/
mount:unknown filesystem type ‘vboxsf’

Open a console window. Just a terminal
sudo yum install system-config-display

sudo system-config-display
sudo yum install gcc kernel kernel-devel kernel-headers

Restart the VM to boot with the newest kernel. Go to the Devices menu and select install Guest additions

Tick the CD/DVD DevicesVBoxguestAdditions.iso. Now you will see the ISO in your home folder.

cd /media/VBOXADDITIONS_3.2.6_63112

VBoxLinuxAdditions-x86.run
sudo mount -t vboxsf share-vm /home/kasun/window-share/

Copy some files to your share-vm folder and check from your VB. So you are installed guest addition to VB. This will also enable you to use “Seamless Mode”, “Full screen” with my Windows7.


Fedora-14

yum -y update kernel
yum -y install kernel-devel kernel-headers dkms gcc gcc-c++

Restart the virtual machine after the updates.
Now, go to Devices and select Install Guest Additions from menu as shown below.

Once ISO file mounted, open the terminal and go inside CD ROM (Under /media)

Run following command as root.

sh VBoxLinuxAdditions-x86.run

Successful installation will return following OK results.
Restart again.

Here we go- It is done. Now it’s enabling with seamless mode, increasing screen and folder sharing.
Installing in Ubuntu 11.4 and virtual-box 4.0.8
Well, this is the easiest.
Go to Devices Installs Guest Additions


Then run the VBoxLinuxAdditions.run inside mounted ISO
./VBoxLinuxAdditions.run

Then restart. You are done. Share you folders now.
sudo mount -t vboxsf share-xp share-ubuntu

Tuesday, June 14, 2011

MySQL special data types – BLOB

BLOB is data type which hold large binary object. MySQL has TINYBLOB, BLOB, MEDIUM BLOB, and LARGEBLOB. These were based on the size of the data that it can hold.
And BLOB is referring to as binary strings or byte strings. On the other hand TEXT treated as character strings. BLOB doesn’t have a character set. Comparisons, Sorting will do on the numeric values of the bytes in the column. Using SQL strict mode value will be truncated to match with maximum column length.
Except few things you can treat BLOB as VARBINARY. For indexes you need to specify prefix length and there is no DEFAULT value for BLOB.

-----------------------------------------------------------------------
mysql> CREATE TABLE test (blob_col BLOB, INDEX(blob_col(10)));
Query OK, 0 rows affected (0.19 sec)
mysql> desc test;
+----------+------+------+-----+---------+-------+
| Field    | Type | Null | Key | Default | Extra |
+----------+------+------+-----+---------+-------+
| blob_col | blob | YES  | MUL | NULL    |       |
+----------+------+------+-----+---------+-------+
1 row in set (0.05 sec)

mysql> CREATE TABLE test2 (blob_col BLOB, INDEX(blob_col));
ERROR 1170 (42000): BLOB/TEXT column 'blob_col' used in key specification without a key length
-----------------------------------------------------------------------
Note – prefix can be up to 1000 bytes long. On innodb it is 767 bytes. Importantly prefix length were calculated in bytes but in CREATE TABLE statements it is use no of characters.
-----------------------------------------------------------------------
mysql> CREATE TABLE test2 (blob_col BLOB, INDEX(blob_col(10000)));
Query OK, 0 rows affected, 1 warning (0.08 sec)

mysql> desc test2;
+----------+------+------+-----+---------+-------+
| Field    | Type | Null | Key | Default | Extra |
+----------+------+------+-----+---------+-------+
| blob_col | blob | YES  | MUL | NULL    |       |
+----------+------+------+-----+---------+-------+
1 row in set (0.00 sec)
-----------------------------------------------------------------------
Below is example of BLOB field usagein java.
Write to Database – insert “fileName” to the MySQL database.
            connection.setAutoCommit(false);
            //I have disable the auto commit
            File file = new File(fileName);
            fis = new FileInputStream(file);
            preparedStatement = connection.prepareStatement(INSERT_PICTURE);
            preparedStatement.setBinaryStream(1, fis, (int) file.length());
            preparedStatement.executeUpdate();
            System.out.println("INSERT Query executed");
            connection.commit();
-----------------------------------------------------------------------
Read from the Database
            Statement stmt = connection.createStatement();
            ResultSet rs = stmt.executeQuery(selectQuery);
            System.out.println("SELET Query executed");
            System.out.println("Going to write the files to the disk");
            System.out.println("---------------------------------");
            while (rs.next()) {
                String fileName = "fileNameOut.jpg";
                File image = new File(fileName);
                fos = new FileOutputStream(image);

                byte[] buffer = new byte[1];
                is = rs.getBinaryStream(1);
                while (is.read(buffer) > 0) {
                    fos.write(buffer);
                }
                System.out.println("File " + fileName + " written to the disk");
-----------------------------------------------------------------------
Table definition is,
CREATE TABLE `picture` (
                  `picture_blob` longblob,
                  `id` int(11) NOT NULL auto_increment,
                  PRIMARY KEY  (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=latin1
-----------------------------------------------------------------------
It’s better to have good understand about max_allowed_packet parameter when working with BLOB columns. If the client program encounter “Packet too large” or “Lost connection to MySQL server during query” better check this property. And may result in strange response specially when deal with bigger BLOB columns. Keep in mind that BLOB was larger than 100MB, and then MySQL need 3 times the size of memory allocated for BLOB processing.
mysql> show variables like "max_allowed_packet";
+--------------------+---------+
| Variable_name      | Value   |
+--------------------+---------+
| max_allowed_packet | 1048576 |
+--------------------+---------+
TINYBLOB – 255bytes
BLOB – 65535bytes
MEDIUMBLOB – 16777215bytes
LONGBLOB – 4GB

Sunday, May 15, 2011

Smile a bit

Simple, elegant smile is what we expect everyday from everybody. It’s not that difficult neither complex to give a good smile. Smile can be results of simple foolish joke to a rocket science story. Sometimes you smile because you happy or maybe you want to pretend that you are happy. Even being happy has different meanings.

When you are really happy you smile, sometimes you even don’t know that you’re smiling. When you are part of an audience you need to smile when others smile. Cause I don’t want to destroy my reputation. Sometimes I just want to runaway then I do smile ;)

Whatever intention smile is always good. It always makes someone happy. Except you blow up eyes of the receiving end.

During my life time I saw so many advertisements, sayings, and stories and even by experience smile is so simple important.

But it’s going to be different from this moment onwards. I am writing this on top of small desk in hospital. We had several hard days with my 2 months baby. She is infected with germ that causes fever and limp node enlargement just below right ear. We have spent lot of time just to get a Simple Single Smile. We feed her. Medicate her. But she just refused to smile. Only positive idea came to my mind was maybe she smile when she is feel terrible.

I have planned everything before I came down to Sri Lanka from Singapore. But germ causes my vacation to be in a hospital. Fortunately my mum and dad work in health department. So we get served very well. Otherwise you know what would be the outcome. But she is still not fully recovered. Even I had asked for extension of my annual leaves.

Well now I have so many issues. I am running out of annual leaves, money, and my customer chasing me for the last 10 days. But I didn’t reply to him yet. I didn’t check my emails for last 10 days. But the biggest issue is getting that Simple Single Smile. Just 30 minutes ago she gave the smile may be because of dedicated medication. Whatever the reason is its feel so good when she smiles.

Now I know how much difficult to get a Simple Single Smile. And the Smile that will definitely change my life

22-04-2011

Monday, May 9, 2011

File Compression

Why you need to compress file, simple and single requirement is reduce file size. Save disk space.
When to compress, No need to be genius simply every day we compress files. It will reduce bandwidth usage during file transfer. And importantly it will save space on backup storage devices on production systems. So that makes backup stay for long period of time, before it overwrites by recent backup files.
Which method to use, simply on windows I use Winrar or Winzip. In Linux it is Tar or Gunzip. It is something to think about?
Well, I thought it is not be serious problem.
Then sometime back I compare the different methods.
Server I used is 6GB Ram with 4 Dual-Core AMD Opteron processors running rhel4.7.

Bzip2

Compressed file is a text file.
Average CPU usage is 90-99% during compression. But sometimes CPU usage exceed 100% also
Memory usage is around 1%
Original text file size 1135782806
Bunzip2 file size 30722634
Size reduction 1105060172(bytes). Reduction percentage 97.29%
Time elapsed - 528 sec

Gzip

It’s the same text file.
Average CPU usage is less than 1%.
Memory usage is very low. Less than 1%
Original text file size 1135782806
Gzip file size 51512452.
Size reduction is 1084270354. As a percentage 95.46%
Time elapsed 23 seconds.

Tar.gz

This is what I commonly used for archive and compress. So I want to know how efficient it is.
Average CPU usage is less than 1%.
Memory usage is very low. Less than 1%
Original text file size 1135782806
File size reduction 1135782806 --> 51512524. Ratio is 95.46%
Time taken is 23 seconds.

Zip

CPU usage is 90-100%. Memory usage is very low. Around 0.1%
File reduction was 1135782806 --> 51512601. Ratio is 95.46
Time taken was 27 seconds

Compression type you need is really depending with the requirement. If you have separate backup server, only have few script to run and if you don’t mind the CPU usage during file compression bzip2 is your choice. It will reduce file size to minimum. But remember it will eat up your CPU. Also need much more time.

For me gzip full fill my requirements. Compression ratio is less than bzip2 but not harm on CPU usage. So I can use it with production servers. And I do have lot of scripts on my crontab so the time need for compression is also important for me. Tar.gz also which I was currently using do the same. So basically I don’t need to change my backup scripts.

But whenever I need to do a file transfer I will prefer bzip, cause it is reduce the file size significantly when you compare with gzip.


So end of the day it always gonna be you to decide.

Tuesday, April 5, 2011

InnoDB

InnoDb is the leading transactional storage engine for MySQL, which is deliver high performance transaction processing with row level locking and multi version concurrency control (consistent non-locking reads). InnoDB ensures data integrity and reliability. It provides referential integrity support and automatic data recovery. InnoDB is integrating with MySQL and replication stored procedures and triggers.
Execute “SHOW ENGINES” on MySQL command line for identifying the supported storage engines. In windows it’s the default engine for MySQL. In a single SQL statement you can query the InnoDB table with other type of tables.
mysql> SHOW ENGINES;
| InnoDB     | DEFAULT | Supports transactions, row-level locking, and foreign keys     |

Row-level locking
Innodb facilitate row-level locking. Several users are allowed to lock every row in Innodb table, or any random subset or rows.

Transactions
Each connection to MySQL starts with new session. If auto-commit is enable each SQL statement start with new transaction automatically. And after execute the SQL it commit the transaction automatically. In MySQL by default Innodb auto-commit is enable. Simply once the SQL execute successfully results visible to all sessions.

Now if we disable auto-commit,
SET autocommit = 0
It’s always keeping the transaction open. Only ‘COMMIT’ ’ROLLBACK’ will end current transaction and start new. So the changes won’t visible to other session until we commit or roll-back the transaction.



mysql> set autocommit=0;
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT * FROM test;
+----+-----------+------------+
| id | last_name | first_name |
+----+-----------+------------+
|  1 | Ekanayake | Kasun      |
|  2 | Ekanayake | Arunodha     |
+----+-----------+------------+
2 rows in set (0.00 sec)
mysql> INSERT INTO  test (id,last_name,first_name) VALUES(3,'Ekanayake','Nehansa
');
Query OK, 1 row affected (0.00 sec)

mysql> SELECT * FROM test;
+----+-----------+------------+
| id | last_name | first_name |
+----+-----------+------------+
|  1 | Ekanayake | Kasun      |
|  2 | Ekanayake | Arunodha     |
|  3 | Ekanayake | Nehansa    |
+----+-----------+------------+
3 rows in set (0.00 sec)

Now if we use different session, below are the results.
mysql> select * from test;
+----+-----------+------------+
| id | last_name | first_name |
+----+-----------+------------+
|  1 | Ekanayake | Kasun      |
|  2 | Ekanayake | Arunodha     |
+----+-----------+------------+
2 rows in set (0.00 sec)

Only the changes will be permanent once the ‘COMMIT’ or ‘ROLLBACK’ executes on the transaction.

Configurations
Here I will not go through entire configuration list. But I have found below parameters are quite useful. Knowledge on these will definitely benefit you. These will definitely benefit you as a database administrator or system administrator.

innodb_data_file_path = ibdata1:10M:autoextend
Binary file name “ibdata1” size of 10MB (K-KB, G-GB also applicable) will be created inside you data directory (that because you have not mentioned the path) with auto extending.

innodb_data_home_dir = /mnt/data
innodb_data_file_path=ibdata1:50M;ibdata2:50M:autoextend
Here the files will create inside /mnt/data

innodb_data_file_path=ibdata1:10M;ibdata2:10M:autoextend
Two files will create inside your data directory.

innodb_data_file_path=ibdata1:10M:autoextend:max:500M
One file and the file max size is as 500MB.
innodb_buffer_pool_size = 4096M
Set this to 80% of Ram on dedicated database server. But do not set it too high, because competition for the physical memory may result in paging in the OS.

innodb_additional_mem_pool_size = 64M
Use for store data dictionary and other structure internal data structures. 1MB is default and you may need to increase depend on no of tables you create. You will see warning messages on MySQL error log when it acquire additional memory from OS.

innodb_log_file_size = 1024M
Larger value will make sure less data flush on check point activities. But bigger the log file recovery takes some time.

Auto-extend
MySQL will increase the data file size if it is running out of free space in table-space. Unless you change it, increase will happened with 8MB at a time.
mysql> show variables like 'innodb_auto%';
+-----------------------------+-------+
| Variable_name               | Value |
+-----------------------------+-------+
| innodb_autoextend_increment | 8     |
+-----------------------------+-------+
Size is in Mega Bytes. Parameter will not take into consideration in case the per-table table-space files created.

ib_logfile0 and mysql-bin.000001
First question that came to my mind was why two type log files. Then I snoop around and with some help from Google.
ib_logfile is the Innodb log file. It has fixed size as per the configuration (my.cnf).
1073741824 Mar 25 00:21 ib_logfile1
1073741824 Mar 25 17:31 ib_logfile0

innodb_log_file_size = 1024M
Configuration for InnoDB log files size.

This log file will be use in kind of MySQL start after and a crash (like server power outage). Imagine you are running a UPDATE query on big table (means most of the rows will update :)) and half on the way server was down. Next time you start the MySQL it will use Innodb log files so it knows which have been updated and up to what extent.
Then I had issue after couple of months the data directory getting filled up (client always tend to use df –h, So they misreading the data usages) with logs. Then I have to write small script to clean out mysql-bin.[] files. These files are MySQL binary logs (or bin logs). These have binary representation of the command to be executed.
Another type of logs is relay logs used in MySQL replication. Below configuration will help limiting the relay log file size in slave.
relay-log-space-limit=20G


Force-Recovery
This parameter helped me in numerous occasions. Specially when your prestige database crash due to abnormal server shutdown. So your backup won’t let you 100% recovery.
innodb_force_recovery = 1-6

Most important thing here is this won’t recover your database for full functionality. It’s make sure (anyway you still need to be lucky) you can back-up the most important data before you start all over from the scratch. So you can start MySQL with Innodb recovery mode and backup the data which was not in my database backup.
Default value is zero (0). You can start recovery mode starting from 1. Each needs MySQL server restart. Then connect to MySQL and try the backups. 1-Run the MySQL server even with corrupted tables
2-if the crash occurred during purge operation this will help you. No background MySQL main thread is running.
3-No transaction rollback after recovery
4-No insert-buffer merge operations, if it is causing the crash it will not do it

Value of 4 or less identify as safe and only lost of some data and will results in few individual corrupted pages.
5-Even incomplete transactions taken as committed. No process of undo logs
6-No log roll-forward with connection recovery

InnoDB use clustered index. It means the actual data is in the leaves of the PK index. And this is why it take consuming lot of memory. Unlike key_buffer in MyISAM which only take index into memory innodb_buffer_pool load all data into memory. Which will enahnce performance overall.

Friday, March 18, 2011

MySQL Index


So without index MySQL start searching from first row and then to the entire table to find relevant rows. So bigger the table higher the cost. If indexes were introduced for the seeking columns query can locate the relevant rows without going through the entire table. If table as 1000 records so this is at least 100 times fast (as per the MySQL Doc). If you need to access much of the data then reading the entire table sequentially is won’t be big problem. Because it minimize the data seeks. If “WHERE” clause has more than on indexed columns it uses the index which gives the smallest number of rows.

If you use JOIN in your query it will use index on different tables. Here having same type of index columns coming in handy. If comparison cannot be done without conversion on dissimilar data types MySQL will prevent use of index. So having similar types on different columns on different table will definitely increase the performance when comes to JOIN. VARCHAR and CHAR is taken as same type if the size also same.

All MySQL data types can be use as indexes. But maximum number of indexes per table and maximum index length depend on the storage engine. Most storage engines have higher values but at least 16 indexes per table and a total index length of at least 256 bytes supported.

CREATE TABLE emp (emp_id INT, INDEX(emp_id));

You can create an index using first N characters also.

CREATE TABLE employee (e_b_col BLOB, INDEX(e_b_col (10)));

You can use up to 1000 bytes of prefixes (prefix is calculated by bytes). FULL-TEXT indexing only possible with MyISAM which will use for full text searches. And data types CHAR, VARCHAR and TEXT can be used.
Spatial data type indexing can be done except NDBCLUSTER and ARCHIVE, which use RTREE. MEMORY storage engine uses HASH as default but BTREE also supports.
If the query uses only columns that are numeric and left most prefix of key, then result can be obtain from index tree with higher speed.

Index Merge optimization

MySQL do several range scans and merge their results into one. It’s only applied to single table not multiple tables across.

      CREATE TABLE `t2` (`id` INT NOT NULL, `age` INT NOT NULL, `marks` INT NOT NULL,
KEY `age` (`age`),
KEY `marks` (`marks`));

mysql> explain select * from t2  where age=1 or marks=1 \G
*************************** 1. row ***************************
           id: 1
  select_type: SIMPLE
        table: t2
         type: index_merge
possible_keys: age,marks
          key: age,marks
      key_len: 4,4
          ref: NULL
         rows: 2
        Extra: Using union(age,marks); Using where
1 row in set (0.00 sec)

In ‘type’ column you can see it is using index_merge.

mysql> explain select * from t2 ignore index (age,marks) where age=1 or marks=1
\G
*************************** 1. row ***************************
           id: 1
  select_type: SIMPLE
        table: t2
         type: ALL
possible_keys: NULL
          key: NULL
      key_len: NULL
          ref: NULL
         rows: 1347
        Extra: Using where
Use “EXPLAIN” is a good way to proceed with the query optimization

Indexes are something extra that you can enable on your MySQL table to increase performance, but they do have some downsides. Upon creating a new index MySQL builds a separate clock of information that needs to be updated every time there are changes made to the table. This means that if you are constantly executed UPDATE, INSERT and DELETE queries in your table this could have negative impact on performance.

So when introducing index you need to be careful with,
The SELECT queries you going to execute.
What would be your WHERE clause.
How often the table gets updated with data.