-
In how many different ways can the letters of the word 'LEADING' be arranged in such a way that the vowels always come together?
-
How many words can be formed by using letters of the word ‘DELHI’?
-
From a group of 7 men and 6 women, five persons are to be selected to form a committee so that at least 3 men are there on the committee. In how many ways can it be done?
-
In how many different ways can the letters of the word 'CORPORATION' be arranged so that the vowels always come together?
-
Find the number of ways the letters of the word ‘RUBBER can be arranged?
-
Find in how many different ways, the letters of the word ‘LEADING’ can be arranged in such way that the vowels always come together?
-
Out of 5 consonants and 4 vowels, how many words of 3 consonants and 2 vowels can be formed?
-
A bag contains 2 white marbles, 3 black marbles and 4 red marbles. Find in how many ways, 3 marbles can be drawn, so that at least one black marble is included in each draw?
-
In how many ways can the letters of the word 'LEADER' be arranged?
-
Out of 7 consonants and 4 vowels, how many words of 3 consonants and 2 vowels can be formed?
-
In a group of 6 boys and 4 girls, four children are to be selected. In how many different ways can they be selected such that at least one boy should be there?
-
How many combinations are possible while selecting four letters from the word ‘SMOKEJACK’ with the condition that ‘J’ must appear in it?
-
There are 30 people in a group. If all shake hands with one another , how many handshakes are possible?
-
On a railway line there are 20 stops. A ticket is needed to travel between any 2 stops. How many different tickets would the government need to prepare to cater to all possibilities?
-
Mayur travels from Mumbai to Jammu in 7 different ways. But he is allowed to return to Mumbai by any way except the one he used earlier. In how many ways can he complete his journey?
-
If Suraj doesn’t want three vowels together, then in how many, can he arrange letters of the word 'MARKER'?
-
There are 35 people in a group. There are 12 school girls, 10 school boys, 5 senior citizens and 8 babies in the group. The organizer of the group wants to select a school girl or a school boy as leader of the group. In how many ways can he do so?
-
There are 30 people in a party. If everyone is to shake hands with one another, how many hand shakes are possible?
-
A box contains 2 white, 3 black and 5 red balls. In how many ways can three balls be drawn from the box if at least one black ball is to be included in the draw?
-
A person can go from place “P” to “Q” by 7 different modes of transport, but is allowed to return back to “P” by any mode other than the one used earlier. In how many different ways can he complete the entire journey?
-
In how many different ways can the letters of the word ‘GEOMETRY’ be arranged so that the vowels always come together?
-
In how many ways can the letters of the word INDIA be arranged, such that all vowels are never together?
-
In Cricket League, in first round every team plays a match with every other team. 9 teams participated in the Cricket league. How many matches were played in the first round?
-
In Daya’s bag there are 3 books of History, 4 books of Science and 2 books of Maths. In how many ways can Daya arrange the books so that all the books of same subject are together?
-
A trekking group is to be formed having 6 members. They are to be selected from 3 girls, 4 boys and 5 teachers. In how many ways can the group be formed so that there are 3 teachers and 3 boys or 2 girls and 4 teachers?
-
In a class, there are 15 students. During a Christmas party all of them shook hands with each other only once. How many handshakes took place in the class?
-
A box contains 4 black, 3 red and 6 green marbles. 2 marbles are drawn from the box at random. What is the probability that both the marbles are of the same color?
-
How many words can be formed by using all letters of word ALIVE.
-
In how many ways can the letters of the word ENCYCLOPAEDIA be arranged such that vowels only occupy the even positions?
-
A locker in bank has 3 digit lock. Mahesh forgot his password and was trying all possible combinations. He took 6 seconds for each try. The problem was that each digit can be from 0 to 9. How much time will be needed to by Mahesh to try all the combinations?
-
A bank has 6 digit account number with no repetition of digits within a account number. The first and last digit of the account numbers is fixed to be 4 and 7. How many such account numbers are possible?
-
4 members form a group out of total 8 members.
(i) In how many ways it is possible to make the group if two particular members must be included.
(ii) In how many ways it is possible to make the group if two particular members must not be included?
-
A briefcase has a number-lock system containing a combination of 3 digits (Each digit can be of numbers 0 to 8). If the correct combination is unknown, how much maximum time would be required to open the bag if each “trial” of combination takes 3 seconds?
-
In a group containing 6 cows and 4 buffalos, 4 livestock are to be selected in such a way that at least 1 cow should always be present. How many way of doing that are possible?
-
In a room there are 2 green chairs, 3 yellow chairs and 4 blue chairs. In how many ways can Raj choose 3 chairs so that at least one yellow chair is included?
-
There are 8 routes from London to Delhi. And there are 6 routes from Delhi to Tokyo. In how many different ways can Raj travel from London to Tokyo via Delhi?
-
How many 3-letter words can be formed out of the letters of the word ‘CORPORATION’, if repetition of letters is not allowed?
-
In how many ways can we arrange the word ‘FUZZTONE’ so that all the vowels come together?
-
On a shelf, 2 books of Geology, 2 books of Sociology and 5 of Economics are to be arranged in such a way that the books of any subject are to be together. Find in how many ways can this be done?
-
Without repetition, using digits 2, 3, 4, 5, 6, 8 and 0, how many numbers can be made which lie between 500 and 1000?
Permutation and Combination problems, Example and Formula
MySQL Explain Query and Execution Plan Example
EXPLAIN in MySql is one of the strongest feature tool through which we can analyze and optimize the Query and we can rewrite in a cost efficient and resource Optimized way which can execute faster.
Basically EXPLAIN will give you the information about the Query Execution Plan which is used. Means it will give the information about the way through which Database execute Query. It can be used in front of SELECT, INSERT, UPDATE, DELETE and REPLACE. It is a feature tool through which we can find the Quick remedy for Slow Query.
If your MySql EXPLAIN Query is not working or not Parsing correctly then you can type SHOW WARNINGS into your editor and run it.
Basically EXPLAIN will give you the information about the Query Execution Plan which is used. Means it will give the information about the way through which Database execute Query. It can be used in front of SELECT, INSERT, UPDATE, DELETE and REPLACE. It is a feature tool through which we can find the Quick remedy for Slow Query.
If your MySql EXPLAIN Query is not working or not Parsing correctly then you can type SHOW WARNINGS into your editor and run it.
Use EXPLAIN to Improve Query Performance
Prameter |
Purpose |
id |
SQL Query id |
select_type |
Type of SQL Statement |
table |
Referenced Table |
type |
Type of Join (It defined how the table will be accessed or joined) |
possible_keys |
Possible
key which can be used in the Query |
key | Key which is used in the Query |
key_len |
Used Key length in
the Query |
ref | Columns
which got compared to indexes |
rows | Numbe
of rows scanned during query execution |
Extra | Additional
Information about Query |
Consider the below Query (We have studentDetails Table which have millions of record in it ) :
EXPLAIN SELECT * FROM `studentDetails`
id | 1 |
select_type | SIMPLE |
table | studentDetails |
type | ALL |
possible_keys | (NULL) |
key | (NULL) |
key_len | (NULL) |
ref | (NULL) |
rows | 40846 |
Extra |
Above will be the output of the Query which we tried Executing using EXPLAIN. Usually EXPLAIN will give you lot of information regarding your query like which key are used, Indexing is used or not, how many rows are getting scanned while executing query, what are all the possible keys we can use in query etc.. We will study the above in detail below.
select_type ( Type of SQL Statement ) : Possible value which can come based on the Query is below
- SIMPLE
- PRIMARY, DERIVED
- SUBQUERY
- DEPENDENT SUBQUERY
- UNCACHEABLE SUBQUERY
- UNION
- DEPENDENT UNION
- UNION RESULT
Most important point to look in the EXPLAIN Query output is type and rows. Row gives you the information about how many rows are scanned before the query output. Type define how the table will be access or joined. We will see EXPLAIN Query type in detail below.
- system : The table contain one or Zero rows.
- const : It is fastest type of join. It will have only one matching rows which will be indexed. It is fastest because table is scanned once and the column is treated as constant while joining other table.
- eq_ref : In this Index (Primary or Unique NOT NULL) will be used by the join and it is the best table join type. One rows will read from the table and compared with rows from the previous table.
- ref
- fulltext : This join will use FULLTEXT index for processing the query.
- ref_or_null
- index_merge
- unique_subquery
- range : Only rows belong to some particular or specified range get scanned for the query output. DB indexing is used to select or find the matching rows.
- index : In this all Index Tree will be scanned to find the exact matched query condition.
- all : Entire Table row and its combination will be scanned to find the matched query condition output.
EXPLAIN SELECT * FROM users WHERE id >60000 AND id < 60002
Prameter | Value |
id | 1 |
select_type | SIMPLE |
table | users |
type | range |
possible_keys | id,registered_user,id_attyp |
key | id |
key_len | 4 |
ref | (NULL) |
rows | 1 |
Extra | Using where |
MySql Query Optimization Techniques and Performance Tuning
Query Optimization and technique is a feature of RDBMS(Relational Database Management System). The main purpose of Query Optimization is to reduce the usage of CPU resource and execute the Query faster for the User access.
As we know single query can be written in multiple ways, So Optimization technique use the best way which consume lesser system resource and provide faster data access to the users. Query Optimization Make Application response faster and enhance the performance. Now we will go through the query optimization technique step by step.
Above query is there as a example for your reference. What column is needed we must pull that particular column.
Once you create MySql Indexes it will consume space and also slow down the speed of INSERT, UPDATE and DELETE Query Command.
Example : Consider you have a Table named with studentDetail which contain laks of record and indexed on primary key column Named with ID. If we try to access the record using id the query execution will be faster because it will scan minimal row to get the exact data.
We will use EXPLAIN on the query and try to know some information about the query.
If we will refer the above image which is the output of EXPLAIN query. In that there is column named with rows which is explaining how many rows are scanned before giving the query output.
Using EXPLAIN query we can get the information about the query and row scanned once the query execution happened.
In the above query each time outer Query will be executed the sub-query will also run row-by-row. which is bad practice of writing queries. We can write the above query in efficient way which is below for your reference.
Avoid so many column in the Table
It's not a good practice of Having large number of column ( >100 ) in single table which start impacting the query performance and consume the system resource at the time of Query Execution. If you need more column in that case you must break the table based on the logic. Normalization Database Design Technique comes in picture which enhance the system performance.Avoid Using Select *
Using Select * pulls all the column even if it is not not required which consume the resource. Imagine you have a table which consist more then 100 column and laks or millions of record ( rows ). Querying all the record (Column) using Select * even if all the column is not required is wastage of system resource. If you use actual column what is required for the application instead of all column then your Query execution become faster.SELECT * FROM `studetnInfo` (This will pull all the column of the studetnInfo Table)
SELECT firstName, lastName, dob, emailId FROM `studetnInfo`
Above query is there as a example for your reference. What column is needed we must pull that particular column.
Indexing a Column
We must use DB indexing on the column which is used in SQL Clause such as where, order by and group by etc. Once Indexing is done it will help you in faster data retrieval and also help us in sorting the data.Once you create MySql Indexes it will consume space and also slow down the speed of INSERT, UPDATE and DELETE Query Command.
Example : Consider you have a Table named with studentDetail which contain laks of record and indexed on primary key column Named with ID. If we try to access the record using id the query execution will be faster because it will scan minimal row to get the exact data.
SELECT * FROM `studentDetail` WHERE id= 33333
We will use EXPLAIN on the query and try to know some information about the query.
EXPLAIN SELECT * FROM `student_details` WHERE id= 33333
If we will refer the above image which is the output of EXPLAIN query. In that there is column named with rows which is explaining how many rows are scanned before giving the query output.
Using EXPLAIN query we can get the information about the query and row scanned once the query execution happened.
Avoid Using Correlated Sub-queries
Basically correlated Sub-queries depend on the outer query or parent query. Sub-query runs for each row-by-row return by the parent or Outer query which slow down the process and decrease the database efficiency.SELECT Name, dob, (SELECT SchoolName FROM School WHERE ID = Student.schoolid) AS SchoolName FROM Student
In the above query each time outer Query will be executed the sub-query will also run row-by-row. which is bad practice of writing queries. We can write the above query in efficient way which is below for your reference.
SELECT st.name, st.dob, sc.SchoolName FROM Student st JOIN School sc ON sc.ID = st.schoolid
Avoid NULL Values in Column
We must avoid NULL Value in our database column because it harm the execution of the query and give unexpected result.Avoid Storing HTML, XML, JSON or other Mark Up Language
Storing HTML, XML, JSON and other Mark Up Language in database will cost us, these Data is presentation data which must be handled by our Application. We must store data and rest of the presentation data must be handled by Application. Database is there for Data Operation( Fetching, Inserting, Deleting, Updating ) not for rendering the web page or generating the document.Use EXPLAIN to analyze your Query
Whenever query is executed the mysql optimizer uses Execution plan. EXPLAIN will give you all the information of execution plan. You can use this EXPLAIN in the beginning of the query. Example is below for your reference.EXPLAIN SELECT * FROM `student_details` ORDER BY student_name DESC LIMIT 10
id | 1 |
select_type | SIMPLE |
table | student_details |
type | all |
possible_keys | (NULL) |
key | (NULL) |
key_len | (NULL) |
ref | (NULL) |
rows | 40716 |
Extra | Using filesort |
Subscribe to:
Posts (Atom)
Our Feature Post
There is a tree between houses of A and B If the tree leans on As House
There is a tree between houses of A and B. If the tree There is a tree between houses of A and B. If the tree leans on A’s House, the t...

Our Popular Post
-
👉 Reema can complete a piece of work in 12 days while Seema can the same work in 18 days. If they both work together, then how many da...
-
Probability Question and Solutions Two dice are thrown simultaneously. What is the probability of getting two numbers whose product...
-
The average of 11 numbers is 30. If the | Solutions The average of 11 numbers is 30 . If the average of first six numbers is...
-
Karan, Hari and Kowshik play cricket. The runs got by Karan to Hari and Hari to Kowshik are in the ratio of 5:3. They get altogether 588 ...
-
Analogies Questions :: Logical Reasoning 👉 Analogies shortcut tricks, Formula, Method and Notes 👉 Analogies Questions and a...