A method comprising: accessing a social graph comprising a plurality of nodes and a plurality of edges connecting the nodes, each of the edges between two of the nodes representing a single degree of separation between them, the nodes comprising: a first node corresponding to a first user associated with an online social network; and a plurality of second nodes that each correspond to a concept or a second user associated with the online social network; receiving from the first user a structured query comprising references to one or more selected nodes from the plurality of nodes and one or more selected edges from the plurality of edges; parsing the structured query to identify a first query constraint and one or more second query constraints; determining a number of nodes satisfying the first query constraint; and if the number of nodes is greater than a threshold number of nodes, then identifying an inverse constraint associated with the first query constraints; and generating a query command based on the structured query, wherein the query command comprises the inverse constraint and the one or more second query constraints; else generating the query command with the first query constraint. accessing a social graph comprising a plurality of nodes and a plurality of edges connecting the nodes, each of the edges between two of the nodes representing a single degree of separation between them, the nodes comprising: a first node corresponding to a first user associated with an online social network; and a plurality of second nodes that each correspond to a concept or a second user associated with the online social network; receiving from the first user a structured query comprising references to one or more selected nodes from the plurality of nodes and one or more selected edges from the plurality of edges; parsing the structured query to identify a first query constraint and one or more second query constraints; determining a number of nodes satisfying the first query constraint; and if the number of nodes is greater than a threshold number of nodes, then identifying an inverse constraint associated with the first query constraints; and generating a query command based on the structured query, wherein the query command comprises the inverse constraint and the one or more second query constraints; else generating the query command with the first query constraint. a first node corresponding to a first user associated with an online social network; and a plurality of second nodes that each correspond to a concept or a second user associated with the online social network; receiving from the first user a structured query comprising references to one or more selected nodes from the plurality of nodes and one or more selected edges from the plurality of edges; parsing the structured query to identify a first query constraint and one or more second query constraints; determining a number of nodes satisfying the first query constraint; and if the number of nodes is greater than a threshold number of nodes, then identifying an inverse constraint associated with the first query constraints; and generating a query command based on the structured query, wherein the query command comprises the inverse constraint and the one or more second query constraints; else generating the query command with the first query constraint.