The data grids are very wide distributed environments where the nodes are distributed through the sphere, and the data which are shared there, are very bulky. The data grids are facing new problems during the distributed queries processing. These problems are caused by the characteristics of grid systems (e.g. the large-scale, instability and the autonomy of nodes, heterogeneity and the unavailability of resources). We propose in this paper, a new strategy for optimizing the query execution, taking into account the problems of discovery of nodes, and the efficient allocation of replicas. Thus, we propose to execute each relational operator of an execution plan by two mobile agents, by attaching each agent to the node storing the replica involved in the operator. A mobile agent can migrate to another site to improve the query execution cost. This cost is calculated using a cost model that we have determined.