Re: [sqlsmith] Crash in mcv_get_match_bitmap

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Tomas Vondra <tomas.vondra@2ndquadrant.com>
Cc: Andreas Seltenreich <seltenreich@gmx.de>, pgsql-hackers@lists.postgresql.org, Tomas Vondra <tomas.vondra@postgresql.org>
Date: 2019-07-10T21:45:24Z
Lists: pgsql-hackers
Tomas Vondra <tomas.vondra@2ndquadrant.com> writes:
> Yeah, that's a bug. Will fix (not sure how yet).

You could do worse than replace this:

        ok = (NumRelids(clause) == 1) &&
            (is_pseudo_constant_clause(lsecond(expr->args)) ||
             (varonleft = false,
              is_pseudo_constant_clause(linitial(expr->args))));

with something like

	if (IsA(linitial(expr->args), Var) &&
	    IsA(lsecond(expr->args), Const))
	   ok = true, varonleft = true;
	else if (IsA(linitial(expr->args), Const) &&
	         IsA(lsecond(expr->args), Var))
	   ok = true, varonleft = false;

Or possibly get rid of varonleft as such, and merge extraction of the
"var" and "cst" variables into this test.

BTW, I bet passing a unary-argument OpExpr also makes this code
unhappy.

			regards, tom lane



Commits

  1. Use column collation for extended statistics

  2. Rework examine_opclause_expression to use varonleft

  3. Fix handling of NULLs in MCV items and constants

  4. Fix handling of opclauses in extended statistics

  5. Remove unnecessary TYPECACHE_GT_OPR lookup

  6. Simplify bitmap updates in multivariate MCV code

  7. Make pg_statistic and related code account more honestly for collations.