<commit_before>﻿using System;

namespace LinqToDB.DataProvider.Firebird
{
	using Extensions;
	using SqlProvider;
	using SqlQuery;

	class FirebirdSqlOptimizer : BasicSqlOptimizer
	{
		public FirebirdSqlOptimizer(SqlProviderFlags sqlProviderFlags) : base(sqlProviderFlags)
		{
		}

		static void SetNonQueryParameter(IQueryElement element)
		{
			if (element.ElementType == QueryElementType.SqlParameter)
				((SqlParameter)element).IsQueryParameter = false;
		}

		public override SelectQuery Finalize(SelectQuery selectQuery)
		{
			CheckAliases(selectQuery, int.MaxValue);

			new QueryVisitor().Visit(selectQuery.Select, SetNonQueryParameter);

			if (selectQuery.QueryType == QueryType.InsertOrUpdate)
			{
				foreach (var key in selectQuery.Insert.Items)
					new QueryVisitor().Visit(key.Expression, SetNonQueryParameter);

				foreach (var key in selectQuery.Update.Items)
					new QueryVisitor().Visit(key.Expression, SetNonQueryParameter);

				foreach (var key in selectQuery.Update.Keys)
					new QueryVisitor().Visit(key.Expression, SetNonQueryParameter);
			}

			new QueryVisitor().Visit(selectQuery, element =>
			{
				if (element.ElementType == QueryElementType.InSubQueryPredicate)
					new QueryVisitor().Visit(((SelectQuery.Predicate.InSubQuery)element).Expr1, SetNonQueryParameter);
			});

			selectQuery = base.Finalize(selectQuery);
<commit_msg>FbOptimazer inlines parameter in select clause only<commit_after>﻿using System;

namespace LinqToDB.DataProvider.Firebird
{
	using Extensions;
	using SqlProvider;
	using SqlQuery;

	class FirebirdSqlOptimizer : BasicSqlOptimizer
	{
		public FirebirdSqlOptimizer(SqlProviderFlags sqlProviderFlags) : base(sqlProviderFlags)
		{
		}

		static void SetNonQueryParameter(IQueryElement element)
		{
		    if (element.ElementType == QueryElementType.SqlParameter)
		        ((SqlParameter) element).IsQueryParameter = false;
		}

	    private bool SearchSelectClause(IQueryElement element)
	    {
            if (element.ElementType != QueryElementType.SelectClause) return true;

            new QueryVisitor().VisitParentFirst(element, SetNonQueryParameterInSelectClause);
            return false;
	        
	    }

	    private bool SetNonQueryParameterInSelectClause(IQueryElement element)
	    {
            if (element.ElementType == QueryElementType.SqlParameter)
            {
                ((SqlParameter)element).IsQueryParameter = false;
                return false;
            }
            if (element.ElementType == QueryElementType.SqlQuery)
            {
                new QueryVisitor().VisitParentFirst(element, SearchSelectClause);
                return false;
            }
            return true;
	    }

		public override SelectQuery Finalize(SelectQuery selectQuery)
		{
			CheckAliases(selectQuery, int.MaxValue);

            new QueryVisitor().VisitParentFirst(selectQuery, SearchSelectClause);

			if (selectQuery.QueryType == QueryType.InsertOrUpdate)
			{
				foreach (var key in selectQuery.Insert.Items)
					new QueryVisitor().Visit(key.Expression, SetNonQueryParameter);

				foreach (var key in selectQuery.Update.Items)
					new QueryVisitor().Visit(key.Expression, SetNonQueryParameter);

				foreach (var key in selectQuery.Update.Keys)
					new QueryVisitor().Visit(key.Expression, SetNonQueryParameter);
			}

			selectQuery = base.Finalize(selectQuery);

{'fraction_non_alphanumeric': 0.08615567439096851, 'fraction_numerical': 0.00029708853238265005, 'mean_word_length': 3.695955369595537, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5623363', 'n_tokens_mistral': 1044, 'n_tokens_neox': 903, 'n_words': 181}