SlideShare a Scribd company logo
International Journal of Database Management Systems ( IJDMS ) Vol.5, No.5, October 2013

THE OPTIMIZATION OF RUNNING QUERIES IN
RELATIONAL DATABASES USING ANT-COLONY
ALGORITHM
Adel Alinezhad Kolaei and Marzieh Ahmadzadeh
Department of Computer Engineering & IT Shiraz University of Technology

ABSTRACT
The issue of optimizing queries is a cost-sensitive process and with respect to the number of associated
tables in a query, its number of permutations grows exponentially. On one hand, in comparison with other
operators in relational database, join operator is the most difficult and complicated one in terms of
optimization for reducing its runtime. Accordingly, various algorithms have so far been proposed to solve
this problem. On the other hand, the success of any database management system (DBMS) means
exploiting the query model. In the current paper, the heuristic ant algorithm has been proposed to solve this
problem and improve the runtime of join operation. Experiments and observed results reveal the efficiency
of this algorithm compared to its similar algorithms.

KEYWORDS
Database, Join Operation Optimization , Traveling Salesperson, Ants Algorithm.

1. INTRODUCTION
Optimization of database queries such as relational database queries is one of the most important
research issues. If queries are in interactional mode, they will contain a few relations such that
optimization of these queries can be done using a comprehensive search. However, if the number
of relations is more than 5 or 6, techniques for comprehensive search will be costly in terms of
computer memory and time. Optimization of queries is an activity in which an efficient strategy
for performing the query is produced hence it is a fundamental step in query processing. In this
stage, DBMS selects the best strategy among some given executive strategies so that running the
given query using this strategy by user has minimum cost. The input in this system is a query
such as q to DBMS by user. Suppose that S is the set of all possible strategies to answer query q.
Each element of the set S such as s has cost C(s) (in terms of CPU usage, input and output,
memory consumption, etc.). The purpose of an optimization algorithm to find an element s0 in S
such that [1,2]:
C(s0) = min C(si) si ε S
DOI : 10.5121/ijdms.2013.5501

1
International Journal of Database Management Systems ( IJDMS ) Vol.5, No.5, October 2013

In order to respond to query q, a strategy applies a sequence of algebraic operators on database
relations so that it ultimately finds the answer of q. The overall cost of a strategy is the sum of
processing cost of each operator. In comparison to existing relational operators, processing and
optimizing join operator which is denoted by ∞ is one of the most complicated tasks. Basically,
the join operator uses two relations as input and combines tuples of each relation correspondingly
and returns a new relation as the output. Since join operator has commutative and associative
properties, the number of existing running strategies to answer a query grows exponentially as the
number of joins between relations increases; however, all of the existing running strategies to
answer to a specified query have not the same output (such as R3=R1 ∞ (R2 ∞ R3) ∞ (R1 ∞ R2)),
the resultant running strategy has a different cost, since the cardinality of alternative relations are
not the same. So, selecting an appropriate ordering for running join operator is influential to the
overall cost. Since, optimization of a query which consists of join operator is more timeconsuming than other relational operators such as selection or projection operator, all of the query
optimization techniques are applied to queries involved in join operator. Some algorithms which
can be used to solve this problem are as follow:
Iterative Improvement, Genetic Algorithm, Particle Swarm Optimization, Simulated Annealing,
Hybrid Evolutionary Algorithm, etc. It can be understood that hyper-heuristic algorithms have
been resulted in appropriate solutions to this problem. Accordingly, in the present paper, we have
used hyper-heuristic ant algorithm to solve this problem.
The contents of this paper have been organized as follows:
In sections 2 and 3, Traveling sales person problem and a brief history of ant Algorithm is
respectively mentioned. In section 4, the proposed Algorithm is illustrated. In sections 5 and 6,
implementation environment and results of experiments are explained, respectively. In section 7,
the paper is concluded.

2. TRAVELING SALES PERSON PROBLEM
Traveling Sales Person problem is a classic and famous problem in the field of operation
research. Many problems in science can be formulated in the form of this problem and then
solved. This problem consists of n cities where there will be a path between each two cities.
Every such path between two cities has a cost function which equals to the distance between these
cities. Traveling sales person wants to start his travel from one of the cities and then visits all of
the cities just once and finally returns to the first city where he started his travel. The solution for
this problem is a sequence of cities where the sales person has visited once and the main constrain
is that the total cost (distance) be minimized [7].

3. ANT ALGORITHM
In 1991, Dorigo and Clarini used hybrid-heuristic ant Algorithms to solve separable problems [8].
This Algorithm has such properties as simple adaptability for applying in many problems. Ant
Algorithms are multi-agent systems whose behavior is derived from real ants and each agent is an
artificial ant. These Algorithms are successful samples of swarm intelligence systems and are
applicable to a range of problems from Traveling Sales Person problem to routing in remote
communication networks. In addition, they can be used in hybrid optimization problems such as
quadratic allocation and scheduling task problems in a set of given tasks.
2
International Journal of Database Management Systems ( IJDMS ) Vol.5, No.5, October 2013

Figure 1. The way of moving ants to find food resources and shedding pheromone

