{"id":679,"date":"2014-04-27T21:21:44","date_gmt":"2014-04-27T19:21:44","guid":{"rendered":"http:\/\/konsilium.de\/blog\/?p=679"},"modified":"2022-07-07T22:03:43","modified_gmt":"2022-07-07T20:03:43","slug":"cognos-framework-minimized-sql","status":"publish","type":"post","link":"https:\/\/konsilium.de\/blog\/2014\/04\/27\/cognos-framework-minimized-sql\/","title":{"rendered":"Cognos Framework: &#8222;Minimized SQL&#8220;"},"content":{"rendered":"\n<p>In Framework Manager gibt es verschiedene Hebel zur Optimierung der Abfrage Performance. Einer davon ist die Richtlinie &#8222;Minimized SQL wo immer m\u00f6glich&#8220;.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Minimized SQL<\/h2>\n\n\n\n<p>Das modellierte Cognos Framework Modell kennt zwei Modi zur Generierung von SQL:<\/p>\n\n\n\n<ol><li>&#8222;As View&#8220;<\/li><li>&#8222;Minimized SQL&#8220;<\/li><\/ol>\n\n\n\n<p>&#8222;Minimized SQL&#8220; bedeutet, dass nur der notwendige Anteil an Tabellen, JOINs und Spalten in die Abfrage einbezogen wird, der notwendig ist, um die Abfrage zu beantworten. Wenn zum Bsp. von einem Model-Query-Subject&#8220; nur ein einzelnes Query-Item in eine Abfrage einbezogen wird, so wird auch nur f\u00fcr diese Spalte ein entsprechendes SQL-Select generiert. Im gezeigten Beispiel wird f\u00fcr die Role-Playing-Dimension &#8222;Datum Antrag&#8220; nur das Query-Item &#8222;Ant: Monat Bez. (lang)&#8220; und &#8222;Ant: Monat (Nr.)&#8220; in die Abfrage einbezogen. Die Abfrage wird in diesem Fall direkt in Framework-Manager mittels der Funktion &#8222;Test&#8220; durchgef\u00fchrt.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/konsilium.de\/blog\/wp-content\/uploads\/2014\/04\/minimized-sql-0.bmp\"><img decoding=\"async\" src=\"http:\/\/konsilium.de\/blog\/wp-content\/uploads\/2014\/04\/minimized-sql-0.bmp\" alt=\"Minimized SQL, Auswahl einzelnes Query-Item\" class=\"wp-image-697\"\/><\/a><\/figure>\n\n\n\n<p>Zus\u00e4tzlich wurde die Checkbox f\u00fcr &#8222;Auto Sum&#8220; aktiviert. Als Ergebnis wird folgendes angezeigt:<a href=\"http:\/\/konsilium.de\/blog\/wp-content\/uploads\/2014\/04\/minimized-sql-1.bmp\"><img decoding=\"async\" loading=\"lazy\" width=\"846\" height=\"666\" class=\"wp-image-695 alignnone\" src=\"http:\/\/konsilium.de\/blog\/wp-content\/uploads\/2014\/04\/minimized-sql-1.bmp\" alt=\"Minimized SQL, Abfrage\"><\/a><\/p>\n\n\n\n<p>Nach Klick auf Registerkarte &#8222;Query Information&#8220;:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/konsilium.de\/blog\/wp-content\/uploads\/2014\/04\/minimized-sql-2.bmp\"><img decoding=\"async\" src=\"http:\/\/konsilium.de\/blog\/wp-content\/uploads\/2014\/04\/minimized-sql-2.bmp\" alt=\"Minimized SQL, Query Information\" class=\"wp-image-694\"\/><\/a><\/figure>\n\n\n\n<p>Wie man sieht wurde noch eine weitere Spalte in die Query mitaufgenommen. Dies hat mit der Definition von Determinanten zu tun, die f\u00fcr die unterschiedlichen Ebenen der Zeitdimension definiert wurden. Wichtig ist jedoch die Tatsache, dass sonst keine weiteren Spalten und auch kein JOIN zu einer Faktentabelle mit in das SQL aufgenommen wurde. Man spricht in diesem Fall von einem &#8222;Minimized SQL&#8220;. Nur die Spalte &#8222;BEZ_JAHR_MONAT&#8220; wurde noch zus\u00e4tzlich aufgenommen, weil sie \u00fcber die Determinaten Definition als Gruppierungsschl\u00fcssel dient.<\/p>\n\n\n\n<p>F\u00fcr jedes &#8222;Data-Query-Subject&#8220; oder &#8222;Model-Query-Subject&#8220; gibt es die M\u00f6glichkeit unter &#8222;Edit Definition&#8220; den SQL-Generierungsmodus einzustellen.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/konsilium.de\/blog\/wp-content\/uploads\/2014\/04\/minimized-sql.bmp\"><img decoding=\"async\" src=\"http:\/\/konsilium.de\/blog\/wp-content\/uploads\/2014\/04\/minimized-sql.bmp\" alt=\"Minimized SQL\" class=\"wp-image-692\"\/><\/a><\/figure>\n\n\n\n<p>Ein SELECT, das mit der Option &#8222;Minimized SQL&#8220; generiert wurde, hat eine h\u00f6here Chance durch den Datenbank-Optimizer hinsichtlich Ausf\u00fchrungspfad optimiert zu werden. Die Performance-Optimierung \u00fcber den Einsatz von Materialized Views ist hiervon betroffen.<\/p>\n\n\n\n<p>&#8222;Minimized SQL&#8220; kann in den folgenden F\u00e4llen (unter Umst\u00e4nden) nicht generiert werden:<\/p>\n\n\n\n<ul><li>Wenn Filter, Calculations, Parameterized SQL in den Data-Source-Query-Subjects hinzugef\u00fcgt wurden<\/li><li>Wenn das von Framework-Manager (per Default) generierte SQL in den &#8222;Data-Source-Query-Subjects&#8220; \u00fcberschrieben \/ angepasst wurde<\/li><li>Wenn ein (abgeleitetes) Model-Query-Subject mind. zwei andere Model-Query-Subjects referenziert, die bereits Releationships besitzen und ferner dieses abgeleitete Model-Query-Subject ebenfalls eine Relationship besitzt bei deren Erzeugung auf die Frage &#8222;Re-Create-Underlying Relationship?&#8220; mit &#8222;Yes&#8220; geantwortet wurde.<br>Bsp. Die Tabellen Order_Detail und Order_Header wurden \u00fcber einen JOIN zu einem Query-Subject&#8220; namens &#8222;Sales_Fact&#8220; zusammengef\u00fcgt, um Abfragen einfacher und sicherer f\u00fcr die Berichtsersteller zu gestalten.<\/li><\/ul>\n\n\n\n<p>Manchmal ist es auch notwendig, Query-Pfade anzupassen &#8211; vorallem, wenn kein sauber modelliertes Star-Schema zugrundeliegt. In diesem Fall wird im Hintergrund immer der zugrunde liegende JOIN und weitere Spalten im SQL mitgeneriert. Auf die im Beispiel beschriebene Weise wird eine &#8222;<strong>As View<\/strong>&#8220; SQL-Generierung erzeugt.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Model-Query-Subjects und SQL-Types<\/h1>\n\n\n\n<p>Bsp.: Ein Model-Query-Subject ABC referenziert) ein anderes Query-Subjekt XYZ. Wenn XYZ die Einstellung &#8222;Minimized SQL&#8220; besitzt, dann \u00fcbernimmt ABC nicht die Einstellungen von XYZ. Ist Query-Subject XYZ auf &#8222;As View&#8220; eingestellt, so wird die SQL Logik von XYZ auf ABC vererbt (&#8222;As View&#8220;).<\/p>\n\n\n\n<p>Minimized SQL&#8220; ist die Default-Einstellung f\u00fcr Model-Query-Subjects.<\/p>\n\n\n\n<p><strong>Ein weiteres Beispiel, um zu verdeutlichen, was Minimized SQL&#8220; bedeutet<br>(aus der Cognos Dokumentation, daher ausnahmsweise in Englisch)<\/strong><\/p>\n\n\n\n<p>When you use minimized SQL, the generated SQL contains only the minimal set of tables and joins needed to obtain values for the selected query items.<\/p>\n\n\n\n<p>To see an example of what minimized SQL means, you can use the following Product tables. Four query subjects, Product Line, Product Type, Product, and Product Multilingual all join to each other.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/konsilium.de\/blog\/wp-content\/uploads\/2014\/04\/ug_fm_bst30.jpg\"><img decoding=\"async\" loading=\"lazy\" width=\"300\" height=\"140\" src=\"http:\/\/konsilium.de\/blog\/wp-content\/uploads\/2014\/04\/ug_fm_bst30-300x140.jpg\" alt=\"What Is Minimized SQL, Bild 1\" class=\"wp-image-709\" srcset=\"https:\/\/konsilium.de\/blog\/wp-content\/uploads\/2014\/04\/ug_fm_bst30-300x140.jpg 300w, https:\/\/konsilium.de\/blog\/wp-content\/uploads\/2014\/04\/ug_fm_bst30-500x233.jpg 500w, https:\/\/konsilium.de\/blog\/wp-content\/uploads\/2014\/04\/ug_fm_bst30.jpg 691w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/figure>\n\n\n\n<p>They can be combined in a model query subject.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/konsilium.de\/blog\/wp-content\/uploads\/2014\/04\/ug_fm_bst29.jpg\"><img decoding=\"async\" loading=\"lazy\" width=\"208\" height=\"254\" src=\"http:\/\/konsilium.de\/blog\/wp-content\/uploads\/2014\/04\/ug_fm_bst29.jpg\" alt=\"What Is Minimized SQL, Bild 2\" class=\"wp-image-708\"\/><\/a><\/figure>\n\n\n\n<p>If you test the Products model query subject as a whole, you see that four tables are referenced in the from clause of the query.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>select \n PRODUCT_LINE.PRODUCT_LINE_CODE as Product_Line_Code,\n PRODUCT_LINE.PRODUCT_LINE_EN as Product_Line,\n PRODUCT_TYPE.PRODUCT_TYPE_CODE as Product_Type_Code,\n PRODUCT_TYPE.PRODUCT_TYPE_EN as Product_Type,\n PRODUCT.PRODUCT_NUMBER as Product_Number,\n PRODUCT_MULTILINGUAL.PRODUCT_NAME as Product_Name,\n PRODUCT_MULTILINGUAL.DESCRIPTION as Product_Description,\n PRODUCT.INTRODUCTION_DATE as Introduction_Date,\n PRODUCT.PRODUCT_IMAGE as Product_Image,\n PRODUCT.PRODUCTION_COST as Production_Cost,\n PRODUCT.MARGIN as Margin\nfrom\n gosl_82..gosl.PRODUCT_LINE PRODUCT_LINE,\n gosl_82..gosl.PRODUCT_TYPE PRODUCT_TYPE,\n gosl_82..gosl.PRODUCT PRODUCT,\n gosl_82..gosl.PRODUCT_MULTILINGUAL PRODUCT_MULTILINGUAL\nwhere\n (PRODUCT_MULTILINGUAL.\"LANGUAGE\" - N'EN') and \n(PRODUCT_LINE.PRODUCT_LINE_CODE = PRODUCT_TYPE.PRODUCT_LINE_CODE) and\n(PRODUCT_TYPE.PRODUCT_TYPE_CODE = PRODUCT.PRODUCT_TYPE_CODE) and\n(PRODUCT.PRODUCT_NUMBER = PRODUCT_MULTILINGUAL.PRODUCT_NUMBER<\/code><\/pre>\n\n\n\n<p>If you test only Product name, you see that the resulting query uses only Product Multilingual, which is the table that was required. This is the effect of minimized SQL.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>select \n PRODUCT_MULTILINGUAL.PRODUCT_NAME as Product_Name \nfrom \n gosl_82..gosl.PRODUCT_MULTILINGUAL PRODUCT_MULTILINGUAL \nwhere \n (PRODUCT_MULTILINGUAL.\"LANGUAGE\" - N'EN\")<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">Example: When Minimized SQL Is Important<\/h1>\n\n\n\n<p>If you are modeling a normalized data source, you may be more concerned about minimized SQL because it will reduce the number of tables used in some requests and perform better. In this case, it would be best to create relationships and determinants between the data source query subjects and then create model query subjects that do not have relationships.<\/p>\n\n\n\n<p>There is a common misconception that if you do not have relationships between objects, you cannot create star schema groups. This is not the case. Select the model query subjects to include in the group and use the Star Schema Grouping wizard. Or you can create shortcuts and move them to a new namespace. There is no need to have shortcuts to the relationships; this feature is purely visual in the diagram. The effect on query generation and presentation in the studios is the same.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Example: When Minimized SQL Is Not as Important as Predictable Queries<\/h1>\n\n\n\n<p>There may be some elements in a data source that you need to encapsulate to ensure that they behave as if they were one data object. An example might be a security table that must always be joined to a fact. In the Great Outdoors Sales model, Order Header and Order Details are a set of tables that together represent a fact and you would always want them to be queried together. For an example, see Where Should You Create Relationships and Determinants?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Framework Manager gibt es verschiedene Hebel zur Optimierung der Abfrage Performance. Einer davon ist die Richtlinie &#8222;Minimized SQL wo immer m\u00f6glich&#8220;. Minimized SQL Das modellierte Cognos Framework Modell kennt zwei Modi zur Generierung von SQL: &#8222;As View&#8220; &#8222;Minimized SQL&#8220; &#8222;Minimized SQL&#8220; bedeutet, dass nur der notwendige Anteil an Tabellen, JOINs und Spalten in die&hellip;&nbsp;<a href=\"https:\/\/konsilium.de\/blog\/2014\/04\/27\/cognos-framework-minimized-sql\/\" class=\"\" rel=\"bookmark\">Weiterlesen &raquo;<span class=\"screen-reader-text\">Cognos Framework: &#8222;Minimized SQL&#8220;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":2278,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","footnotes":""},"categories":[33,59],"tags":[94,34,60],"_links":{"self":[{"href":"https:\/\/konsilium.de\/blog\/wp-json\/wp\/v2\/posts\/679"}],"collection":[{"href":"https:\/\/konsilium.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/konsilium.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/konsilium.de\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/konsilium.de\/blog\/wp-json\/wp\/v2\/comments?post=679"}],"version-history":[{"count":25,"href":"https:\/\/konsilium.de\/blog\/wp-json\/wp\/v2\/posts\/679\/revisions"}],"predecessor-version":[{"id":2700,"href":"https:\/\/konsilium.de\/blog\/wp-json\/wp\/v2\/posts\/679\/revisions\/2700"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/konsilium.de\/blog\/wp-json\/wp\/v2\/media\/2278"}],"wp:attachment":[{"href":"https:\/\/konsilium.de\/blog\/wp-json\/wp\/v2\/media?parent=679"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/konsilium.de\/blog\/wp-json\/wp\/v2\/categories?post=679"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/konsilium.de\/blog\/wp-json\/wp\/v2\/tags?post=679"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}