Query is the core function of a Database Management System. A powerful and effective query algorithm is the key of a successful database system. In the paper, an algorithm of database query optimization is introduced and is implemented on a federal database system——LNFDBS(Lingnan federal database system). The adaptation to the federal database system is also discussed.