Figure (1) shows the way that ants adopt to find food resources. When ants move they remain a
chemical substance called pheromone. As it is shown in figure (1), at time t=0 the number of ants
in two different paths are the same but at time t=1 their numbers in these paths are different and in
shorter path the number of ants is more. This is the case because during their movement, ants
release pheromone and as time passes, it is evaporated. Therefore, the shorter the length of the
path, the less the pheromone is evaporated and the more the remaining pheromone will be, so ants
will select this shorter path through next stages.
The experiment on ants shows that despite the existence of two paths with different length from
nest to food, after a while (about a few minutes), most of ants select shorter path and this ratio
increases as the difference between paths increases. In order to find food, ants release pheromone
while moving from nest to other place and vice versa. When they reach a point which is the
intersection point of shorter and longer path, they adopt a probabilistic selection based on the
amount of pheromone smelled. Such behavior has an autocatalytic effect because when a path is
selected, it is more probable that in future the same path will be selected too. Therefore, by
repeating this procedure, the released pheromone in the shorter path will be saved in higher rate
so that the shorter path is more and more selected. This simple idea is applicable to find
appropriate solutions in complicated optimization problems [8, 9, 10, 11].
In Traveling Sales Person problem, there are a set of n cities in which we should find the shortest
closed path consisting of these cities. If dij denotes the length of path between cities i and j in
symmetric Traveling Sales Person problem, to find the shortest path among these cities we will
use some artificial ants (agents) which have the following properties:
Ants will randomly be placed on nodes.
Each ant selects the next city in a probabilistic approach. The probability of selecting next city is
a function of distance to other cities the associated value in the sequence of cities on the related
nodes.

3
International Journal of Database Management Systems ( IJDMS ) Vol.5, No.5, October 2013

Each ant has to move to allowable paths i.e. it should move to cities that was not visited in the
past. This condition is controlled using prohibited list.
When a path is formed, pheromone is placed on its nodes and the ant releases some pheromone
while crossing the cities. Ant in the time interval (t, t+1) performs one move, so, in each iteration
of Algorithm, m move will occur.
In the time interval (t, t+1), some pheromone evaporates. When each ant has created its own path,
pheromone will again be specified to them [8, 9, 10, 11].
In 1996, Dorigo and Jembardla, made some modifications to ant Algorithm [9] and proposed AntColony Algorithm. This proposed Algorithm was different from previous Algorithm in terms of
following characteristics:

•
•
•

The changing position rule which directly controls the effect of new nodes and old
ones on the Algorithm.
The overall updating rule that updating had been used only on nodes which
belonged to ants’ paths.
When the ants form a solution, the local updating rule will be applied.

4. OUR PROPOSED APPROACH
Considering the proposed illustrations, it can be stated that if we can formulate optimization
problems in well-known problems for which some Algorithms have been proposed, we can solve
them through the above-mentioned methods. Therefore, the main task is how to convert these
problems in to famous solved problems. As it was mentioned above, one of the famous problems
is Traveling Sales Person problem for which different Algorithms have been proposed to solve it.
Such Algorithms are Genetic Algorithm, Particle Swarm Optimization, Ant Algorithm, hybrid
Algorithm, etc.
We decide to solve optimizing join operation problem in relational database firstly by converting
it to TSP problem and then solve it using Hyper-Heuristic Ant Algorithm. It should be mentioned
that the main problem in this paper is not the same to original TSP problem because in the
original TSP problem, sales person returns to first city, however, in the proposed problem, this is
not the case. So, firstly formulas and the way that this problem should be solved using ant
Algorithm has been stated and then important parameters and how converting this problem will
be stated.
Ant-Colony Algorithm which we considered in this paper is exactly the one proposed by Dorigo
[9]. In this Algorithm, in the first phase, initially m ants with memory are created. These ants will
randomly be placed on n nodes. On each node, there is some initial pheromone. In the second
phase, to obtain initial solutions, the following steps are run in parallel.
To select city s in its next move, the ant which is placed on node r, uses relation (1) known as
position changing rule in Ant-Colony Algorithm. In relation (1), q is a random number in [0, 1]
interval and the value of q0 is between 0 and 1.

4
International Journal of Database Management Systems ( IJDMS ) Vol.5, No.5, October 2013


β
.
 arg max u∈J k ( r ) [τ ( r , u )][η (r , u )]
s=
S


{

}

if q ≤ q 0
otherwise

(1)

Where τ(r, s) represents the amount of pheromone on arc (r,s), η(r, s) is the reciprocal distance
δ(r,s), JK(r) is the remaining set of cities for k-th ant placed on city r,β is the importance
determining parameter in the relation between pheromone and distance. However, in relation (1),
s is a random variable that follows from the probability distribution mentioned as relation (2).

 [τ (r , s )][η (r , s )]β
.

[τ (r , u)][η (r , u )]β
.

