def _query_and_op(self, tree, table, method_name, method_kwargs):
        """ Query the table and perform an operation on each item """
        result = []
        if tree.keys_in:
            if tree.using:
                raise SyntaxError("Cannot use USING with KEYS IN")
            keys = self._iter_where_in(tree)
        else:
            visitor = Visitor(self.reserved_words)
            (action, kwargs, _) = self._build_query(table, tree, visitor)
            attrs = [visitor.get_field(table.hash_key.name)]
            if table.range_key is not None:
                attrs.append(visitor.get_field(table.range_key.name))
            kwargs["attributes"] = attrs
            kwargs["expr_values"] = visitor.expression_values
            kwargs["alias"] = visitor.attribute_names
            # If there is no 'where' on this update/delete, check with the
            # caution_callback before proceeding.
            if (
                visitor.expression_values is None
                and callable(self.caution_callback)
                and not self.caution_callback(method_name)  # pylint: disable=E1102
            ):
                return False
            method = getattr(self.connection, action + "2")
            keys = method(table.name, **kwargs)
            if self._explaining:
                try:
                    list(keys)
                except ExplainSignal:
                    keys = [{}]

        method = getattr(self.connection, method_name + "2")
        count = 0
        for key in keys:
            try:
                ret = method(table.name, key, **method_kwargs)
            except CheckFailed:
                continue
            count += 1
            if ret:
                result.append(ret)
        if result:
            return result
        else:
            return count
Query the table and perform an operation on each item