Many knowledge-based applications require efficient access and manipulation of database objects. Although high level declarative language formalisms have been suggested for programming these applications, the general purpose nature of such languages makes optimization for database access a much harder problem than with traditional query languages. In this paper, we present a solution to this problem that allows direct and effective use of existing query optimization techniques originally developed for relational databases.