This paper discusses a problem of query processing in logic databases and proposes a method for optimizing queries which is based on the idea of analogical query processing. First, we introduce the notion of a higher-order relation which leads to a kind of design principle for constructing spacially efficient logic databases. Then, by making use of the notion of a higher-order relation, a method is presented in which a query given in a Horn logic formula is transformed into a string called primitive expression over the alphabet comprising primitive constructs of an internal representation langugage. A primitive expression of a query represents the essential meaning of the query and is used to detect analogy between queries. By using the analogical property between the transformed queries, a method for optimizing queries is demonstrated in three ways of query processing.