ALTER TABLE fm_variant_states
  ADD COLUMN is_parent_variant TINYINT(1) NOT NULL DEFAULT 0 AFTER variant_title,
  ADD KEY fm_variant_states_client_parent_ix (client, is_parent_variant);

UPDATE fm_variant_states
SET is_parent_variant = 0;

UPDATE fm_variant_states v
INNER JOIN (
  SELECT client, product_id, MIN(variant_id) AS parent_variant_id
  FROM fm_variant_states
  GROUP BY client, product_id
) p
  ON p.client = v.client
  AND p.product_id = v.product_id
  AND p.parent_variant_id = v.variant_id
SET v.is_parent_variant = 1;
