Topological invariants of spatial databases (i.e., finite structures that capture the topological properties of the database) are receiving increasing attention since they can act as a basic structure to tackle relevant problems in the field (e.g., assessment of the topological equivalence). In this paper, the novel notion of boundary decomposition of a topological invariant is introduced and a polynomial time algorithm to compute such a decomposition is given. The decomposition consists of a recursive subdivision of the topological invariant into a finite set of simpler structures, each being a topological invariant in itself. The decomposition is proved to be lossless, a nice property which makes the boundary decomposition useful in real applications. As a relevant application, we use the boundary decomposition as the basis for devising a polynomial time algorithm for testing the topological equivalence of two 2-dimensional spatial databases. Key words: Spatial data, constraint data...