s =  u∈∑r )
Jk (

0


if s ∈ J k (r )
otherwise

(2)

Where Pk(r,s) is the probability that k-th ant after selecting city r will select city s. After that ants
create their own paths, they return to their first city. In this step, local updating will be done and
the amount of pheromone changes by relation (3).

τ ( r , s ) ← (1 − ρ ).τ ( r , s ) + ρ .∆τ ( r , s )

(3)

Where ρ is pheromone evaporating parameter and ∆τ(r,s) is obtained using relation (4):


−1
( L gb )
∆τ ( r , s ) = 
0


if ( r , s ) ∈ global _ best _ tour
otherwise

(4)

where Lgb is the length of the best path which has already been found in the current iteration [9].
To solve the join problem of tables using Ant-Colony Algorithm, it suffices that we consider
every table as a city (n cities) and that sales person doesn’t return to first city and also we should
consider η(r, u) equal to reciprocal of the cost of two tables r and u and Lgb as minimum cost of
the join of all tables in each iteration of Algorithm (parameter β can also be considered as an
important parameter in distributed database). Therefore, in beginning of Algorithm, each ant is
randomly placed on a city, then for move, join of this city with other cities (tables) should be
verified if joining of these cities is possible as mentioned in the definition of problem-that is there
exists a path between them- and after these steps, the table with minimum cost (least time for join
operation) will be considered as a next city (table).
To achieve this purpose, in each step, the cost of joining two tables as a cost of path between
these two cities is added up with the cost of previous joins (equals total cost up to current step). In
each run of Algorithm, with respect to local updating, the amount of pheromone changes until the
best path is specified, so this path can be used in the next step and finally the best path (the join
with minimum cost) can be selected.

5
International Journal of Database Management Systems ( IJDMS ) Vol.5, No.5, October 2013

5. IMPLEMENTATION ENVIRONMENT
We have used databases with the number of tables equal to 8, 12, 16, 20, 24, 28 and 32 in which
the number of records in each table has been produced as a random number with uniform
distribution. The parameters and system specification and implementation environment are as
follows:
We have used a system with Intel Core 2duo and 2.26GHZ cpu, 3GB RAM memory XP
operating system. The language that program has been written with is C# and also we have used
SQL SERVER database. In addition, we ran the program 20 times and in each run we have used
30 iterations, in other words, Iteration Number=30 and Run Number=20. The mean number of
records which are used from each table in experiments is given in table1:
Table1 : The mean number of records in each table in experiments
Number of tables
8
12
16
20
24
28
32

Average number of records per table
383
418
362
397
403
354
429

6. EXPERIMENTAL RESULTS
For our proposed approach, the number of ants is considered as the number of vertices and then
the program has been executed. The number of iteration s for each experiment was 20 and the
mean number of times through which iterations have been done is given in figure2.

Figure 2. Execution time tests

6
International Journal of Database Management Systems ( IJDMS ) Vol.5, No.5, October 2013

As it can be seen from figure 2, the proposed approach has resulted in a good performance in
comparison to other approaches. This is the case because other approaches verify almost all
existing ways of running a query while in the proposed approach , in each experiment if ants find
a better solution (to join tables), they will inform the existence of this solution with respect to the
updating strategy to other ants in order that they use this solution to find optimal solutions.
Therefore, all existed solutions for running a query (join of multiple tables) will have not been
verified and cpu time is saved. In other words, in our approach, ants operate in parallel.
It should be noted that in the proposed approach, we have set the number of ants equal to the
number of tables w and in the next time, we set it as half the number of tables and finally we have
shown that for the second case, cpu time has decreased. On the other hand, the more the number
of ants is, the less the decrease in the probability of the precision of the obtained result (as the
experiment shows). Therefore, if we use more powerful processors, the runtime of Algorithm will
decrease. In other words, if we use multi-processor system, runtime will decrease to an acceptable
level and this is the case because ants Algorithm operates parallel and also the ants work in
parallel with each other and updating is performed when each step is finished.

7. CONCLUSION
In this paper, we stated a new approach for optimizing execution of queries in relational databases
using Ant Colony algorithm. For this, we initially maped the connection between tables into a
TSP model ,in which each table was considered as a city and each table link as a relation
between two cities. Then the problem was solved by Ant Colony algorithm. Several such
experiment was conducted for a number of different tables for which the numbers of records in
each table were chosen randomly with uniform distribution. Experiments and given results proved
the better performance of this approach rather than others that were given in the literature. The
main reason for the efficiency of this method is its parallel property. This happened since our
approach did not investigate all the existing ineffective and useless solutions for query execution,
while, in the majority of other approaches the most existing solutions need to be evaluated. . As a
consequence, we achieved a better execution time.

REFERENCES
[1]

[2]

[3]

[4]
[5]
[6]

F. Mahmoudi, M. Zahedi Anaraki, A.H. Zahedi Anaraki, Optimization of executing queries in
relational databases with particle swarm algorithm, 16th National CSI Computer Conference,
2011.[Paper published in Persian]
S. Parsa, H. Izadkhah, A. Hossein zadeh, Combination of hill climbing algorithm in parallel machine
for optimization of large queries in question graph, 3rd IKT Conference, 2007. [Paper published in
Persian]
J. L. Sushil and Z. Yongmian . An Empirical Comparison of Randomized Algorithms for Large Join
Query Optimization. Proceedings of the Eleventh International Florida Artificial Intelligence
Research Society Conference, pp. 95-100, 1998.
K. Bennet, M. C. Ferris and Y. E. Ioannidis. A Genetic Algorithm for Database Query Optimization.
In Proc. of the Fourth Intl. Conf. on Genetic Algorithms, pp. 400-407, San Diego, USA, 1991.
Y. E. Ioannidis and E. Wong. Query Optimization by Simulated Annealing. In Proc. of the ACMSIGMOD Conf. on Management of Data, pp. 9-22 San Francisco, USA, May 1987.
K. Asghari, A. Safari Mamaghani, F. Mahmoudi, M. Meibodi, Optimization of executing queries in
relational databases with hybrid evolutionary algorithm. Computer and Robotics magazine. p.25-37.
2008. [Paper published in Persian]
7
International Journal of Database Management Systems ( IJDMS ) Vol.5, No.5, October 2013
[7]
[8]
[9]

[10]
[11]

M. Jünger, G. Reinelt and G. Rinaldi. The Traveling Salemsan Problem, in Handbooks in Operations
Research and Manageme nt Science, Vol. 7, pp. 225-330, 1995.
M. Dorigo and L. M. Gambardella. Ant Colony System: A Cooperative Learning Approach to the
Travelling Salesman Problem. IEEE Trans. Evol. Comp. 1, pp. 53-66, 1991.
M. Dorigo and L. M. Gambardella. A Study of Some Properties of Ant-Q. In Proceedings of PPSNIV, Fourth International Conference on Parallel Problem Solving From Nature, pp. 656-665, Berlin:
Springer-Verlag, 1996.
M.dorigo and G.Dicaro. AntAlgorithm for Discrete Optimization. universite Libre de Bruxelles
vol,5,No.3,pp.137-172,Dec.1999.
Z. C. S. S. Hlaing and M. A. Khine. Solving Traveling Salesman Problem by Using Improved Ant
Colony Optimization Algorithm. International Journal of Information and Education Technology,
Vol. 1, No. 5, December 2011.

AUTHORS
Adel Alinezhad Kolaei is a MS student of Computer Science at Shiraz University of
Technology. He received his BSc in Software Engineering from Iran University of
Science and Technology. His major research interests are high performance algorithms
and database management.

Marzieh Ahmadzadeh is an Assistant Professor of Computer Science at Shiraz University
of Technology. She received her PhD in Computer Science and MSc in Information
Technology from the University of Nottingham, UK and her BSc in Software Engineering
from Isfahan University, Iran. She teaches a variety of graduate and undergraduate courses
and her research interest includes Computer Science Education in general and Computer
Supported Learning, specifically Data Mining and Human Computer Interaction.

8

More Related Content

What's hot (19)

PDF
Improved Hybrid Behavior Ant Colony Algorithm to Solve the Vehicle Routing Pr...
International Journal of Engineering Inventions www.ijeijournal.com
 
PPTX
Firefly algorithm
supriya shilwant
 
PDF
08 2008 068_prvulovic_03
Barbara Onwutalobi
 
PDF
Robot Three Dimensional Space Path-planning Applying the Improved Ant Colony ...
Nooria Sukmaningtyas
 
PDF
Bat Algorithm is Better Than Intermittent Search Strategy
Xin-She Yang
 
PDF
Two-Stage Eagle Strategy with Differential Evolution
Xin-She Yang
 
PPT
Swarm intelligence algorithms
Aboul Ella Hassanien
 
PDF
Multi-objective Flower Algorithm for Optimization
Xin-She Yang
 
PPTX
Bat algorithm and applications
Md.Al-imran Roton
 
PDF
an improver particle optmizacion plan de negocios
Carlos Iza
 
PPTX
Firefly algorithm
Hasan Gök
 
PDF
A COMPARISON BETWEEN SWARM INTELLIGENCE ALGORITHMS FOR ROUTING PROBLEMS
ecij
 
PPT
Swarm intelligence pso and aco
satish561
 
PDF
Recent Advances in Flower Pollination Algorithm
Editor IJCATR
 
PDF
Improved Firefly Algorithm for Unconstrained Optimization Problems
Editor IJCATR
 
PDF
Flower Pollination Algorithm: A Novel Approach for Multiobjective Optimization
Xin-She Yang
 
PDF
A Hybrid Bat Algorithm
Xin-She Yang
 
PDF
Multiobjective Firefly Algorithm for Continuous Optimization
Xin-She Yang
 
PDF
Using Learning Automata in Coordination Among Heterogeneous Agents in a Compl...
Waqas Tariq
 
Improved Hybrid Behavior Ant Colony Algorithm to Solve the Vehicle Routing Pr...
International Journal of Engineering Inventions www.ijeijournal.com
 
Firefly algorithm
supriya shilwant
 
08 2008 068_prvulovic_03
Barbara Onwutalobi
 
Robot Three Dimensional Space Path-planning Applying the Improved Ant Colony ...
Nooria Sukmaningtyas
 
Bat Algorithm is Better Than Intermittent Search Strategy
Xin-She Yang
 
Two-Stage Eagle Strategy with Differential Evolution
Xin-She Yang
 
Swarm intelligence algorithms
Aboul Ella Hassanien
 
Multi-objective Flower Algorithm for Optimization
Xin-She Yang
 
Bat algorithm and applications
Md.Al-imran Roton
 
an improver particle optmizacion plan de negocios
Carlos Iza
 
Firefly algorithm
Hasan Gök
 
A COMPARISON BETWEEN SWARM INTELLIGENCE ALGORITHMS FOR ROUTING PROBLEMS
ecij
 
Swarm intelligence pso and aco
satish561
 
Recent Advances in Flower Pollination Algorithm
Editor IJCATR
 
Improved Firefly Algorithm for Unconstrained Optimization Problems
Editor IJCATR
 
Flower Pollination Algorithm: A Novel Approach for Multiobjective Optimization
Xin-She Yang
 
A Hybrid Bat Algorithm
Xin-She Yang
 
Multiobjective Firefly Algorithm for Continuous Optimization
Xin-She Yang
 
Using Learning Automata in Coordination Among Heterogeneous Agents in a Compl...
Waqas Tariq
 

Viewers also liked (20)

PDF
MGS-CEU-Functional-Assessment-Jones
Kristy Reed
 
PPT
British Accent Wednesdays
Geoffrey Rosenthal
 
PPT
แปลโดยพยัญชนะเรื่องพราหมณ์ชื่อว่าจูเฬกสาฎก ๘
วัดดอนทอง กาฬสินธุ์
 
PPTX
अस्द्फ्घ्ज्क्ल
kaviahuja
 
PDF
Proyect1
alejitaeri
 
DOCX
Bt132088
Adev Yabes
 
PDF
oconnorcampmainepamphlet1
April Liberty
 
PPTX
Our Teams (Spain) - Misioneras de la Providencia-Santa Teresa
Comenius Misioneras
 
DOCX
PRÁCTICO REALIZDO
Pablo Perez Rodriguez
 
PPTX
Application of two bicistronic systems involving 2A and IRES sequences to the...
Nacho Lara
 
PDF
Untitled Presentation
jadasandh
 
PPT
แปลโดยพยัญชนะเรื่องพราหมณ์ชื่อว่าจูเฬกสาฎก ๗
วัดดอนทอง กาฬสินธุ์
 
PPT
แปลโดยพยัญชนะเรื่องพราหมณ์ชื่อว่า จูเฬกสาฎก๒
วัดดอนทอง กาฬสินธุ์
 
DOCX
PRODUCTOS NATURALES Y TECNOLOGICOS
isabela arango restrepo
 
TXT
gdfgdfgdfgdfgdfgNuevo documento de texto
drrafaelgarcia23
 
PDF
Clinica Amedic Granada
cynicalbeast9228
 
PPTX
Patologia benigna de esofago
andrexcordoba
 
PPTX
Test 2
Sophia Decanteur
 
DOCX
Структура 2015/2016 навчального року
Alla Kolosai
 
PPTX
Narcissistic remmy giveaway!
Remmy Rem
 
MGS-CEU-Functional-Assessment-Jones
Kristy Reed
 
British Accent Wednesdays
Geoffrey Rosenthal
 
แปลโดยพยัญชนะเรื่องพราหมณ์ชื่อว่าจูเฬกสาฎก ๘
วัดดอนทอง กาฬสินธุ์
 
अस्द्फ्घ्ज्क्ल
kaviahuja
 
Proyect1
alejitaeri
 
Bt132088
Adev Yabes
 
oconnorcampmainepamphlet1
April Liberty
 
Our Teams (Spain) - Misioneras de la Providencia-Santa Teresa
Comenius Misioneras
 
PRÁCTICO REALIZDO
Pablo Perez Rodriguez
 
Application of two bicistronic systems involving 2A and IRES sequences to the...
Nacho Lara
 
Untitled Presentation
jadasandh
 
แปลโดยพยัญชนะเรื่องพราหมณ์ชื่อว่าจูเฬกสาฎก ๗
วัดดอนทอง กาฬสินธุ์
 
แปลโดยพยัญชนะเรื่องพราหมณ์ชื่อว่า จูเฬกสาฎก๒
วัดดอนทอง กาฬสินธุ์
 
PRODUCTOS NATURALES Y TECNOLOGICOS
isabela arango restrepo
 
gdfgdfgdfgdfgdfgNuevo documento de texto
drrafaelgarcia23
 
Clinica Amedic Granada
cynicalbeast9228
 
Patologia benigna de esofago
andrexcordoba
 
Структура 2015/2016 навчального року
Alla Kolosai
 
Narcissistic remmy giveaway!
Remmy Rem
 
Ad

Similar to The optimization of running queries in relational databases using ant colony algorithm (20)

PDF
Classification With Ant Colony
Gissely Souza
 
PDF
A new move towards updating pheromone trail in order to gain increased predic...
ijsrd.com
 
PDF
IJCSI-2015-12-2-10138 (1) (2)
Dr Muhannad Al-Hasan
 
PPT
53564379-Ant-Colony-Optimization.ppt
AhmedSalimJAlJawadi
 
PDF
Accelerating the ant colony optimization by
ijcsa
 
PPT
Ant Colony Optimization algorithms in ADSA
ALIZAIB KHAN
 
PDF
50120130405011
IAEME Publication
 
PPT
香港六合彩-六合彩
vfnvtd
 
PPTX
ant colony optimization.pptx
Grishma Sharma
 
PDF
Enhanced local search in artificial bee colony algorithm
Dr Sandeep Kumar Poonia
 
PPTX
Meetup Julio Algoritmos Genéticos
DataLab Community
 
PDF
An improved ant colony algorithm based on
IJCI JOURNAL
 
PPTX
Ant colony optimization
Joy Dutta
 
PDF
Enhanced abc algo for tsp
Dr Sandeep Kumar Poonia
 
PDF
Swarm Intelligence Technique ACO and Traveling Salesman Problem
IRJET Journal
 
PPTX
Bio-inspired computing Algorithms.pptx
pawansher2002
 
PDF
Software testing
DIPEN SAINI
 
PDF
AN OPTIMIZATION ALGORITHM BASED ON BACTERIA BEHAVIOR
ijaia
 
PDF
antcolonyoptimization-130619020831-phpapp01.pdf
nrusinhapadhi
 
PDF
A heuristic approach for optimizing travel planning using genetics algorithm
eSAT Journals
 
Classification With Ant Colony
Gissely Souza
 
A new move towards updating pheromone trail in order to gain increased predic...
ijsrd.com
 
IJCSI-2015-12-2-10138 (1) (2)
Dr Muhannad Al-Hasan
 
53564379-Ant-Colony-Optimization.ppt
AhmedSalimJAlJawadi
 
Accelerating the ant colony optimization by
ijcsa
 
Ant Colony Optimization algorithms in ADSA
ALIZAIB KHAN
 
50120130405011
IAEME Publication
 
香港六合彩-六合彩
vfnvtd
 
ant colony optimization.pptx
Grishma Sharma
 
Enhanced local search in artificial bee colony algorithm
Dr Sandeep Kumar Poonia
 
Meetup Julio Algoritmos Genéticos
DataLab Community
 
An improved ant colony algorithm based on
IJCI JOURNAL
 
Ant colony optimization
Joy Dutta
 
Enhanced abc algo for tsp
Dr Sandeep Kumar Poonia
 
Swarm Intelligence Technique ACO and Traveling Salesman Problem
IRJET Journal
 
Bio-inspired computing Algorithms.pptx
pawansher2002
 
Software testing
DIPEN SAINI
 
AN OPTIMIZATION ALGORITHM BASED ON BACTERIA BEHAVIOR
ijaia
 
antcolonyoptimization-130619020831-phpapp01.pdf
nrusinhapadhi
 
A heuristic approach for optimizing travel planning using genetics algorithm
eSAT Journals
 
Ad

Recently uploaded (20)

PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 

The optimization of running queries in relational databases using ant colony algorithm

  • 1. International Journal of Database Management Systems ( IJDMS ) Vol.5, No.5, October 2013 THE OPTIMIZATION OF RUNNING QUERIES IN RELATIONAL DATABASES USING ANT-COLONY ALGORITHM Adel Alinezhad Kolaei and Marzieh Ahmadzadeh Department of Computer Engineering & IT Shiraz University of Technology ABSTRACT The issue of optimizing queries is a cost-sensitive process and with respect to the number of associated tables in a query, its number of permutations grows exponentially. On one hand, in comparison with other operators in relational database, join operator is the most difficult and complicated one in terms of optimization for reducing its runtime. Accordingly, various algorithms have so far been proposed to solve this problem. On the other hand, the success of any database management system (DBMS) means exploiting the query model. In the current paper, the heuristic ant algorithm has been proposed to solve this problem and improve the runtime of join operation. Experiments and observed results reveal the efficiency of this algorithm compared to its similar algorithms. KEYWORDS Database, Join Operation Optimization , Traveling Salesperson, Ants Algorithm. 1. INTRODUCTION Optimization of database queries such as relational database queries is one of the most important research issues. If queries are in interactional mode, they will contain a few relations such that optimization of these queries can be done using a comprehensive search. However, if the number of relations is more than 5 or 6, techniques for comprehensive search will be costly in terms of computer memory and time. Optimization of queries is an activity in which an efficient strategy for performing the query is produced hence it is a fundamental step in query processing. In this stage, DBMS selects the best strategy among some given executive strategies so that running the given query using this strategy by user has minimum cost. The input in this system is a query such as q to DBMS by user. Suppose that S is the set of all possible strategies to answer query q. Each element of the set S such as s has cost C(s) (in terms of CPU usage, input and output, memory consumption, etc.). The purpose of an optimization algorithm to find an element s0 in S such that [1,2]: C(s0) = min C(si) si ε S DOI : 10.5121/ijdms.2013.5501 1
  • 2. International Journal of Database Management Systems ( IJDMS ) Vol.5, No.5, October 2013 In order to respond to query q, a strategy applies a sequence of algebraic operators on database relations so that it ultimately finds the answer of q. The overall cost of a strategy is the sum of processing cost of each operator. In comparison to existing relational operators, processing and optimizing join operator which is denoted by ∞ is one of the most complicated tasks. Basically, the join operator uses two relations as input and combines tuples of each relation correspondingly and returns a new relation as the output. Since join operator has commutative and associative properties, the number of existing running strategies to answer a query grows exponentially as the number of joins between relations increases; however, all of the existing running strategies to answer to a specified query have not the same output (such as R3=R1 ∞ (R2 ∞ R3) ∞ (R1 ∞ R2)), the resultant running strategy has a different cost, since the cardinality of alternative relations are not the same. So, selecting an appropriate ordering for running join operator is influential to the overall cost. Since, optimization of a query which consists of join operator is more timeconsuming than other relational operators such as selection or projection operator, all of the query optimization techniques are applied to queries involved in join operator. Some algorithms which can be used to solve this problem are as follow: Iterative Improvement, Genetic Algorithm, Particle Swarm Optimization, Simulated Annealing, Hybrid Evolutionary Algorithm, etc. It can be understood that hyper-heuristic algorithms have been resulted in appropriate solutions to this problem. Accordingly, in the present paper, we have used hyper-heuristic ant algorithm to solve this problem. The contents of this paper have been organized as follows: In sections 2 and 3, Traveling sales person problem and a brief history of ant Algorithm is respectively mentioned. In section 4, the proposed Algorithm is illustrated. In sections 5 and 6, implementation environment and results of experiments are explained, respectively. In section 7, the paper is concluded. 2. TRAVELING SALES PERSON PROBLEM Traveling Sales Person problem is a classic and famous problem in the field of operation research. Many problems in science can be formulated in the form of this problem and then solved. This problem consists of n cities where there will be a path between each two cities. Every such path between two cities has a cost function which equals to the distance between these cities. Traveling sales person wants to start his travel from one of the cities and then visits all of the cities just once and finally returns to the first city where he started his travel. The solution for this problem is a sequence of cities where the sales person has visited once and the main constrain is that the total cost (distance) be minimized [7]. 3. ANT ALGORITHM In 1991, Dorigo and Clarini used hybrid-heuristic ant Algorithms to solve separable problems [8]. This Algorithm has such properties as simple adaptability for applying in many problems. Ant Algorithms are multi-agent systems whose behavior is derived from real ants and each agent is an artificial ant. These Algorithms are successful samples of swarm intelligence systems and are applicable to a range of problems from Traveling Sales Person problem to routing in remote communication networks. In addition, they can be used in hybrid optimization problems such as quadratic allocation and scheduling task problems in a set of given tasks. 2
  • 3. International Journal of Database Management Systems ( IJDMS ) Vol.5, No.5, October 2013 Figure 1. The way of moving ants to find food resources and shedding pheromone Figure (1) shows the way that ants adopt to find food resources. When ants move they remain a chemical substance called pheromone. As it is shown in figure (1), at time t=0 the number of ants in two different paths are the same but at time t=1 their numbers in these paths are different and in shorter path the number of ants is more. This is the case because during their movement, ants release pheromone and as time passes, it is evaporated. Therefore, the shorter the length of the path, the less the pheromone is evaporated and the more the remaining pheromone will be, so ants will select this shorter path through next stages. The experiment on ants shows that despite the existence of two paths with different length from nest to food, after a while (about a few minutes), most of ants select shorter path and this ratio increases as the difference between paths increases. In order to find food, ants release pheromone while moving from nest to other place and vice versa. When they reach a point which is the intersection point of shorter and longer path, they adopt a probabilistic selection based on the amount of pheromone smelled. Such behavior has an autocatalytic effect because when a path is selected, it is more probable that in future the same path will be selected too. Therefore, by repeating this procedure, the released pheromone in the shorter path will be saved in higher rate so that the shorter path is more and more selected. This simple idea is applicable to find appropriate solutions in complicated optimization problems [8, 9, 10, 11]. In Traveling Sales Person problem, there are a set of n cities in which we should find the shortest closed path consisting of these cities. If dij denotes the length of path between cities i and j in symmetric Traveling Sales Person problem, to find the shortest path among these cities we will use some artificial ants (agents) which have the following properties: Ants will randomly be placed on nodes. Each ant selects the next city in a probabilistic approach. The probability of selecting next city is a function of distance to other cities the associated value in the sequence of cities on the related nodes. 3
  • 4. International Journal of Database Management Systems ( IJDMS ) Vol.5, No.5, October 2013 Each ant has to move to allowable paths i.e. it should move to cities that was not visited in the past. This condition is controlled using prohibited list. When a path is formed, pheromone is placed on its nodes and the ant releases some pheromone while crossing the cities. Ant in the time interval (t, t+1) performs one move, so, in each iteration of Algorithm, m move will occur. In the time interval (t, t+1), some pheromone evaporates. When each ant has created its own path, pheromone will again be specified to them [8, 9, 10, 11]. In 1996, Dorigo and Jembardla, made some modifications to ant Algorithm [9] and proposed AntColony Algorithm. This proposed Algorithm was different from previous Algorithm in terms of following characteristics: • • • The changing position rule which directly controls the effect of new nodes and old ones on the Algorithm. The overall updating rule that updating had been used only on nodes which belonged to ants’ paths. When the ants form a solution, the local updating rule will be applied. 4. OUR PROPOSED APPROACH Considering the proposed illustrations, it can be stated that if we can formulate optimization problems in well-known problems for which some Algorithms have been proposed, we can solve them through the above-mentioned methods. Therefore, the main task is how to convert these problems in to famous solved problems. As it was mentioned above, one of the famous problems is Traveling Sales Person problem for which different Algorithms have been proposed to solve it. Such Algorithms are Genetic Algorithm, Particle Swarm Optimization, Ant Algorithm, hybrid Algorithm, etc. We decide to solve optimizing join operation problem in relational database firstly by converting it to TSP problem and then solve it using Hyper-Heuristic Ant Algorithm. It should be mentioned that the main problem in this paper is not the same to original TSP problem because in the original TSP problem, sales person returns to first city, however, in the proposed problem, this is not the case. So, firstly formulas and the way that this problem should be solved using ant Algorithm has been stated and then important parameters and how converting this problem will be stated. Ant-Colony Algorithm which we considered in this paper is exactly the one proposed by Dorigo [9]. In this Algorithm, in the first phase, initially m ants with memory are created. These ants will randomly be placed on n nodes. On each node, there is some initial pheromone. In the second phase, to obtain initial solutions, the following steps are run in parallel. To select city s in its next move, the ant which is placed on node r, uses relation (1) known as position changing rule in Ant-Colony Algorithm. In relation (1), q is a random number in [0, 1] interval and the value of q0 is between 0 and 1. 4
  • 5. International Journal of Database Management Systems ( IJDMS ) Vol.5, No.5, October 2013  β .  arg max u∈J k ( r ) [τ ( r , u )][η (r , u )] s= S  { } if q ≤ q 0 otherwise (1) Where τ(r, s) represents the amount of pheromone on arc (r,s), η(r, s) is the reciprocal distance δ(r,s), JK(r) is the remaining set of cities for k-th ant placed on city r,β is the importance determining parameter in the relation between pheromone and distance. However, in relation (1), s is a random variable that follows from the probability distribution mentioned as relation (2).  [τ (r , s )][η (r , s )]β .  [τ (r , u)][η (r , u )]β .  s =  u∈∑r ) Jk (  0  if s ∈ J k (r ) otherwise (2) Where Pk(r,s) is the probability that k-th ant after selecting city r will select city s. After that ants create their own paths, they return to their first city. In this step, local updating will be done and the amount of pheromone changes by relation (3). τ ( r , s ) ← (1 − ρ ).τ ( r , s ) + ρ .∆τ ( r , s ) (3) Where ρ is pheromone evaporating parameter and ∆τ(r,s) is obtained using relation (4):  −1 ( L gb ) ∆τ ( r , s ) =  0  if ( r , s ) ∈ global _ best _ tour otherwise (4) where Lgb is the length of the best path which has already been found in the current iteration [9]. To solve the join problem of tables using Ant-Colony Algorithm, it suffices that we consider every table as a city (n cities) and that sales person doesn’t return to first city and also we should consider η(r, u) equal to reciprocal of the cost of two tables r and u and Lgb as minimum cost of the join of all tables in each iteration of Algorithm (parameter β can also be considered as an important parameter in distributed database). Therefore, in beginning of Algorithm, each ant is randomly placed on a city, then for move, join of this city with other cities (tables) should be verified if joining of these cities is possible as mentioned in the definition of problem-that is there exists a path between them- and after these steps, the table with minimum cost (least time for join operation) will be considered as a next city (table). To achieve this purpose, in each step, the cost of joining two tables as a cost of path between these two cities is added up with the cost of previous joins (equals total cost up to current step). In each run of Algorithm, with respect to local updating, the amount of pheromone changes until the best path is specified, so this path can be used in the next step and finally the best path (the join with minimum cost) can be selected. 5
  • 6. International Journal of Database Management Systems ( IJDMS ) Vol.5, No.5, October 2013 5. IMPLEMENTATION ENVIRONMENT We have used databases with the number of tables equal to 8, 12, 16, 20, 24, 28 and 32 in which the number of records in each table has been produced as a random number with uniform distribution. The parameters and system specification and implementation environment are as follows: We have used a system with Intel Core 2duo and 2.26GHZ cpu, 3GB RAM memory XP operating system. The language that program has been written with is C# and also we have used SQL SERVER database. In addition, we ran the program 20 times and in each run we have used 30 iterations, in other words, Iteration Number=30 and Run Number=20. The mean number of records which are used from each table in experiments is given in table1: Table1 : The mean number of records in each table in experiments Number of tables 8 12 16 20 24 28 32 Average number of records per table 383 418 362 397 403 354 429 6. EXPERIMENTAL RESULTS For our proposed approach, the number of ants is considered as the number of vertices and then the program has been executed. The number of iteration s for each experiment was 20 and the mean number of times through which iterations have been done is given in figure2. Figure 2. Execution time tests 6
  • 7. International Journal of Database Management Systems ( IJDMS ) Vol.5, No.5, October 2013 As it can be seen from figure 2, the proposed approach has resulted in a good performance in comparison to other approaches. This is the case because other approaches verify almost all existing ways of running a query while in the proposed approach , in each experiment if ants find a better solution (to join tables), they will inform the existence of this solution with respect to the updating strategy to other ants in order that they use this solution to find optimal solutions. Therefore, all existed solutions for running a query (join of multiple tables) will have not been verified and cpu time is saved. In other words, in our approach, ants operate in parallel. It should be noted that in the proposed approach, we have set the number of ants equal to the number of tables w and in the next time, we set it as half the number of tables and finally we have shown that for the second case, cpu time has decreased. On the other hand, the more the number of ants is, the less the decrease in the probability of the precision of the obtained result (as the experiment shows). Therefore, if we use more powerful processors, the runtime of Algorithm will decrease. In other words, if we use multi-processor system, runtime will decrease to an acceptable level and this is the case because ants Algorithm operates parallel and also the ants work in parallel with each other and updating is performed when each step is finished. 7. CONCLUSION In this paper, we stated a new approach for optimizing execution of queries in relational databases using Ant Colony algorithm. For this, we initially maped the connection between tables into a TSP model ,in which each table was considered as a city and each table link as a relation between two cities. Then the problem was solved by Ant Colony algorithm. Several such experiment was conducted for a number of different tables for which the numbers of records in each table were chosen randomly with uniform distribution. Experiments and given results proved the better performance of this approach rather than others that were given in the literature. The main reason for the efficiency of this method is its parallel property. This happened since our approach did not investigate all the existing ineffective and useless solutions for query execution, while, in the majority of other approaches the most existing solutions need to be evaluated. . As a consequence, we achieved a better execution time. REFERENCES [1] [2] [3] [4] [5] [6] F. Mahmoudi, M. Zahedi Anaraki, A.H. Zahedi Anaraki, Optimization of executing queries in relational databases with particle swarm algorithm, 16th National CSI Computer Conference, 2011.[Paper published in Persian] S. Parsa, H. Izadkhah, A. Hossein zadeh, Combination of hill climbing algorithm in parallel machine for optimization of large queries in question graph, 3rd IKT Conference, 2007. [Paper published in Persian] J. L. Sushil and Z. Yongmian . An Empirical Comparison of Randomized Algorithms for Large Join Query Optimization. Proceedings of the Eleventh International Florida Artificial Intelligence Research Society Conference, pp. 95-100, 1998. K. Bennet, M. C. Ferris and Y. E. Ioannidis. A Genetic Algorithm for Database Query Optimization. In Proc. of the Fourth Intl. Conf. on Genetic Algorithms, pp. 400-407, San Diego, USA, 1991. Y. E. Ioannidis and E. Wong. Query Optimization by Simulated Annealing. In Proc. of the ACMSIGMOD Conf. on Management of Data, pp. 9-22 San Francisco, USA, May 1987. K. Asghari, A. Safari Mamaghani, F. Mahmoudi, M. Meibodi, Optimization of executing queries in relational databases with hybrid evolutionary algorithm. Computer and Robotics magazine. p.25-37. 2008. [Paper published in Persian] 7
  • 8. International Journal of Database Management Systems ( IJDMS ) Vol.5, No.5, October 2013 [7] [8] [9] [10] [11] M. Jünger, G. Reinelt and G. Rinaldi. The Traveling Salemsan Problem, in Handbooks in Operations Research and Manageme nt Science, Vol. 7, pp. 225-330, 1995. M. Dorigo and L. M. Gambardella. Ant Colony System: A Cooperative Learning Approach to the Travelling Salesman Problem. IEEE Trans. Evol. Comp. 1, pp. 53-66, 1991. M. Dorigo and L. M. Gambardella. A Study of Some Properties of Ant-Q. In Proceedings of PPSNIV, Fourth International Conference on Parallel Problem Solving From Nature, pp. 656-665, Berlin: Springer-Verlag, 1996. M.dorigo and G.Dicaro. AntAlgorithm for Discrete Optimization. universite Libre de Bruxelles vol,5,No.3,pp.137-172,Dec.1999. Z. C. S. S. Hlaing and M. A. Khine. Solving Traveling Salesman Problem by Using Improved Ant Colony Optimization Algorithm. International Journal of Information and Education Technology, Vol. 1, No. 5, December 2011. AUTHORS Adel Alinezhad Kolaei is a MS student of Computer Science at Shiraz University of Technology. He received his BSc in Software Engineering from Iran University of Science and Technology. His major research interests are high performance algorithms and database management. Marzieh Ahmadzadeh is an Assistant Professor of Computer Science at Shiraz University of Technology. She received her PhD in Computer Science and MSc in Information Technology from the University of Nottingham, UK and her BSc in Software Engineering from Isfahan University, Iran. She teaches a variety of graduate and undergraduate courses and her research interest includes Computer Science Education in general and Computer Supported Learning, specifically Data Mining and Human Computer Interaction. 8